예제 #1
0
        public async Task RunAsync()
        {
            // Complete all HTTP conversations before exiting application
            Console.CancelKeyPress += HandleControlC;

            // Retrieve all run configuration settings
            _mixInfo = _options.GetMixInfo();
            _mixInfo.Trace();

            using (var uberCsvAggregator = new CsvAggregatingMetricsHandler())
            {
                for (int i = 0; i < _mixInfo.TestRuns.Count && !_terminate; i++)
                {
                    var testRunInfo  = _mixInfo.TestRuns[i];
                    var asyncRunners = new List <Task>();

                    uberCsvAggregator.SetRpsAndConnections(testRunInfo.TargetRPS, testRunInfo.SimultaneousConnections);

                    Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Starting test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");

                    // Handle ramp up if needed
                    await RampUpAsync(testRunInfo);

                    // Initiate separate asyncfor for each API in the mix
                    if (!_terminate)
                    {
                        foreach (var apiInfo in _mixInfo.ApiMix)
                        {
                            var myFor = new AsyncFor(testRunInfo.TargetRPS * apiInfo.Percentage, GetResourceDescription(apiInfo, _mixInfo), GetTestDescription(apiInfo), testRunInfo.MeasureServerSideTime);
                            if (_mixInfo.ApiMix.Count > 1)
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleAggregatingMetricsHandler(_mixInfo.ApiMix.Count, 60).MetricsAvailableHandler;
                            }
                            else
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler;
                                myFor.PerSecondMetricsAvailable += new CsvFileMetricsHandler().MetricsAvailableHandler;
                            }

                            if (testRunInfo.TestTimeSeconds != int.MaxValue)
                            {
                                myFor.PerSecondMetricsAvailable += uberCsvAggregator.MetricsAvailableHandler;
                            }

                            _asyncForInstances.Add(myFor);
                            asyncRunners.Add(myFor.For(TimeSpan.FromSeconds(testRunInfo.TestTimeSeconds), testRunInfo.SimultaneousConnections, new MaaServiceApiCaller(apiInfo, _mixInfo.ProviderMix, testRunInfo.EnclaveInfoFile, testRunInfo.ForceReconnects).CallApi));
                        }
                    }

                    // Wait for all to be complete (happens when crtl-c is hit)
                    await Task.WhenAll(asyncRunners.ToArray());

                    Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Completed test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");
                }
            }
            Tracer.TraceInfo($"Organized shutdown complete.");
        }
예제 #2
0
        public async Task RunAsync()
        {
            // Complete all HTTP conversations before exiting application
            Console.CancelKeyPress += HandleControlC;

            // Retrieve all run configuration settings
            _mixInfo = _options.GetMixInfo();
            _mixInfo.Trace();

            using (var uberCsvAggregator = new CsvAggregatingMetricsHandler())
            {
                for (var i = 0; i < _mixInfo.TestRuns.Count && !_cancellationTokenSource.IsCancellationRequested; i++)
                {
                    var testRunInfo  = _mixInfo.TestRuns[i];
                    var asyncRunners = new List <Task>();

                    uberCsvAggregator.SetRpsAndConnections(testRunInfo.TargetRPS, testRunInfo.SimultaneousConnections);

                    Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Starting test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");

                    // Handle ramp up if needed
                    await RampUpAsync(testRunInfo);

                    // Initiate separate asyncfor for each API in the mix
                    if (!_cancellationTokenSource.IsCancellationRequested)
                    {
                        foreach (var apiInfo in _mixInfo.ApiMix)
                        {
                            var myFor = new AsyncFor(testRunInfo.TargetRPS * apiInfo.Percentage, GetResourceDescription(apiInfo, _mixInfo), GetTestDescription(apiInfo), testRunInfo.MeasureServerSideTime);
                            if (_mixInfo.ApiMix.Count > 1)
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleAggregatingMetricsHandler(_mixInfo.ApiMix.Count, 60).MetricsAvailableHandler;
                            }
                            else
                            {
                                myFor.PerSecondMetricsAvailable += new ConsoleMetricsHandler().MetricsAvailableHandler;
                            }

                            myFor.PerSecondMetricsAvailable += new CsvFileMetricsHandler().MetricsAvailableHandler;
                            if (testRunInfo.TestTimeSeconds != int.MaxValue)
                            {
                                myFor.PerSecondMetricsAvailable += uberCsvAggregator.MetricsAvailableHandler;
                            }

                            _asyncForInstances.Add(myFor);
                            asyncRunners.Add(myFor.ForAsync(
                                                 TimeSpan.FromSeconds(testRunInfo.TestTimeSeconds),
                                                 testRunInfo.SimultaneousConnections,
                                                 new MaaServiceApiCaller(apiInfo, _mixInfo.ProviderMix, testRunInfo.EnclaveInfoFile, testRunInfo.ForceReconnects).CallApi,
                                                 _cancellationTokenSource.Token));
                        }
                    }

                    // Wait for all to be complete (happens when they finish or crtl-c is hit)
                    try
                    {
                        await Task.WhenAll(asyncRunners.ToArray());
                    }
                    catch (TaskCanceledException)
                    {
                        // Ignore task cancelled if we requested cancellation via ctrl-c
                        if (_cancellationTokenSource.IsCancellationRequested)
                        {
                            Tracer.TraceInfo(($"Organized shutdown in progress.  All {asyncRunners.Count} asyncfor instances have gracefully shutdown."));
                        }
                        else
                        {
                            throw;
                        }
                    }

                    //Tracer.TraceInfo("");
                    Tracer.TraceInfo($"Completed test run #{i}   RPS: {testRunInfo.TargetRPS}  Connections: {testRunInfo.SimultaneousConnections}");
                }
            }
            Tracer.TraceInfo($"Organized shutdown complete.");

            // Print out exception history
            MaaServiceApiCaller.TraceExceptionHistory();
        }