feat: expose the number of strategy retries in pool info
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 7 Jan 2024 20:25:40 +0000 (21:25 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 7 Jan 2024 20:25:40 +0000 (21:25 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
package.json
pnpm-lock.yaml
src/pools/abstract-pool.ts
src/pools/pool.ts
src/pools/selection-strategies/worker-choice-strategy-context.ts
tests/pools/abstract-pool.test.mjs

index 8ca73c22ea4c8df7355278f8facbeca96f834425..c97f90cb90d54052b493fc2089d11206fdd9f89f 100644 (file)
     "@release-it/keep-a-changelog": "^5.0.0",
     "@rollup/plugin-terser": "^0.4.4",
     "@rollup/plugin-typescript": "^11.1.5",
-    "@types/node": "^20.10.6",
+    "@types/node": "^20.10.7",
     "@typescript-eslint/eslint-plugin": "^6.18.0",
     "@typescript-eslint/parser": "^6.18.0",
     "benchmark": "^2.1.4",
index cc074b1ccffe3dd4a313a89f5b5c825da46716c0..38148a1bdec78bfd4ae0dd0b009b869ce39ace68 100644 (file)
@@ -13,7 +13,7 @@ devDependencies:
     version: 1.4.1
   '@commitlint/cli':
     specifier: ^18.4.4
-    version: 18.4.4(@types/node@20.10.6)(typescript@5.3.3)
+    version: 18.4.4(@types/node@20.10.7)(typescript@5.3.3)
   '@commitlint/config-conventional':
     specifier: ^18.4.4
     version: 18.4.4
@@ -30,8 +30,8 @@ devDependencies:
     specifier: ^11.1.5
     version: 11.1.5(rollup@4.9.4)(typescript@5.3.3)
   '@types/node':
-    specifier: ^20.10.6
-    version: 20.10.6
+    specifier: ^20.10.7
+    version: 20.10.7
   '@typescript-eslint/eslint-plugin':
     specifier: ^6.18.0
     version: 6.18.0(@typescript-eslint/parser@6.18.0)(eslint@8.56.0)(typescript@5.3.3)
@@ -232,14 +232,14 @@ packages:
     dev: true
     optional: true
 
-  /@commitlint/cli@18.4.4(@types/node@20.10.6)(typescript@5.3.3):
+  /@commitlint/cli@18.4.4(@types/node@20.10.7)(typescript@5.3.3):
     resolution: {integrity: sha512-Ro3wIo//fV3XiV1EkdpHog6huaEyNcUAVrSmtgKqYM5g982wOWmP4FXvEDFwRMVgz878CNBvvCc33dMZ5AQJ/g==}
     engines: {node: '>=v18'}
     hasBin: true
     dependencies:
       '@commitlint/format': 18.4.4
       '@commitlint/lint': 18.4.4
-      '@commitlint/load': 18.4.4(@types/node@20.10.6)(typescript@5.3.3)
+      '@commitlint/load': 18.4.4(@types/node@20.10.7)(typescript@5.3.3)
       '@commitlint/read': 18.4.4
       '@commitlint/types': 18.4.4
       execa: 5.1.1
@@ -310,7 +310,7 @@ packages:
       '@commitlint/types': 18.4.4
     dev: true
 
-  /@commitlint/load@18.4.4(@types/node@20.10.6)(typescript@5.3.3):
+  /@commitlint/load@18.4.4(@types/node@20.10.7)(typescript@5.3.3):
     resolution: {integrity: sha512-RaDIa9qwOw2xRJ3Jr2DBXd14rmnHJIX2XdZF4kmoF1rgsg/+7cvrExLSUNAkQUNimyjCn1b/bKX2Omm+GdY0XQ==}
     engines: {node: '>=v18'}
     dependencies:
@@ -320,7 +320,7 @@ packages:
       '@commitlint/types': 18.4.4
       chalk: 4.1.2
       cosmiconfig: 8.3.6(typescript@5.3.3)
-      cosmiconfig-typescript-loader: 5.0.0(@types/node@20.10.6)(cosmiconfig@8.3.6)(typescript@5.3.3)
+      cosmiconfig-typescript-loader: 5.0.0(@types/node@20.10.7)(cosmiconfig@8.3.6)(typescript@5.3.3)
       lodash.isplainobject: 4.0.6
       lodash.merge: 4.6.2
       lodash.uniq: 4.5.0
@@ -492,7 +492,7 @@ packages:
       '@jest/schemas': 29.6.3
       '@types/istanbul-lib-coverage': 2.0.6
       '@types/istanbul-reports': 3.0.4
-      '@types/node': 20.10.6
+      '@types/node': 20.10.7
       '@types/yargs': 17.0.32
       chalk: 4.1.2
     dev: true
@@ -948,7 +948,7 @@ packages:
     resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
     dependencies:
       '@types/minimatch': 5.1.2
-      '@types/node': 20.10.6
+      '@types/node': 20.10.7
     dev: true
 
   /@types/http-cache-semantics@4.0.4:
@@ -987,8 +987,8 @@ packages:
     resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==}
     dev: true
 
-  /@types/node@20.10.6:
-    resolution: {integrity: sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==}
+  /@types/node@20.10.7:
+    resolution: {integrity: sha512-fRbIKb8C/Y2lXxB5eVMj4IU7xpdox0Lh8bUPEdtLysaylsml1hOOx1+STloRs/B9nf7C6kPRmmg/V7aQW7usNg==}
     dependencies:
       undici-types: 5.26.5
     dev: true
@@ -1808,7 +1808,7 @@ packages:
     resolution: {integrity: sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==}
     dev: true
 
-  /cosmiconfig-typescript-loader@5.0.0(@types/node@20.10.6)(cosmiconfig@8.3.6)(typescript@5.3.3):
+  /cosmiconfig-typescript-loader@5.0.0(@types/node@20.10.7)(cosmiconfig@8.3.6)(typescript@5.3.3):
     resolution: {integrity: sha512-+8cK7jRAReYkMwMiG+bxhcNKiHJDM6bR9FD/nGBXOWdMLuYawjF5cGrtLilJ+LGd3ZjCXnJjR5DkfWPoIVlqJA==}
     engines: {node: '>=v16'}
     peerDependencies:
@@ -1816,7 +1816,7 @@ packages:
       cosmiconfig: '>=8.2'
       typescript: '>=4'
     dependencies:
-      '@types/node': 20.10.6
+      '@types/node': 20.10.7
       cosmiconfig: 8.3.6(typescript@5.3.3)
       jiti: 1.21.0
       typescript: 5.3.3
@@ -3669,7 +3669,7 @@ packages:
     engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
     dependencies:
       '@jest/types': 29.6.3
-      '@types/node': 20.10.6
+      '@types/node': 20.10.7
       chalk: 4.1.2
       ci-info: 3.9.0
       graceful-fs: 4.2.11
@@ -4050,7 +4050,7 @@ packages:
     requiresBuild: true
     dependencies:
       node-addon-api: 5.1.0
-      node-gyp-build: 4.7.1
+      node-gyp-build: 4.8.0
     dev: true
 
   /mime-db@1.52.0:
@@ -4250,8 +4250,8 @@ packages:
       formdata-polyfill: 4.0.10
     dev: true
 
-  /node-gyp-build@4.7.1:
-    resolution: {integrity: sha512-wTSrZ+8lsRRa3I3H8Xr65dLWSgCvY2l4AOnaeKdPA9TB/WYMPaTcrzf3rXvFoVvjKNVnu0CcWSx54qq9GKRUYg==}
+  /node-gyp-build@4.8.0:
+    resolution: {integrity: sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==}
     hasBin: true
     dev: true
 
index 2b834158914a93a49aca61cd0ed7f41b2f1e2451..3f6fa98ae373cfb7054747f089ebaa6fb0c84420 100644 (file)
@@ -283,6 +283,7 @@ export abstract class AbstractPool<
       ready: this.ready,
       // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
       strategy: this.opts.workerChoiceStrategy!,
+      strategyRetries: this.workerChoiceStrategyContext?.retriesCount ?? 0,
       minSize: this.minimumNumberOfWorkers,
       maxSize: this.maximumNumberOfWorkers ?? this.minimumNumberOfWorkers,
       ...(this.workerChoiceStrategyContext?.getTaskStatisticsRequirements()
index cda63d881f0bab742cf0412cfa266714fdefeb27..73ca3aa105e477add5fd11d3d5cd19911c41f115 100644 (file)
@@ -64,6 +64,7 @@ export interface PoolInfo {
   readonly started: boolean
   readonly ready: boolean
   readonly strategy: WorkerChoiceStrategy
+  readonly strategyRetries: number
   readonly minSize: number
   readonly maxSize: number
   /** Pool utilization. */
index 40e2e18f303122685c70eb09e824175ab5309cef..d3d2ae56004c37698c5c7b0e055e27b3725f4c7e 100644 (file)
@@ -29,6 +29,11 @@ export class WorkerChoiceStrategyContext<
   Data = unknown,
   Response = unknown
 > {
+  /**
+   * The number of worker choice strategy execution retries.
+   */
+  public retriesCount: number
+
   /**
    * The worker choice strategy instances registered in the context.
    */
@@ -38,7 +43,7 @@ export class WorkerChoiceStrategyContext<
   >
 
   /**
-   * The number of worker choice strategy execution retries.
+   * The maximum number of worker choice strategy execution retries.
    */
   private readonly retries: number
 
@@ -111,6 +116,7 @@ export class WorkerChoiceStrategyContext<
         >(pool, opts)
       ]
     ])
+    this.retriesCount = 0
     this.retries = getWorkerChoiceStrategyRetries(pool, opts)
   }
 
@@ -189,7 +195,8 @@ export class WorkerChoiceStrategyContext<
     do {
       workerNodeKey = workerChoiceStrategy.choose()
       if (workerNodeKey == null && chooseCount > 0) {
-        retriesCount++
+        ++retriesCount
+        ++this.retriesCount
       }
       chooseCount++
     } while (workerNodeKey == null && retriesCount < this.retries)
index 84a0195e0cfd3b1aaef9b818476891b11a61cbc5..4b32e253a3aed5c203bfff7476d49a02a6b4488c 100644 (file)
@@ -704,6 +704,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: 0,
       minSize: numberOfWorkers,
       maxSize: numberOfWorkers,
       workerNodes: numberOfWorkers,
@@ -726,6 +727,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: 0,
       minSize: Math.floor(numberOfWorkers / 2),
       maxSize: numberOfWorkers,
       workerNodes: Math.floor(numberOfWorkers / 2),
@@ -1075,6 +1077,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: expect.any(Number),
       minSize: expect.any(Number),
       maxSize: expect.any(Number),
       workerNodes: expect.any(Number),
@@ -1115,6 +1118,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: expect.any(Number),
       minSize: expect.any(Number),
       maxSize: expect.any(Number),
       workerNodes: expect.any(Number),
@@ -1154,6 +1158,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: expect.any(Number),
       minSize: expect.any(Number),
       maxSize: expect.any(Number),
       workerNodes: expect.any(Number),
@@ -1196,6 +1201,7 @@ describe('Abstract pool test suite', () => {
       started: true,
       ready: true,
       strategy: WorkerChoiceStrategies.ROUND_ROBIN,
+      strategyRetries: expect.any(Number),
       minSize: expect.any(Number),
       maxSize: expect.any(Number),
       workerNodes: expect.any(Number),