public static LoadRunnerParameters Build() { // For this example we will create a little bit modified of default preset (see this.DefaultParametersPreset below). LoadRunnerParameters parameters = new LoadRunnerParameters { // Incremental strategy here increases thread count every 10 seconds. // This can be aligned with TimeDimension used below in shown aggregator. ThreadingStrategy = new IncrementalThreadCount(20, TimeSpan.FromSeconds(10), 20) }; return parameters; }
public static void Run() { // LoadRunnerParameters used to configure on how load test will execute. LoadRunnerParameters loadRunnerParameters = new LoadRunnerParameters { Limits = new ExecutionLimits { // Maximum LoadTest duration threshold, after which test is stopped MaxDuration = TimeSpan.FromSeconds(30), // Maximum executed iterations count threshold, after which test is stopped MaxIterationsCount = Int32.MaxValue, // Once LoadTest execution finishes because of [maxDuration] or [maxIterationsCount] limit // coordinating thread will wait [FinishTimeout] amount of time before // terminating them with Thread.Abort() // // Aborted threads won't get the chance to call IterationTearDown() or ScenarioTearDown() // neither it will broadcast TestContextResultReceived() to aggregators with the state as it is after abort. FinishTimeout = TimeSpan.FromSeconds(60) }, // [ISpeedStrategy] defines maximum allowed load by dampening executed Iterations per second count // * Other existing version of [ISpeedStrategy] // - IncremantalSpeed(initialRequestsPerSec: 1.0, increasePeriod: TimeSpan.FromSeconds(10), increaseStep: 3.0) SpeedStrategy = new FixedSpeed(maxIterationsPerSec: Double.MaxValue), //[IThreadingStrategy] defines allowed worker thread count // * SemiAutoThreading initializes [minThreadCount] at begining // It will be increased if not enough threads are available to reach [ISpeedStrategy] limits ThreadingStrategy = new IncrementalThreadCount(15, TimeSpan.FromSeconds(10), 15) }; // Initialize aggregator string[] ignoredCheckpoints = { Checkpoint.IterationSetupCheckpointName, Checkpoint.IterationStartCheckpointName, Checkpoint.IterationTearDownCheckpointName }; HistogramAggregator histogramAggregator = new HistogramAggregator() .Add(new TimeDimension(TimeSpan.FromSeconds(10))) .Add(new MinDurationMetric(ignoredCheckpoints)) .Add(new AvgDurationMetric(ignoredCheckpoints)) .Add(new MaxDurationMetric(ignoredCheckpoints)) .Add(new PercentileMetric(new[] {0.5, 0.8, 0.9, 0.95, 0.99}, ignoredCheckpoints)) .Add(new CountMetric(ignoredCheckpoints)) .Add(new ErrorCountMetric()) .Add(new FuncMetric<int>("Created Threads", 0, (i, result) => result.CreatedThreads)) .Alias($"Min: {Checkpoint.IterationEndCheckpointName}", "Min (ms)") .Alias($"Avg: {Checkpoint.IterationEndCheckpointName}", "Avg (ms)") .Alias($"Max: {Checkpoint.IterationEndCheckpointName}", "Max (ms)") .Alias($"50%: {Checkpoint.IterationEndCheckpointName}", "50% (ms)") .Alias($"80%: {Checkpoint.IterationEndCheckpointName}", "80% (ms)") .Alias($"90%: {Checkpoint.IterationEndCheckpointName}", "90% (ms)") .Alias($"95%: {Checkpoint.IterationEndCheckpointName}", "95% (ms)") .Alias($"99%: {Checkpoint.IterationEndCheckpointName}", "99% (ms)") .Alias($"Count: {Checkpoint.IterationEndCheckpointName}", "Success: Count") .Alias($"Errors: {Checkpoint.IterationSetupCheckpointName}", "Errors: Setup") .Alias($"Errors: {Checkpoint.IterationStartCheckpointName}", "Errors: Iteration") .Alias($"Errors: {Checkpoint.IterationTearDownCheckpointName}", "Errors: Teardown"); JsonStreamAggregator _jsonStreamAggregator = new JsonStreamAggregator(() => DateTime.Now.ToString("HH_mm_ss__ffff") + ".json"); //TotalsResultsAggregator resultsAggregator = new TotalsResultsAggregator(); // Initializing LoadTest Client //LoadRunnerEngine loadRunner = LoadRunnerEngine.Create<TestScenario>(loadRunnerParameters, histogramAggregator, _jsonStreamAggregator); LoadRunnerUi loadRunnerUi = LoadRunnerUi.Create<TestScenario>(loadRunnerParameters, histogramAggregator, _jsonStreamAggregator); Application.Run(loadRunnerUi); return; // Run test (blocking call) //loadRunner.Run(); //loadRunner.RunAsync(); //Console.WriteLine("Async started"); //loadRunner.Wait(); //object defaultResults = histogramAggregator.BuildResultsObjects(); //Console.WriteLine(JsonConvert.SerializeObject(defaultResults, Formatting.Indented)); //Console.ReadKey(); }