/// <summary> /// Sets the max parallelism for the given queue /// </summary> public void SetMaxParallelDegreeByKind(DispatcherKind kind, int maxParallelDegree) { if (m_queuesByKind[kind].AdjustParallelDegree(maxParallelDegree) && maxParallelDegree > 0) { TriggerDispatcher(); } }
internal void Dequeued() { if (m_currentQueue != DispatcherKind.None) { var duration = DateTime.UtcNow - m_queueEnterTime; QueueDurations.Value[(int)m_currentQueue] += duration; m_currentQueue = DispatcherKind.None; } }
/// <summary> /// Sets the max parallelism for the given queue /// </summary> public void SetMaxParallelDegreeByKind(DispatcherKind kind, int maxParallelDegree) { if (maxParallelDegree == 0) { // We only allow 0 for ChooseWorkerCpu and ChooseWorkerCacheLookup dispatchers. // For all other dispatchers, 0 is not allowed for potential deadlocks. if (!kind.IsChooseWorker()) { maxParallelDegree = 1; } } if (m_queuesByKind[kind].AdjustParallelDegree(maxParallelDegree) && maxParallelDegree > 0) { TriggerDispatcher(); } }
internal void Dequeued(bool hasWaitedForMaterializeOutputsInBackground) { if (m_currentQueue != DispatcherKind.None) { var duration = DateTime.UtcNow - m_queueEnterTime; if (hasWaitedForMaterializeOutputsInBackground) { QueueWaitDurationForMaterializeOutputsInBackground = duration; } else { QueueDurations.Value[(int)m_currentQueue] += duration; } m_currentQueue = DispatcherKind.None; } }
protected ChooseWorkerContext( LoggingContext loggingContext, IReadOnlyList <Worker> workers, IPipQueue pipQueue, DispatcherKind kind, int maxParallelDegree) { Workers = workers; PipQueue = pipQueue; LocalWorker = (LocalWorker)workers[0]; LoggingContext = loggingContext; Kind = kind; MaxParallelDegree = maxParallelDegree; foreach (var worker in Workers) { worker.ResourcesChanged += OnWorkerResourcesChanged; } }
internal void Enqueued(DispatcherKind kind) { m_currentQueue = kind; m_queueEnterTime = DateTime.UtcNow; }
/// <inheritdoc/> public int GetMaxParallelDegreeByKind(DispatcherKind queueKind) => m_innerQueue.GetMaxParallelDegreeByKind(queueKind);
/// <inheritdoc/> public void SetMaxParallelDegreeByKind(DispatcherKind queueKind, int maxParallelDegree) => m_innerQueue.SetMaxParallelDegreeByKind(queueKind, maxParallelDegree);
/// <inheritdoc/> public int GetNumQueuedByKind(DispatcherKind queueKind) => m_innerQueue.GetNumQueuedByKind(queueKind);
internal void UnpauseChooseWorkerQueueIfEnqueuingNewPip(RunnablePip runnablePip, DispatcherKind nextQueue) { // If enqueuing a new highest priority pip to queue if (nextQueue == DispatcherKind.ChooseWorkerCpu) { if (runnablePip != m_lastIterationBlockedPip) { TogglePauseChooseWorkerQueue(pause: false); } // Capture the sequence number which will be used to compare if ChooseWorker queue is paused // waiting for resources for this pip to avoid race conditions where pip cannot acquire worker // resources become available then queue is paused potentially indefinitely (not likely but theoretically // possilbe) runnablePip.ChooseWorkerSequenceNumber = Volatile.Read(ref WorkerEnableSequenceNumber); } }
/// <inheritdoc/> public int GetMaxParallelDegreeByKind(DispatcherKind kind) => m_queuesByKind[kind].MaxParallelDegree;
/// <inheritdoc/> public int GetNumQueuedByKind(DispatcherKind kind) => m_queuesByKind[kind].NumQueued;
/// <inheritdoc/> public int GetNumRunningByKind(DispatcherKind kind) => m_queuesByKind[kind].NumRunning;
/// <inheritdoc/> public bool IsUseWeightByKind(DispatcherKind kind) => m_queuesByKind[kind].UseWeight;
/// <inheritdoc/> public int GetNumAcquiredSlotsByKind(DispatcherKind kind) => m_queuesByKind[kind].NumAcquiredSlots;
/// <summary> /// Whether this dispatcher represents a logic for choosing a worker. /// </summary> public static bool IsChooseWorker(this DispatcherKind kind) { return(kind == DispatcherKind.ChooseWorkerLight || kind == DispatcherKind.ChooseWorkerCacheLookup || kind == DispatcherKind.ChooseWorkerCpu); }