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."); }
void PullCigarette() { StringBuilder sb = new StringBuilder(); MixInfo info = MixedClass.GetMixCig(machineSeq, groupNo, 0)[0]; if (MixedClass.UpdatePullStatus2Put3(info.CigCode, machineSeq, info.SortNum)) { WriteLog.GetLog().Write("<点击放烟成功>"); BtnRemove.Enabled = false; BtnRemove.Visible = false; GetData(); } }
private string GetResourceDescription(ApiInfo apiInfo, MixInfo mixInfo) { if (string.IsNullOrEmpty(apiInfo.Url)) { var description = mixInfo.ProviderMix[0].DnsName; var totalProviderCount = mixInfo.ProviderMix.Sum(p => p.ProviderCount); if (totalProviderCount > 1) { description = $"{description} + {totalProviderCount - 1} more"; } return(description); } else { return(apiInfo.Url); } }
void PullCigarette(string stri) { MixInfo info = MixedClass.GetMixCig(machineSeq, groupNo, 0)[0]; WriteLog.GetLog().Write("扫到条码" + stri); if (info.CigCode.Trim() == stri.Trim() /* && info.CigName == strs[1].Trim()*/) { if (MixedClass.UpdatePullStatus2Put(machineSeq, info.SortNum, info.CigCode)) { WriteLog.GetLog().Write("<扫码放烟成功>"); BtnRemove.Enabled = false; BtnRemove.Visible = false; GetData(); str = ""; } } else { WriteLog.GetLog().Write("放烟品牌错误:扫描到条码" + stri); MessageBox.Show("放烟错误,请重放"); str = ""; } }
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(); }