perf: pickup free worker in the less busy and used strategies for fixed
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Apr 2023 23:32:38 +0000 (01:32 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Apr 2023 23:32:38 +0000 (01:32 +0200)
pool

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/less-busy-worker-choice-strategy.ts
src/pools/selection-strategies/less-used-worker-choice-strategy.ts

index e9ba619a9767814acae8c2dd4caec7d07fc0dcd6..61e2d369db8e0b6280d03ca6d5277c5e63bef8c9 100644 (file)
@@ -26,6 +26,10 @@ export class LessBusyWorkerChoiceStrategy<
 
   /** {@inheritDoc} */
   public choose (): number {
+    const freeWorkerKey = this.pool.findFreeWorkerKey()
+    if (!this.isDynamicPool && freeWorkerKey !== false) {
+      return freeWorkerKey
+    }
     let minRunTime = Infinity
     let lessBusyWorkerKey!: number
     for (const [index, workerItem] of this.pool.workers.entries()) {
index f653160bdb29ece08cd5f1265012739da3443044..7fe56ef9dd2293ea33aaf3a9f4a2d3cda28be451 100644 (file)
@@ -20,6 +20,10 @@ export class LessUsedWorkerChoiceStrategy<
 
   /** {@inheritDoc} */
   public choose (): number {
+    const freeWorkerKey = this.pool.findFreeWorkerKey()
+    if (!this.isDynamicPool && freeWorkerKey !== false) {
+      return freeWorkerKey
+    }
     let minNumberOfTasks = Infinity
     let lessUsedWorkerKey!: number
     for (const [index, workerItem] of this.pool.workers.entries()) {