this.setupHook()
- while (this.workerNodes.length < this.numberOfWorkers) {
+ while (
+ this.workerNodes.reduce(
+ (accumulator, workerNode) =>
+ !workerNode.info.dynamic ? accumulator + 1 : accumulator,
+ 0
+ ) < this.numberOfWorkers
+ ) {
this.createAndSetupWorker()
}
throw new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
- } else if (min === 0 && max === 0) {
+ } else if (max === 0) {
throw new RangeError(
- 'Cannot instantiate a dynamic pool with a minimum pool size and a maximum pool size equal to zero'
+ 'Cannot instantiate a dynamic pool with a pool size equal to zero'
)
} else if (min === max) {
throw new RangeError(
}
private get starting (): boolean {
- return this.workerNodes.length < this.minSize
+ return (
+ this.workerNodes.reduce(
+ (accumulator, workerNode) =>
+ !workerNode.info.dynamic ? accumulator + 1 : accumulator,
+ 0
+ ) < this.minSize
+ )
}
private get ready (): boolean {
return (
- this.workerNodes.length >= this.minSize &&
- this.workerNodes.every(
- (workerNode, workerNodeKey) =>
- workerNodeKey < this.minSize && workerNode.info.ready
- )
+ this.workerNodes.reduce(
+ (accumulator, workerNode) =>
+ !workerNode.info.dynamic && workerNode.info.ready
+ ? accumulator + 1
+ : accumulator,
+ 0
+ ) >= this.minSize
)
}
}
})
const workerInfo = this.getWorkerInfo(this.getWorkerNodeKey(worker))
- workerInfo.ready = true
+ if (this.workerChoiceStrategyContext.getStrategyPolicy().useDynamicWorker) {
+ workerInfo.ready = true
+ }
workerInfo.dynamic = true
this.sendToWorker(worker, {
checkAlive: true,
*/
private pushWorkerNode (worker: Worker): number {
const workerNode = new WorkerNode<Worker, Data>(worker, this.worker)
- // Flag the worker as ready at pool startup.
+ // Flag the worker node as ready at pool startup.
if (this.starting) {
workerNode.info.ready = true
}
new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
).toThrowError(
new RangeError(
- 'Cannot instantiate a dynamic pool with a minimum pool size and a maximum pool size equal to zero'
+ 'Cannot instantiate a dynamic pool with a pool size equal to zero'
)
)
})
}
})
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
- expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier)
+ expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
+ numberOfWorkers * maxMultiplier
+ )
+ expect(workerNode.usage.runTime.history.length).toBe(0)
+ expect(workerNode.usage.waitTime.history.length).toBe(0)
+ expect(workerNode.usage.elu.idle.history.length).toBe(0)
+ expect(workerNode.usage.elu.active.history.length).toBe(0)
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
})
expect(workerNode.usage.runTime.history.length).toBe(0)
expect(workerNode.usage.waitTime.history.length).toBe(0)
+ expect(workerNode.usage.elu.idle.history.length).toBe(0)
+ expect(workerNode.usage.elu.active.history.length).toBe(0)
}
await pool.destroy()
})