poolifier 2.6.37 → 2.6.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/README.md +6 -3
  2. package/lib/index.d.ts +1881 -22
  3. package/lib/index.js +1 -1
  4. package/lib/index.mjs +1 -1
  5. package/package.json +4 -3
  6. package/lib/circular-array.d.ts +0 -22
  7. package/lib/deque.d.ts +0 -83
  8. package/lib/pools/abstract-pool.d.ts +0 -316
  9. package/lib/pools/cluster/dynamic.d.ts +0 -29
  10. package/lib/pools/cluster/fixed.d.ts +0 -62
  11. package/lib/pools/pool.d.ts +0 -243
  12. package/lib/pools/selection-strategies/abstract-worker-choice-strategy.d.ts +0 -104
  13. package/lib/pools/selection-strategies/fair-share-worker-choice-strategy.d.ts +0 -39
  14. package/lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.d.ts +0 -39
  15. package/lib/pools/selection-strategies/least-busy-worker-choice-strategy.d.ts +0 -26
  16. package/lib/pools/selection-strategies/least-elu-worker-choice-strategy.d.ts +0 -26
  17. package/lib/pools/selection-strategies/least-used-worker-choice-strategy.d.ts +0 -24
  18. package/lib/pools/selection-strategies/round-robin-worker-choice-strategy.d.ts +0 -24
  19. package/lib/pools/selection-strategies/selection-strategies-types.d.ts +0 -200
  20. package/lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.d.ts +0 -35
  21. package/lib/pools/selection-strategies/worker-choice-strategy-context.d.ts +0 -71
  22. package/lib/pools/thread/dynamic.d.ts +0 -29
  23. package/lib/pools/thread/fixed.d.ts +0 -54
  24. package/lib/pools/version.d.ts +0 -1
  25. package/lib/pools/worker-node.d.ts +0 -60
  26. package/lib/pools/worker.d.ts +0 -277
  27. package/lib/utility-types.d.ts +0 -152
  28. package/lib/utils.d.ts +0 -123
  29. package/lib/worker/abstract-worker.d.ts +0 -192
  30. package/lib/worker/cluster-worker.d.ts +0 -35
  31. package/lib/worker/task-functions.d.ts +0 -33
  32. package/lib/worker/thread-worker.d.ts +0 -43
  33. package/lib/worker/worker-options.d.ts +0 -61
