From: Jérôme Benoit Date: Tue, 21 Nov 2023 19:20:19 +0000 (+0100) Subject: fix: sort round weights descending in IWRR X-Git-Tag: v3.0.6~13 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b51d859692c3830760721f06bdb2c909c1d5d9a7;p=poolifier.git fix: sort round weights descending in IWRR Signed-off-by: Jérôme Benoit --- diff --git a/.vscode/settings.json b/.vscode/settings.json index a6c38972..258931c1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -22,7 +22,7 @@ "FOSS", "Gitter", "inheritDoc", - "IWWR", + "IWRR", "jaywcjlove", "lcov", "libuv", diff --git a/CHANGELOG.md b/CHANGELOG.md index c1cad104..1e17cee6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Ensure pool statuses are checked at initialization, `start()` or `destroy()` +- Ensure pool statuses are checked at initialization, `start()` or `destroy()`. +- Sort IWRR worker choice strategy round weights in descending order. ## [3.0.5] - 2023-10-27 diff --git a/docs/api.md b/docs/api.md index f9af05a7..2b917c46 100644 --- a/docs/api.md +++ b/docs/api.md @@ -41,7 +41,7 @@ ### `pool.execute(data, name, transferList)` -`data` (optional) An object that you want to pass to your worker implementation. +`data` (optional) An object that you want to pass to your worker task function implementation. `name` (optional) A string with the task function name that you want to execute on the worker. Default: `'default'` `transferList` (optional) An array of transferable objects that you want to transfer to your [worker_threads](https://nodejs.org/api/worker_threads.html) worker implementation. diff --git a/docs/worker-choice-strategies.md b/docs/worker-choice-strategies.md index bd5f9e2b..f7380dd6 100644 --- a/docs/worker-choice-strategies.md +++ b/docs/worker-choice-strategies.md @@ -24,7 +24,7 @@ The worker weights are maximum tasks execution time. Once the worker has reached ### Interleaved weighted round robin (experimental) -The worker weights are maximum tasks execution time. The rounds are the deduplicated worker weights. +The worker weights are maximum tasks execution time. The rounds are the deduplicated worker weights in descending order. During a round, if the worker weight is superior or equal to the current round weight and its tasks execution time is inferior to the current round weight, the task is assigned to the worker. Once all workers weight have been tested, the next round starts. The default worker weights is the same for each and computed given the CPU cores speed and theirs numbers. So the default 'rounds' consists of a unique worker weight. diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index eee39ec8..9c863b56 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -170,7 +170,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< ...new Set( Object.values(this.opts.weights) .slice() - .sort((a, b) => a - b) + .sort((a, b) => b - a) ) ] }