// HDD/SSD intensive, beware
        public static void Run()
        {
            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new TimeDimension(TimeSpan.FromSeconds(2)))
                                             .Add(new CountMetric())
                                             .Add(new TransactionsPerSecMetric());

            HistogramAggregator aggregagorOriginal = new HistogramAggregator()
                                                     .Add(new TimeDimension(TimeSpan.FromSeconds(2)))
                                                     .Add(new CountMetric())
                                                     .Add(new TransactionsPerSecMetric());

            StrategyBuilder strategy = new StrategyBuilder()
                                       .SetScenario <BlankScenario>()
                                       .SetThreading(new FixedThreadCount(3))
                                       .SetLimit(new TimeLimit(TimeSpan.FromSeconds(5)))
                                       .SetAggregator(new JsonStreamAggregator("Raw.json"), aggregagorOriginal);

            strategy.Build().Run();

            JsonStreamAggregator.Replay("Raw.json", aggregator);

            Console.WriteLine(JsonConvert.SerializeObject(aggregagorOriginal.BuildResultsObjects(), Formatting.Indented));
            Console.WriteLine(JsonConvert.SerializeObject(aggregator.BuildResultsObjects(), Formatting.Indented));
        }
        // All IAggregator implementations receive un-aggregated raw measurements (later raw-data) from workers.
        //  - (TODO: More info in IAggregator customization, But IAggregator ir pretty self explanatory anyway :))
        // Main idea behind Raw-Data is that one gets un-aggregated measurements in IResult form
        // and one can do anything with it, preferably post-load-test.
        //
        //
        // Having this unlocks few advantages:
        // * Save this raw-data somewhere(file on disk, array in memory) and do any aggregations after the test.
        //   - I personally persist raw-data from all of the tests I do,
        //     because one will never know what aggregation might be needed until one runs the test and sees initial results.
        //   - There is a RnD JsonStreamAggregator which saves to JSON array file. Though it can take up some space on disk as JSON has lots of overhead.
        // * Or one can write own custom specialized aggregation ignoring provided HistogramAggregator totally.
        //
        //
        // This demo contains:
        // * Load-test with one aggregation:
        //    - [Tools nuget: JsonStreamAggregator] Write data to raw.json file for later aggregation
        // * Replay of raw measurements after the test and do some more aggregating post-load-test.
        //    - Two histogram aggregators: Timeline and KPI.
        //    - One StreamAggregator instance which gives IEnumerable of IResult's for custom inline aggregation.

        public static void Run()
        {
            // JsonStreamAggregator dumps everything it receives to file.
            JsonStreamAggregator jsonAggregator = new JsonStreamAggregator("raw.json");


            StrategyBuilder builder = new StrategyBuilder()
                                      .AddLimit(new TimeLimit(TimeSpan.FromSeconds(4)))
                                      .SetThreading(new FixedThreadCount(4))
                                      .SetScenario(new SleepingScenarioFactory(TimeSpan.FromMilliseconds(100))) // Use scenario from common which sleeps every iteration
                                      .SetAggregator(jsonAggregator);                                           // Register JsonAggregator to be only one to receive results

            // A quick run
            builder.Build().Run();


            // Now lets do actual aggregation post testing.
            // First - just configure HistogramAggregator or any other aggregator in same way one would do for the live test.

            HistogramAggregator histogramTimeline = new HistogramAggregator()
                                                    .Add(new TimeDimension(TimeSpan.FromSeconds(1)))
                                                    .Add(new CountMetric())
                                                    .Add(new GlobalTimerMinValueMetric())
                                                    .Add(new GlobalTimerMaxValueMetric())
                                                    .Add(new GlobalTimerPeriodMetric());

            HistogramAggregator histogramKpi = new HistogramAggregator()
                                               .Add(new CountMetric())
                                               .Add(new GlobalTimerMinValueMetric())
                                               .Add(new GlobalTimerMaxValueMetric())
                                               .Add(new GlobalTimerPeriodMetric());

            // Lets define another more specialized aggregation just for lols.
            TimeSpan         lastIterationEnded = TimeSpan.Zero;
            StreamAggregator streamAggregator   = new StreamAggregator(
                results =>
            {
                lastIterationEnded = results.Max(r => r.IterationFinished);
            }
                );

            // now just replay saved raw-data stream to those later-defined aggregations.
            JsonStreamAggregator.Replay("raw.json", histogramTimeline, histogramKpi, streamAggregator);

            Console.WriteLine($"StreamAggregator, last iteration  finished: {lastIterationEnded:g}");
            Console.WriteLine("---------------- Histogram KPI -----------");
            Console.WriteLine(JsonConvert.SerializeObject(histogramKpi.BuildResultsObjects(), Formatting.Indented));
            Console.WriteLine("---------------- Histogram timeline -----------");
            Console.WriteLine(JsonConvert.SerializeObject(histogramTimeline.BuildResultsObjects(), Formatting.Indented));
        }
Esempio n. 3
0
        // ***
        private static void AggregateFromMultipleSources()
        {
            IEnumerable <ReplayResult <object> > pc1    = JsonStreamAggregator.Load <object>("masterdata.json");
            IEnumerable <ReplayResult <object> > pc2    = JsonStreamAggregator.Load <object>("masterdata.json");
            IEnumerable <ReplayResult <object> > merged = pc1.Concat(pc2);

            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new CountMetric())
                                             .Add(new TransactionsPerSecMetric());

            StreamAggregator.Replay(merged);

            Console.WriteLine("## Merged demo ##");
            Console.WriteLine(JsonConvert.SerializeObject(aggregator.BuildResultsObjects(), Formatting.Indented));
            Console.ReadKey();
        }
Esempio n. 4
0
        static void Main()
        {
            ReadmeDemo.Run();

            return;

            HistogramAggregator histo = new HistogramAggregator();

            histo
            .Add(new TimeDimension(TimeSpan.FromSeconds(1)))
            .Add(new CountMetric())
            .Add(new AvgDurationMetric())
            .Add(new PercentileMetric(0.95));


            JsonStreamAggregator.Replay("d:\\test.stream.json", histo);
        }
Esempio n. 5
0
        public static void Aggregate()
        {
            // Feature disabled?
            if (!File.Exists("masterdata.json"))
            {
                return;
            }

            // Any random aggregator
            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new FuncDimension("Created Threads", i => i.CreatedThreads.ToString()))
                                             .Add(new CountMetric());

            // [TUserData] - Type of UserData object in your tests (If not using it, leave object)
            // Correct type is required to prevent deserialization problems.
            JsonStreamAggregator.Replay <object>("masterdata.json", aggregator);

            Console.WriteLine("## JsonStreamAggregator demo ##");
            Console.WriteLine(JsonConvert.SerializeObject(aggregator.BuildResultsObjects(), Formatting.Indented));
            Console.ReadKey();
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
        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();
        }