From: Jérôme Benoit Date: Fri, 25 Aug 2023 17:28:18 +0000 (+0200) Subject: docs: refine worker choice strategies documentation X-Git-Tag: v2.6.35~6 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=970b38d6f87c7d0d29498f13af934c8ff6d472f5;p=poolifier.git docs: refine worker choice strategies documentation Signed-off-by: Jérôme Benoit --- diff --git a/docs/worker-choice-strategies.md b/docs/worker-choice-strategies.md index e79bd20c..b26819a4 100644 --- a/docs/worker-choice-strategies.md +++ b/docs/worker-choice-strategies.md @@ -25,7 +25,7 @@ The worker weights are maximum tasks execution time, once the worker has reached ### Interleaved weighted round robin The worker weights are maximum tasks execution time. The rounds are the deduplicated worker weights. -During a round, if worker weight is inferior to the current round weight, the next task is assigned to the next worker. Once all workers have been assigned a task, the next round starts. +During a round, if the worker weight is superior or equal 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. ## Statistics diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index 5f2edb25..855c7ad1 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -97,7 +97,7 @@ export interface WorkerChoiceStrategyOptions { readonly elu?: MeasurementOptions /** * Worker weights to use for weighted round robin worker selection strategies. - * A weight is the tasks maximum execution in milliseconds for each worker node. + * A weight is the tasks maximum execution time in milliseconds for each worker node. * * @defaultValue Weights computed automatically given the CPU performance. */ diff --git a/src/utils.ts b/src/utils.ts index f1c0d923..6178d8f1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,5 @@ import * as os from 'node:os' +import { getRandomValues } from 'node:crypto' import type { MeasurementStatisticsRequirements, WorkerChoiceStrategyOptions @@ -252,6 +253,6 @@ export const once = ( * * @returns A number in the [0,1[ range */ -const secureRandom = (): number => { - return crypto.getRandomValues(new Uint32Array(1))[0] / 0x100000000 +export const secureRandom = (): number => { + return getRandomValues(new Uint32Array(1))[0] / 0x100000000 } diff --git a/tests/utils.test.js b/tests/utils.test.js index 97b5e8a9..76abf046 100644 --- a/tests/utils.test.js +++ b/tests/utils.test.js @@ -11,6 +11,7 @@ const { isPlainObject, median, round, + secureRandom, updateMeasurementStatistics } = require('../lib/utils') const { KillBehaviors } = require('../lib/worker/worker-options') @@ -196,4 +197,11 @@ describe('Utils test suite', () => { history: new CircularArray(DEFAULT_CIRCULAR_ARRAY_SIZE, 0.001, 0.003) }) }) + + it('Verify secureRandom() behavior', () => { + const randomNumber = secureRandom() + expect(typeof randomNumber === 'number').toBe(true) + expect(randomNumber).toBeGreaterThanOrEqual(0) + expect(randomNumber).toBeLessThan(1) + }) })