### Added
-- Add back pressure detection on the worker node queue. Event `backPressure` is emitted when the worker node queue is full (size > poolMaxSize^2).
+- Add back pressure detection on the worker node queue. Event `backPressure` is emitted all worker node queues are full (size > poolMaxSize^2).
- Use back pressure detection in worker choice strategies.
- Add worker choice strategies retries mechanism if no worker is eligible.
/** @inheritDoc */
public hasWorkerNodeBackPressure (workerNodeKey: number): boolean {
- if (
+ return (
this.opts.enableTasksQueue === true &&
this.workerNodes[workerNodeKey].hasBackPressure()
- ) {
- return true
- }
- return false
+ )
+ }
+
+ private hasBackPressure (): boolean {
+ return (
+ this.opts.enableTasksQueue === true &&
+ this.workerNodes.findIndex(
+ (workerNode) => !workerNode.hasBackPressure()
+ ) !== -1
+ )
}
/**
private enqueueTask (workerNodeKey: number, task: Task<Data>): number {
const tasksQueueSize = this.workerNodes[workerNodeKey].enqueueTask(task)
- if (this.hasWorkerNodeBackPressure(workerNodeKey)) {
- this.emitter?.emit(PoolEvents.backPressure, {
- workerId: this.getWorkerInfo(workerNodeKey).id,
- ...this.info
- })
+ if (this.hasBackPressure()) {
+ this.emitter?.emit(PoolEvents.backPressure, this.info)
}
return tasksQueueSize
}
* - '`destroy`': Emitted when the pool is destroyed.
* - `'error'`: Emitted when an uncaught error occurs.
* - `'taskError'`: Emitted when an error occurs while executing a task.
- * - `'backPressure'`: Emitted when a worker node has back pressure (i.e. its tasks queue is full).
+ * - `'backPressure'`: Emitted when all worker nodes have back pressure (i.e. their tasks queue is full).
*/
readonly emitter?: PoolEmitter
/**