@@ -1,104 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import type { IWorkerChoiceStrategy, StrategyPolicy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types';
4
- /**
5
- * Worker choice strategy abstract base class.
6
- *
7
- * @typeParam Worker - Type of worker which manages the strategy.
8
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
9
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
10
- */
11
- export declare abstract class AbstractWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> implements IWorkerChoiceStrategy {
12
- protected readonly pool: IPool<Worker, Data, Response>;
13
- protected opts: WorkerChoiceStrategyOptions;
14
- /**
15
- * The next worker node key.
16
- */
17
- protected nextWorkerNodeKey: number | undefined;
18
- /**
19
- * The previous worker node key.
20
- */
21
- protected previousWorkerNodeKey: number;
22
- /** @inheritDoc */
23
- readonly strategyPolicy: StrategyPolicy;
24
- /** @inheritDoc */
25
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
26
- /**
27
- * Constructs a worker choice strategy bound to the pool.
28
- *
29
- * @param pool - The pool instance.
30
- * @param opts - The worker choice strategy options.
31
- */
32
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
33
- protected setTaskStatisticsRequirements(opts: WorkerChoiceStrategyOptions): void;
34
- private toggleMedianMeasurementStatisticsRequirements;
35
- protected resetWorkerNodeKeyProperties(): void;
36
- /** @inheritDoc */
37
- abstract reset(): boolean;
38
- /** @inheritDoc */
39
- abstract update(workerNodeKey: number): boolean;
40
- /** @inheritDoc */
41
- abstract choose(): number | undefined;
42
- /** @inheritDoc */
43
- abstract remove(workerNodeKey: number): boolean;
44
- /** @inheritDoc */
45
- setOptions(opts: WorkerChoiceStrategyOptions): void;
46
- /**
47
- * Whether the worker node is ready or not.
48
- *
49
- * @param workerNodeKey - The worker node key.
50
- * @returns Whether the worker node is ready or not.
51
- */
52
- private isWorkerNodeReady;
53
- /**
54
- * Whether the worker node has back pressure or not (i.e. its tasks queue is full).
55
- *
56
- * @param workerNodeKey - The worker node key.
57
- * @returns `true` if the worker node has back pressure, `false` otherwise.
58
- */
59
- private hasWorkerNodeBackPressure;
60
- /**
61
- * Whether the worker node is eligible or not.
62
- * A worker node is eligible if it is ready and does not have back pressure.
63
- *
64
- * @param workerNodeKey - The worker node key.
65
- * @returns `true` if the worker node is eligible, `false` otherwise.
66
- * @see {@link isWorkerNodeReady}
67
- * @see {@link hasWorkerNodeBackPressure}
68
- */
69
- protected isWorkerNodeEligible(workerNodeKey: number): boolean;
70
- /**
71
- * Gets the worker task runtime.
72
- * If the task statistics require the average runtime, the average runtime is returned.
73
- * If the task statistics require the median runtime , the median runtime is returned.
74
- *
75
- * @param workerNodeKey - The worker node key.
76
- * @returns The worker task runtime.
77
- */
78
- protected getWorkerTaskRunTime(workerNodeKey: number): number;
79
- /**
80
- * Gets the worker task wait time.
81
- * If the task statistics require the average wait time, the average wait time is returned.
82
- * If the task statistics require the median wait time, the median wait time is returned.
83
- *
84
- * @param workerNodeKey - The worker node key.
85
- * @returns The worker task wait time.
86
- */
87
- protected getWorkerTaskWaitTime(workerNodeKey: number): number;
88
- /**
89
- * Gets the worker task ELU.
90
- * If the task statistics require the average ELU, the average ELU is returned.
91
- * If the task statistics require the median ELU, the median ELU is returned.
92
- *
93
- * @param workerNodeKey - The worker node key.
94
- * @returns The worker task ELU.
95
- */
96
- protected getWorkerTaskElu(workerNodeKey: number): number;
97
- /**
98
- * Check the next worker node eligibility.
99
- *
100
- * @param chosenNextWorkerNodeKey - The chosen worker node key.
101
- */
102
- protected checkNextWorkerNodeEligibility(chosenNextWorkerNodeKey: number | undefined): void;
103
- protected computeDefaultWorkerWeight(): number;
104
- }
@@ -1,39 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import { type IWorkerChoiceStrategy, type TaskStatisticsRequirements, type WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the next worker with a fair share scheduling algorithm.
7
- * Loosely modeled after the fair queueing algorithm: https://en.wikipedia.org/wiki/Fair_queuing.
8
- *
9
- * @typeParam Worker - Type of worker which manages the strategy.
10
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
11
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
12
- */
13
- export declare class FairShareWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
14
- /** @inheritDoc */
15
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
16
- /**
17
- * Workers' virtual task end execution timestamp.
18
- */
19
- private workersVirtualTaskEndTimestamp;
20
- /** @inheritDoc */
21
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
22
- /** @inheritDoc */
23
- reset(): boolean;
24
- /** @inheritDoc */
25
- update(workerNodeKey: number): boolean;
26
- /** @inheritDoc */
27
- choose(): number | undefined;
28
- /** @inheritDoc */
29
- remove(workerNodeKey: number): boolean;
30
- private fairShareNextWorkerNodeKey;
31
- /**
32
- * Computes the worker node key virtual task end timestamp.
33
- *
34
- * @param workerNodeKey - The worker node key.
35
- */
36
- private computeWorkerVirtualTaskEndTimestamp;
37
- private getWorkerVirtualTaskEndTimestamp;
38
- private getWorkerVirtualTaskStartTimestamp;
39
- }
@@ -1,39 +0,0 @@
1
- import type { IWorker } from '../worker';
2
- import type { IPool } from '../pool';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the next worker with an interleaved weighted round robin scheduling algorithm.
7
- *
8
- * @typeParam Worker - Type of worker which manages the strategy.
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- */
12
- export declare class InterleavedWeightedRoundRobinWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
13
- /**
14
- * Round id.
15
- * This is used to determine the current round weight.
16
- */
17
- private roundId;
18
- /**
19
- * Round weights.
20
- */
21
- private roundWeights;
22
- /**
23
- * Default worker weight.
24
- */
25
- private readonly defaultWorkerWeight;
26
- /** @inheritDoc */
27
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
28
- /** @inheritDoc */
29
- reset(): boolean;
30
- /** @inheritDoc */
31
- update(): boolean;
32
- /** @inheritDoc */
33
- choose(): number | undefined;
34
- /** @inheritDoc */
35
- remove(workerNodeKey: number): boolean;
36
- /** @inheritDoc */
37
- setOptions(opts: WorkerChoiceStrategyOptions): void;
38
- private getRoundWeights;
39
- }
@@ -1,26 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the least busy worker.
7
- *
8
- * @typeParam Worker - Type of worker which manages the strategy.
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- */
12
- export declare class LeastBusyWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
13
- /** @inheritDoc */
14
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
15
- /** @inheritDoc */
16
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
17
- /** @inheritDoc */
18
- reset(): boolean;
19
- /** @inheritDoc */
20
- update(): boolean;
21
- /** @inheritDoc */
22
- choose(): number | undefined;
23
- /** @inheritDoc */
24
- remove(): boolean;
25
- private leastBusyNextWorkerNodeKey;
26
- }
@@ -1,26 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the worker with the least ELU.
7
- *
8
- * @typeParam Worker - Type of worker which manages the strategy.
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- */
12
- export declare class LeastEluWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
13
- /** @inheritDoc */
14
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
15
- /** @inheritDoc */
16
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
17
- /** @inheritDoc */
18
- reset(): boolean;
19
- /** @inheritDoc */
20
- update(): boolean;
21
- /** @inheritDoc */
22
- choose(): number | undefined;
23
- /** @inheritDoc */
24
- remove(): boolean;
25
- private leastEluNextWorkerNodeKey;
26
- }
@@ -1,24 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the least used worker.
7
- *
8
- * @typeParam Worker - Type of worker which manages the strategy.
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- */
12
- export declare class LeastUsedWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
13
- /** @inheritDoc */
14
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
15
- /** @inheritDoc */
16
- reset(): boolean;
17
- /** @inheritDoc */
18
- update(): boolean;
19
- /** @inheritDoc */
20
- choose(): number | undefined;
21
- /** @inheritDoc */
22
- remove(): boolean;
23
- private leastUsedNextWorkerNodeKey;
24
- }
@@ -1,24 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the next worker in a round robin fashion.
7
- *
8
- * @typeParam Worker - Type of worker which manages the strategy.
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- */
12
- export declare class RoundRobinWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
13
- /** @inheritDoc */
14
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
15
- /** @inheritDoc */
16
- reset(): boolean;
17
- /** @inheritDoc */
18
- update(): boolean;
19
- /** @inheritDoc */
20
- choose(): number | undefined;
21
- /** @inheritDoc */
22
- remove(workerNodeKey: number): boolean;
23
- private roundRobinNextWorkerNodeKey;
24
- }
@@ -1,200 +0,0 @@
1
- /**
2
- * Enumeration of worker choice strategies.
3
- */
4
- export declare const WorkerChoiceStrategies: Readonly<{
5
- /**
6
- * Round robin worker selection strategy.
7
- */
8
- readonly ROUND_ROBIN: "ROUND_ROBIN";
9
- /**
10
- * Least used worker selection strategy.
11
- */
12
- readonly LEAST_USED: "LEAST_USED";
13
- /**
14
- * Least busy worker selection strategy.
15
- */
16
- readonly LEAST_BUSY: "LEAST_BUSY";
17
- /**
18
- * Least ELU worker selection strategy.
19
- */
20
- readonly LEAST_ELU: "LEAST_ELU";
21
- /**
22
- * Fair share worker selection strategy.
23
- */
24
- readonly FAIR_SHARE: "FAIR_SHARE";
25
- /**
26
- * Weighted round robin worker selection strategy.
27
- */
28
- readonly WEIGHTED_ROUND_ROBIN: "WEIGHTED_ROUND_ROBIN";
29
- /**
30
- * Interleaved weighted round robin worker selection strategy.
31
- *
32
- * @experimental
33
- */
34
- readonly INTERLEAVED_WEIGHTED_ROUND_ROBIN: "INTERLEAVED_WEIGHTED_ROUND_ROBIN";
35
- }>;
36
- /**
37
- * Worker choice strategy.
38
- */
39
- export type WorkerChoiceStrategy = keyof typeof WorkerChoiceStrategies;
40
- /**
41
- * Enumeration of measurements.
42
- */
43
- export declare const Measurements: Readonly<{
44
- readonly runTime: "runTime";
45
- readonly waitTime: "waitTime";
46
- readonly elu: "elu";
47
- }>;
48
- /**
49
- * Measurement.
50
- */
51
- export type Measurement = keyof typeof Measurements;
52
- /**
53
- * Measurement options.
54
- */
55
- export interface MeasurementOptions {
56
- /**
57
- * Set measurement median.
58
- */
59
- readonly median: boolean;
60
- }
61
- /**
62
- * Worker choice strategy options.
63
- */
64
- export interface WorkerChoiceStrategyOptions {
65
- /**
66
- * Number of worker choice retries to perform if no worker is eligible.
67
- *
68
- * @defaultValue 6
69
- */
70
- readonly retries?: number;
71
- /**
72
- * Measurement to use in worker choice strategy supporting it.
73
- */
74
- readonly measurement?: Measurement;
75
- /**
76
- * Runtime options.
77
- *
78
- * @defaultValue \{ median: false \}
79
- */
80
- readonly runTime?: MeasurementOptions;
81
- /**
82
- * Wait time options.
83
- *
84
- * @defaultValue \{ median: false \}
85
- */
86
- readonly waitTime?: MeasurementOptions;
87
- /**
88
- * Event loop utilization options.
89
- *
90
- * @defaultValue \{ median: false \}
91
- */
92
- readonly elu?: MeasurementOptions;
93
- /**
94
- * Worker weights to use for weighted round robin worker selection strategies.
95
- * A weight is tasks maximum execution time in milliseconds for a worker node.
96
- *
97
- * @defaultValue Weights computed automatically given the CPU performance.
98
- */
99
- readonly weights?: Record<number, number>;
100
- }
101
- /**
102
- * Measurement statistics requirements.
103
- *
104
- * @internal
105
- */
106
- export interface MeasurementStatisticsRequirements {
107
- /**
108
- * Requires measurement aggregate.
109
- */
110
- aggregate: boolean;
111
- /**
112
- * Requires measurement average.
113
- */
114
- average: boolean;
115
- /**
116
- * Requires measurement median.
117
- */
118
- median: boolean;
119
- }
120
- /**
121
- * Pool worker node worker usage statistics requirements.
122
- *
123
- * @internal
124
- */
125
- export interface TaskStatisticsRequirements {
126
- /**
127
- * Tasks runtime requirements.
128
- */
129
- readonly runTime: MeasurementStatisticsRequirements;
130
- /**
131
- * Tasks wait time requirements.
132
- */
133
- readonly waitTime: MeasurementStatisticsRequirements;
134
- /**
135
- * Tasks event loop utilization requirements.
136
- */
137
- readonly elu: MeasurementStatisticsRequirements;
138
- }
139
- /**
140
- * Strategy policy.
141
- *
142
- * @internal
143
- */
144
- export interface StrategyPolicy {
145
- /**
146
- * Expects tasks execution on the newly created dynamic worker.
147
- */
148
- readonly dynamicWorkerUsage: boolean;
149
- /**
150
- * Expects the newly created dynamic worker to be flagged as ready.
151
- */
152
- readonly dynamicWorkerReady: boolean;
153
- }
154
- /**
155
- * Worker choice strategy interface.
156
- *
157
- * @internal
158
- */
159
- export interface IWorkerChoiceStrategy {
160
- /**
161
- * Strategy policy.
162
- */
163
- readonly strategyPolicy: StrategyPolicy;
164
- /**
165
- * Tasks statistics requirements.
166
- */
167
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
168
- /**
169
- * Resets strategy internals.
170
- *
171
- * @returns `true` if the reset is successful, `false` otherwise.
172
- */
173
- readonly reset: () => boolean;
174
- /**
175
- * Updates the worker node key strategy internals.
176
- *
177
- * @returns `true` if the update is successful, `false` otherwise.
178
- */
179
- readonly update: (workerNodeKey: number) => boolean;
180
- /**
181
- * Chooses a worker node in the pool and returns its key.
182
- * If the worker node is not eligible, `undefined` is returned.
183
- *
184
- * @returns The worker node key or `undefined`.
185
- */
186
- readonly choose: () => number | undefined;
187
- /**
188
- * Removes the worker node key from strategy internals.
189
- *
190
- * @param workerNodeKey - The worker node key.
191
- * @returns `true` if the worker node key is removed, `false` otherwise.
192
- */
193
- readonly remove: (workerNodeKey: number) => boolean;
194
- /**
195
- * Sets the worker choice strategy options.
196
- *
197
- * @param opts - The worker choice strategy options.
198
- */
199
- readonly setOptions: (opts: WorkerChoiceStrategyOptions) => void;
200
- }
@@ -1,35 +0,0 @@
1
- import type { IWorker } from '../worker';
2
- import type { IPool } from '../pool';
3
- import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy';
4
- import type { IWorkerChoiceStrategy, TaskStatisticsRequirements, WorkerChoiceStrategyOptions } from './selection-strategies-types';
5
- /**
6
- * Selects the next worker with a weighted round robin scheduling algorithm.
7
- * Loosely modeled after the weighted round robin queueing algorithm: https://en.wikipedia.org/wiki/Weighted_round_robin.
8
- *
9
- * @typeParam Worker - Type of worker which manages the strategy.
10
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
11
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
12
- */
13
- export declare class WeightedRoundRobinWorkerChoiceStrategy<Worker extends IWorker, Data = unknown, Response = unknown> extends AbstractWorkerChoiceStrategy<Worker, Data, Response> implements IWorkerChoiceStrategy {
14
- /** @inheritDoc */
15
- readonly taskStatisticsRequirements: TaskStatisticsRequirements;
16
- /**
17
- * Default worker weight.
18
- */
19
- private readonly defaultWorkerWeight;
20
- /**
21
- * Worker virtual task runtime.
22
- */
23
- private workerVirtualTaskRunTime;
24
- /** @inheritDoc */
25
- constructor(pool: IPool<Worker, Data, Response>, opts?: WorkerChoiceStrategyOptions);
26
- /** @inheritDoc */
27
- reset(): boolean;
28
- /** @inheritDoc */
29
- update(): boolean;
30
- /** @inheritDoc */
31
- choose(): number | undefined;
32
- /** @inheritDoc */
33
- remove(workerNodeKey: number): boolean;
34
- private weightedRoundRobinNextWorkerNodeKey;
35
- }
@@ -1,71 +0,0 @@
1
- import type { IPool } from '../pool';
2
- import type { IWorker } from '../worker';
3
- import type { StrategyPolicy, TaskStatisticsRequirements, WorkerChoiceStrategy, WorkerChoiceStrategyOptions } from './selection-strategies-types';
4
- /**
5
- * The worker choice strategy context.
6
- *
7
- * @typeParam Worker - Type of worker.
8
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
9
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
10
- */
11
- export declare class WorkerChoiceStrategyContext<Worker extends IWorker, Data = unknown, Response = unknown> {
12
- private workerChoiceStrategy;
13
- private opts;
14
- private readonly workerChoiceStrategies;
15
- /**
16
- * The number of times the worker choice strategy in the context has been retried.
17
- */
18
- private retriesCount;
19
- /**
20
- * Worker choice strategy context constructor.
21
- *
22
- * @param pool - The pool instance.
23
- * @param workerChoiceStrategy - The worker choice strategy.
24
- * @param opts - The worker choice strategy options.
25
- */
26
- constructor(pool: IPool<Worker, Data, Response>, workerChoiceStrategy?: WorkerChoiceStrategy, opts?: WorkerChoiceStrategyOptions);
27
- /**
28
- * Gets the strategy policy in the context.
29
- *
30
- * @returns The strategy policy.
31
- */
32
- getStrategyPolicy(): StrategyPolicy;
33
- /**
34
- * Gets the worker choice strategy in the context task statistics requirements.
35
- *
36
- * @returns The task statistics requirements.
37
- */
38
- getTaskStatisticsRequirements(): TaskStatisticsRequirements;
39
- /**
40
- * Sets the worker choice strategy to use in the context.
41
- *
42
- * @param workerChoiceStrategy - The worker choice strategy to set.
43
- */
44
- setWorkerChoiceStrategy(workerChoiceStrategy: WorkerChoiceStrategy): void;
45
- /**
46
- * Updates the worker node key in the worker choice strategy in the context internals.
47
- *
48
- * @returns `true` if the update is successful, `false` otherwise.
49
- */
50
- update(workerNodeKey: number): boolean;
51
- /**
52
- * Executes the worker choice strategy in the context algorithm.
53
- *
54
- * @returns The key of the worker node.
55
- * @throws {@link https://nodejs.org/api/errors.html#class-error} If after configured retries the worker node key is null or undefined .
56
- */
57
- execute(): number;
58
- /**
59
- * Removes the worker node key from the worker choice strategy in the context.
60
- *
61
- * @param workerNodeKey - The worker node key.
62
- * @returns `true` if the removal is successful, `false` otherwise.
63
- */
64
- remove(workerNodeKey: number): boolean;
65
- /**
66
- * Sets the worker choice strategies in the context options.
67
- *
68
- * @param opts - The worker choice strategy options.
69
- */
70
- setOptions(opts: WorkerChoiceStrategyOptions): void;
71
- }
@@ -1,29 +0,0 @@
1
- import { type PoolType } from '../pool';
2
- import { FixedThreadPool, type ThreadPoolOptions } from './fixed';
3
- /**
4
- * A thread pool with a dynamic number of threads, but a guaranteed minimum number of threads.
5
- *
6
- * This thread pool creates new threads when the others are busy, up to the maximum number of threads.
7
- * When the maximum number of threads is reached and workers are busy, an event is emitted. If you want to listen to this event, use the pool's `emitter`.
8
- *
9
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
10
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
11
- * @author [Alessandro Pio Ardizio](https://github.com/pioardi)
12
- * @since 0.0.1
13
- */
14
- export declare class DynamicThreadPool<Data = unknown, Response = unknown> extends FixedThreadPool<Data, Response> {
15
- protected readonly max: number;
16
- /**
17
- * Constructs a new poolifier dynamic thread pool.
18
- *
19
- * @param min - Minimum number of threads which are always active.
20
- * @param max - Maximum number of threads that can be created by this pool.
21
- * @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
22
- * @param opts - Options for this dynamic thread pool.
23
- */
24
- constructor(min: number, max: number, filePath: string, opts?: ThreadPoolOptions);
25
- /** @inheritDoc */
26
- protected get type(): PoolType;
27
- /** @inheritDoc */
28
- protected get busy(): boolean;
29
- }
@@ -1,54 +0,0 @@
1
- /// <reference types="node" />
2
- import { type TransferListItem, Worker, type WorkerOptions } from 'node:worker_threads';
3
- import type { MessageValue } from '../../utility-types';
4
- import { AbstractPool } from '../abstract-pool';
5
- import { type PoolOptions, type PoolType } from '../pool';
6
- import { type WorkerType } from '../worker';
7
- /**
8
- * Options for a poolifier thread pool.
9
- */
10
- export interface ThreadPoolOptions extends PoolOptions<Worker> {
11
- /**
12
- * Worker options.
13
- *
14
- * @see https://nodejs.org/api/worker_threads.html#new-workerfilename-options
15
- */
16
- workerOptions?: WorkerOptions;
17
- }
18
- /**
19
- * A thread pool with a fixed number of threads.
20
- *
21
- * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
22
- * @typeParam Response - Type of execution response. This can only be structured-cloneable data.
23
- * @author [Alessandro Pio Ardizio](https://github.com/pioardi)
24
- * @since 0.0.1
25
- */
26
- export declare class FixedThreadPool<Data = unknown, Response = unknown> extends AbstractPool<Worker, Data, Response> {
27
- protected readonly opts: ThreadPoolOptions;
28
- /**
29
- * Constructs a new poolifier fixed thread pool.
30
- *
31
- * @param numberOfThreads - Number of threads for this pool.
32
- * @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
33
- * @param opts - Options for this fixed thread pool.
34
- */
35
- constructor(numberOfThreads: number, filePath: string, opts?: ThreadPoolOptions);
36
- /** @inheritDoc */
37
- protected isMain(): boolean;
38
- /** @inheritDoc */
39
- protected destroyWorkerNode(workerNodeKey: number): Promise<void>;
40
- /** @inheritDoc */
41
- protected sendToWorker(workerNodeKey: number, message: MessageValue<Data>, transferList?: TransferListItem[]): void;
42
- /** @inheritDoc */
43
- protected sendStartupMessageToWorker(workerNodeKey: number): void;
44
- /** @inheritDoc */
45
- protected registerWorkerMessageListener<Message extends Data | Response>(workerNodeKey: number, listener: (message: MessageValue<Message>) => void): void;
46
- /** @inheritDoc */
47
- protected createWorker(): Worker;
48
- /** @inheritDoc */
49
- protected get type(): PoolType;
50
- /** @inheritDoc */
51
- protected get worker(): WorkerType;
52
- /** @inheritDoc */
53
- protected get busy(): boolean;
54
- }