/// <summary> /// Initializes new executor instance /// </summary> /// <typeparam name="TTestScenario">ILoadTestScenario to be executed object type</typeparam> /// <param name="parameters">LoadTest parameters</param> /// <param name="resultsAggregators">Aggregators to use when aggregating results from all iterations</param> /// <returns></returns> public static LoadRunnerUi Create <TTestScenario>(LoadRunnerParameters parameters, params IResultsAggregator[] resultsAggregators) where TTestScenario : ILoadTestScenario { LoadRunnerUi ui = new LoadRunnerUi(parameters, typeof(TTestScenario), resultsAggregators); return(ui); }
public static void Run() { // Initialize LoadRunnerEngine by providing: // * Type of class which implements ILoadTestScenario (e.g DemoTestScenario) // * LoadRunnerParameters // * As many aggregators as you like HistogramAggregator histogramAggregator = AggregationSetup.Build(); LoadRunnerParameters parameters = ParametersSetup.Build(); LoadRunnerEngine loadRunner = LoadRunnerEngine.Create <DemoTestScenario>(parameters, histogramAggregator); // Run test (blocking call) loadRunner.Run(); // Once finished, extract information from used aggregators, and do some exceling :) // BuildResultsObjects() will produce results in structure compatible with JSON -> CSV converters. (See ~20 lines below) IEnumerable <object> defaultResults = histogramAggregator.BuildResultsObjects(); Console.WriteLine(JsonConvert.SerializeObject(defaultResults, Formatting.Indented)); Console.ReadKey(); //Alternative export way is // HistogramResults results = histogramAggregator.BuildResults(); // // results will be presented in this structure: // * string[] ColumnNames; // * object[][] Values; }
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); }
/// <summary> /// Initializes new executor instance /// </summary> /// <param name="parameters">LoadTest parameters</param> /// <param name="iTestScenarioObjectType">ILoadTestScenario to be executed object type</param> /// <param name="resultsAggregators">Aggregators to use when aggregating results from all iterations</param> public LoadRunnerEngine(LoadRunnerParameters parameters, Type iTestScenarioObjectType, params IResultsAggregator[] resultsAggregators) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (iTestScenarioObjectType == null) { throw new ArgumentNullException(nameof(iTestScenarioObjectType)); } _parameters = parameters; _iTestScenarioObjectType = iTestScenarioObjectType; _resultsAggregator = new AsyncResultsAggregator(resultsAggregators); }
private LoadRunnerUi(LoadRunnerParameters parameters, Type iTestScenarioType, IResultsAggregator[] resultsAggregators) { _metricMultiplexerTemplate = new MetricMultiplexer(new IMetric[] { new FuncMultiMetric <int>((row, result) => result.Checkpoints.ForEach(c => row[c.Name] = (int)c.TimePoint.TotalMilliseconds), () => default(int) ), new CountMetric(), new ErrorCountMetric(), new TransactionsPerSecMetric() }); _loadRunnerEngine = new LoadRunnerEngine(parameters, iTestScenarioType, resultsAggregators.Concat(new [] { this }).ToArray()); InitializeComponent(); }
/// <summary> /// Initializes new executor instance /// </summary> /// <typeparam name="TTestScenario">ILoadTestScenario to be executed object type</typeparam> /// <param name="parameters">LoadTest parameters</param> /// <param name="resultsAggregators">Aggregators to use when aggregating results from all iterations</param> /// <returns></returns> public static LoadRunnerEngine Create <TTestScenario>(LoadRunnerParameters parameters, params IResultsAggregator[] resultsAggregators) where TTestScenario : ILoadTestScenario { return(new LoadRunnerEngine(parameters, typeof(TTestScenario), resultsAggregators)); }
public static void Run() { // LoadRunnerParameters initializes defaults shown below 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(); }