/// <summary> /// Measures the performance of Watchers. /// </summary> /// <param name="ringMaster">RingMaster client</param> /// <param name="config">Configuration section</param> /// <param name="cancellationToken">Token that must be observed for cancellation signal</param> /// <returns>Task that tracks execution of this test</returns> private async Task SubscribePerformanceTest(IRingMasterRequestHandler ringMaster, ConfigurationSection config, CancellationToken cancellationToken) { string testPath = config.GetStringValue("TestPath"); int maxNodes = config.GetIntValue("MaxNodesToLoad"); int maxGetChildrenEnumerationCount = config.GetIntValue("MaxChildrenEnumerationCount"); int maxConcurrentWatchers = config.GetIntValue("MaxConcurrentWatchers"); int maxConcurrency = 16; SubscribeStressServiceEventSource.Log.WatcherPerformanceTestStarted(testPath, maxNodes, maxConcurrentWatchers); var instrumentation = new WatcherPerformanceInstrumentation(this.MetricsFactory); var watcherPerformanceTest = new BulkWatcherPerformance(instrumentation, maxConcurrency, cancellationToken); await watcherPerformanceTest.LoadNodes(ringMaster, testPath, maxNodes, maxGetChildrenEnumerationCount); await Task.Run(() => watcherPerformanceTest.SetWatchers(ringMaster)); }
/// <summary> /// Measures the performance of Watchers. /// </summary> /// <param name="ringMaster">RingMaster client</param> /// <param name="maxConcurrentWatchers">Maximum number of concurrent watchers</param> /// <param name="cancellation">The cancellation.</param> /// <returns> /// Task that tracks execution of this test /// </returns> private async Task WatcherPerformanceTest(IRingMasterRequestHandler ringMaster, int maxConcurrentWatchers, CancellationTokenSource cancellation) { Trace.TraceInformation($"Watcher performance test path={this.TestPath} batchLength={this.BatchLength}"); var cancellationToken = cancellation.Token; var instrumentation = new WatcherPerformanceInstrumentation(); var watcherPerformanceTest = new WatcherPerformance(instrumentation, cancellationToken); await watcherPerformanceTest.LoadNodes(ringMaster, this.TestPath, this.MaxNodes, this.MaxGetChildrenEnumerationCount); var task = Task.Run(() => watcherPerformanceTest.SetWatchers(ringMaster, maxConcurrentWatchers)); long lastNotificationCount = 0; var timer = Stopwatch.StartNew(); while (!task.Wait(5000)) { timer.Stop(); long rate = (long)((instrumentation.Notifications - lastNotificationCount) * 1000) / timer.ElapsedMilliseconds; Trace.TraceInformation($"Watchers success={instrumentation.Success} failure={instrumentation.Failure} notifications={instrumentation.Notifications} notificationRate={rate}"); timer.Restart(); lastNotificationCount = instrumentation.Notifications; } }