internal void CheckForLongTurns() { if ((CurrentWorkItem == null && CurrentTask == null) || (Utils.Since(CurrentStateStarted) <= OrleansTaskScheduler.TurnWarningLengthThreshold)) { return; } // Since this thread is running a long turn, which (we hope) is blocked on some IO // or other external process, we'll create a replacement thread and tell this thread to // exit when it's done with the turn. // Note that we only do this if the current load is reasonably low and the current thread // count is reasonably small. if (!pool.InjectMoreWorkerThreads || pool.BusyWorkerCount >= MAX_THREAD_COUNT_TO_REPLACE || (Silo.CurrentSilo == null || !(Silo.CurrentSilo.Metrics.CpuUsage < MAX_CPU_USAGE_TO_REPLACE))) { return; } if (Cts.IsCancellationRequested) { return; } // only create a new thread once per slow thread! Log.Warn(ErrorCode.SchedulerTurnTooLong2, string.Format( "Worker pool thread {0} (ManagedThreadId={1}) has been busy for long time: {2}; creating a new worker thread", Name, ManagedThreadId, GetThreadStatus())); Cts.Cancel(); pool.CreateNewThread(); // Consider: mark the activation running a long turn to reduce it's time quantum }
internal void CheckForLongTurns() { if (!IsFrozen()) { return; } // Since this thread is running a long turn, which (we hope) is blocked on some IO // or other external process, we'll create a replacement thread and tell this thread to // exit when it's done with the turn. // Note that we only do this if the current load is reasonably low and the current thread // count is reasonably small. if (!pool.ShouldInjectWorkerThread || !(this.performanceMetrics.CpuUsage < MAX_CPU_USAGE_TO_REPLACE)) { return; } if (Cts.IsCancellationRequested) { return; } // only create a new thread once per slow thread! Log.Warn(ErrorCode.SchedulerTurnTooLong2, string.Format( "Worker pool thread {0} (ManagedThreadId={1}) has been busy for long time: {2}; creating a new worker thread", Name, ManagedThreadId, GetThreadStatus(true))); Cts.Cancel(); pool.CreateNewThread(); // Consider: mark the activation running a long turn to reduce it's time quantum }