private void TryAdjustCreatedThreadCount(WorkerThreadStats threadStats) { int allowedCreatedThreadCount = _parameters.ThreadingStrategy.GetAllowedCreatedThreadCount(_timer.CurrentValue, threadStats); if (allowedCreatedThreadCount > threadStats.CreatedThreadCount) { _threadCoordinator.InitializeThreadsAsync(_parameters.ThreadingStrategy.ThreadCreateBatchSize); } else if (allowedCreatedThreadCount < threadStats.CreatedThreadCount) { _threadCoordinator.StopWorkersAsync(threadStats.CreatedThreadCount - allowedCreatedThreadCount); } }
public int GetAllowedCreatedThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { return((((int)(testExecutionTime.TotalMilliseconds / _increaseTimePeriod.TotalMilliseconds)) * ThreadCreateBatchSize) + InitialThreadCount); }
public int GetAllowedMaxWorkingThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { return(workerThreadStats.CreatedThreadCount); }
int IThreadingStrategy.GetAllowedCreatedThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { if ( workerThreadStats.CreatedThreadCount < _maxThreadCount && workerThreadStats.CreatedThreadCount == workerThreadStats.WorkingThreadCount ) { return(workerThreadStats.CreatedThreadCount + 1); } else { return(workerThreadStats.CreatedThreadCount); } }
int IThreadingStrategy.GetAllowedMaxWorkingThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { return(_maxThreadCount); }
private void RunInner() { if (_threadCoordinator != null) { throw new InvalidOperationException("Async instance is already running"); } try { _threadCoordinator = new ThreadCoordinator( _iTestScenarioObjectType, _timer, _parameters.ThreadingStrategy.InitialThreadCount ) { InitialUserData = _parameters.InitialUserData }; _threadCoordinator.ScenarioIterationFinished += _threadCoordinator_ScenarioIterationFinished; int testIterationCount = 0; TimeSpan executionEnqueueThreshold = TimeSpan.Zero; _timer.Start(); _resultsAggregator.Begin(); while (_timer.CurrentValue < _parameters.Limits.MaxDuration && testIterationCount < _parameters.Limits.MaxIterationsCount) { WorkerThreadStats threadStats = _threadCoordinator.BuildWorkerThreadStats(); int allowedWorkingthreadCount = _parameters.ThreadingStrategy.GetAllowedMaxWorkingThreadCount(_timer.CurrentValue, threadStats); _threadCoordinator.AssertThreadErrors(); TryAdjustCreatedThreadCount(threadStats); if (allowedWorkingthreadCount > threadStats.WorkingThreadCount && _timer.CurrentValue >= executionEnqueueThreshold) { if (_threadCoordinator.TryEnqueueSingleIteration()) { executionEnqueueThreshold = CalculateNextExecutionTime(executionEnqueueThreshold); testIterationCount++; } else { Thread.Sleep(1); } } else { Thread.Sleep(1); } //_timer.UpdateCurrent(); } } finally { _threadCoordinator?.StopAndDispose((int)_parameters.Limits.FinishTimeout.TotalMilliseconds); _resultsAggregator.End(); _threadCoordinator?.AssertThreadErrors(); _threadCoordinator = null; _timer.Stop(); } }
int IThreadingStrategy.GetAllowedCreatedThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { return(_createdThreadCount); }
int IThreadingStrategy.GetAllowedMaxWorkingThreadCount(TimeSpan testExecutionTime, WorkerThreadStats workerThreadStats) { return((((int)(testExecutionTime.TotalMilliseconds / _increaseTimePeriod.TotalMilliseconds)) * _increaseBatchSize) + _initialWorkingThreadCount); }