public static void Run()
        {
            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new TimeDimension(TimeSpan.FromSeconds(10)))
                                             .Add(new FuncMetric <int>("Working Threads", 0, (i, r) => Math.Max(r.CreatedThreads - r.IdleThreads, i)))
                                             .Add(new CountMetric(Checkpoint.NotMeassuredCheckpoints))
                                             .Add(new TransactionsPerSecMetric());

            KpiPrinterAggregator kpi = new KpiPrinterAggregator(
                TimeSpan.FromSeconds(4),
                new FuncMetric <string>("T+", "???", (s, result) => result.IterationFinished.ToString("g")),
                new FuncMetric <int>("Created Threads", 0, (i, r) => Math.Max(r.CreatedThreads, i)),
                new FuncMetric <int>("Working Threads", 0, (i, r) => Math.Max(r.CreatedThreads - r.IdleThreads, i)),
                new CountMetric(Checkpoint.NotMeassuredCheckpoints),
                new CountMetric(i => i / 2.0, Checkpoint.NotMeassuredCheckpoints)
            {
                Prefix = "TPS "
            }
                );

            StrategyBuilder strategy = new StrategyBuilder()
                                       .SetScenario <LimitConcurrencyAndTpsDemo>()
                                       .AddSpeed(new LimitWorkingThreads(11))
                                       .AddSpeed(new IncrementalSpeed(1, TimeSpan.FromSeconds(20), 10))
                                       .SetThreading(new IncrementalThreadCount(250, TimeSpan.FromSeconds(10), -50))
                                       .SetLimit(new TimeLimit(TimeSpan.FromSeconds(52)))
                                       .SetAggregator(aggregator, kpi);

            strategy.Build().Run();

            Console.WriteLine(JsonConvert.SerializeObject(aggregator.BuildResultsObjects(), Formatting.Indented));
        }
示例#2
0
        public static void Run()
        {
            // [2] Results aggregation (Or raw measurement collection, see RawDataMeasurementsDemo.cs)
            // Define how data gets aggregated.
            // Dimensions are like GROUP BY keys in SQL
            // Metrics are aggregation functions like COUNT, SUM, etc..
            // Extensive HistogramAggregator demo now WiP
            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new TimeDimension(TimeSpan.FromSeconds(5)))
                                             .Add(new CountMetric())
                                             .Add(new ErrorCountMetric())
                                             .Add(new TransactionsPerSecMetric())
                                             .Add(new PercentileMetric(0.95, 0.99));

            // Secondary aggregation just to monitor key metrics.
            KpiPrinterAggregator kpiPrinter = new KpiPrinterAggregator(
                TimeSpan.FromSeconds(5),
                new CountMetric(Checkpoint.NotMeassuredCheckpoints),
                new ErrorCountMetric(false),
                new TransactionsPerSecMetric()
                );

            // [3] Execution settings
            // Using StrategyBuilder put defined aggregation, scenario, and execution settings into one object
            StrategyBuilder strategy = new StrategyBuilder()
                                       .SetAggregator(aggregator, kpiPrinter)             // Optional
                                       .SetScenario <BlankScenario>()                     // Required
                                       .SetLimit(new TimeLimit(TimeSpan.FromSeconds(20))) // Optional, but if not provided, execution will never stop - unless running test with RunAsync() and stopping later with CancelAsync(true)
                                       .SetSpeed(new FixedSpeed(100000))                  // Optional (Skip for maximum throughput)
                                       .SetThreading(new FixedThreadCount(4));            // Required



            // [4] Execution
            // All that's left is Build(), run and wait for completion and print out measured results.
            LoadRunnerEngine engine = strategy.Build();

            engine.Run();

            IEnumerable <object> result = aggregator.BuildResultsObjects();

            Console.WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
        }