}
}
+ /** @inheritDoc */
+ public hasWorkerNodeBackPressure (workerNodeKey: number): boolean {
+ if (
+ this.opts.enableTasksQueue === true &&
+ this.workerNodes[workerNodeKey].hasBackPressure()
+ ) {
+ return true
+ }
+ return false
+ }
+
/**
* Executes the given task on the worker given its worker node key.
*
}
private enqueueTask (workerNodeKey: number, task: Task<Data>): number {
- if (
- this.opts.enableTasksQueue === true &&
- this.workerNodes[workerNodeKey].hasBackPressure()
- ) {
+ const tasksQueueSize = this.workerNodes[workerNodeKey].enqueueTask(task)
+ if (this.hasWorkerNodeBackPressure(workerNodeKey)) {
this.emitter?.emit(PoolEvents.backPressure, {
workerId: this.getWorkerInfo(workerNodeKey).id,
...this.info
})
}
- return this.workerNodes[workerNodeKey].enqueueTask(task)
+ return tasksQueueSize
}
private dequeueTask (workerNodeKey: number): Task<Data> | undefined {
* Pool worker nodes.
*/
readonly workerNodes: Array<IWorkerNode<Worker, Data>>
+ /**
+ * Whether the worker node has back pressure (i.e. its tasks queue is full).
+ *
+ * @param workerNodeKey - The worker node key.
+ * @returns `true` if the worker node has back pressure, `false` otherwise.
+ */
+ readonly hasWorkerNodeBackPressure: (workerNodeKey: number) => boolean
/**
* Emitter on which events can be listened to.
*
return this.pool.workerNodes[workerNodeKey].info.ready
}
+ /**
+ * Whether the worker node has back pressure or not (i.e. its tasks queue is full).
+ *
+ * @param workerNodeKey - The worker node key.
+ * @returns `true` if the worker node has back pressure, `false` otherwise.
+ */
+ protected hasWorkerNodeBackPressure (workerNodeKey: number): boolean {
+ return this.pool.hasWorkerNodeBackPressure(workerNodeKey)
+ }
+
/**
* Gets the worker task runtime.
* If the task statistics require the average runtime, the average runtime is returned.
public usage: WorkerUsage
private readonly tasksUsage: Map<string, WorkerUsage>
private readonly tasksQueue: Queue<Task<Data>>
- private readonly tasksQueueBackPressureMaxSize: number
+ private readonly tasksQueueBackPressureSize: number
/**
* Constructs a new worker node.
this.usage = this.initWorkerUsage()
this.tasksUsage = new Map<string, WorkerUsage>()
this.tasksQueue = new Queue<Task<Data>>()
- this.tasksQueueBackPressureMaxSize = Math.pow(poolMaxSize, 2)
+ this.tasksQueueBackPressureSize = Math.pow(poolMaxSize, 2)
}
/** @inheritdoc */
/** @inheritdoc */
public hasBackPressure (): boolean {
- return this.tasksQueueSize() >= this.tasksQueueBackPressureMaxSize
+ return this.tasksQueueSize() >= this.tasksQueueBackPressureSize
}
/** @inheritdoc */
*/
readonly clearTasksQueue: () => void
/**
- * Whether the worker node has back pressure.
+ * Whether the worker node has back pressure (i.e. its tasks queue is full).
*
* @returns `true` if the worker node has back pressure, `false` otherwise.
*/