docs: document availableParallelism() usage
[poolifier.git] / CHANGELOG.md
1 # Changelog
2
3 All notable changes to this project will be documented in this file.
4
5 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
8 ## [Unreleased]
9
10 ### Added
11
12 - Add safe helper `availableParallelism` to help sizing the pool.
13
14 ### Fixed
15
16 - Ensure message handler is only registered in worker.
17
18 ## [2.6.5] - 2023-06-27
19
20 ### Known issues
21
22 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
23
24 ### Fixed
25
26 - Artificial version bump to 2.6.5 to workaround publication issue.
27 - Ensure cluster pool destroy() gracefully shutdowns worker's server.
28 - Ensure pool event is emitted before task error promise rejection.
29 - Fix queued tasks count computation.
30
31 ### Removed
32
33 - Remove unneeded worker-threads worker `MessageChannel` internal usage for IPC.
34
35 ## [2.6.4] - 2023-06-27
36
37 ### Known issues
38
39 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
40
41 ### Fixed
42
43 - Ensure cluster pool destroy() gracefully shutdowns worker's server.
44 - Ensure pool event is emitted before task error promise rejection.
45 - Fix queued tasks count computation.
46
47 ### Removed
48
49 - Remove unneeded worker-threads worker `MessageChannel` internal usage for IPC.
50
51 ## [2.6.3] - 2023-06-19
52
53 ### Fixed
54
55 - Ensure no tasks are queued when trying to soft kill a dynamic worker.
56 - Update strategies internals after statistics computation.
57
58 ### Changed
59
60 - Optimize O(1) queue implementation.
61
62 ## [2.6.2] - 2023-06-12
63
64 ### Fixed
65
66 - Fix new worker use after creation in dynamic pool given the current worker choice strategy.
67
68 ## [2.6.1] - 2023-06-10
69
70 ### Added
71
72 - Add worker choice strategy documentation: [README.md](./src/pools/selection-strategies/README.md).
73
74 ### Fixed
75
76 - Fix average statistics computation: ensure failed tasks are not accounted.
77
78 ## [2.6.0] - 2023-06-09
79
80 ### Added
81
82 - Add `LEAST_ELU` worker choice strategy (experimental).
83 - Add tasks ELU instead of runtime support to `FAIR_SHARE` worker choice strategy.
84
85 ### Changed
86
87 - Refactor pool worker node usage internals.
88 - Breaking change: refactor worker choice strategy statistics requirements: the syntax of the worker choice strategy options has changed.
89 - Breaking change: pool information `info` property object fields have been renamed.
90
91 ### Fixed
92
93 - Fix wait time accounting.
94 - Ensure worker choice strategy `LEAST_BUSY` accounts also tasks wait time.
95 - Ensure worker choice strategy `LEAST_USED` accounts also queued tasks.
96
97 ## [2.5.4] - 2023-06-07
98
99 ### Added
100
101 - Add Event Loop Utilization (ELU) statistics to worker tasks usage.
102
103 ### Changed
104
105 - Compute statistics at the worker level only if needed.
106 - Add `worker-threads` options to thread pool options.
107
108 ### Fixed
109
110 - Make the `LEAST_BUSY` strategy only relies on task runtime.
111
112 ## [2.5.3] - 2023-06-04
113
114 ### Changed
115
116 - Refine pool information content.
117 - Limit pool internals public exposure.
118
119 ## [2.5.2] - 2023-06-02
120
121 ### Added
122
123 - Add `taskError` pool event for task execution error.
124 - Add pool information `info` property to pool.
125 - Emit pool information on `busy` and `full` pool events.
126
127 ## [2.5.1] - 2023-06-01
128
129 ### Added
130
131 - Add pool option `restartWorkerOnError` to restart worker on uncaught error. Default to `true`.
132 - Add `error` pool event for uncaught worker error.
133
134 ## [2.5.0] - 2023-05-31
135
136 ### Added
137
138 - Switch pool event emitter to `EventEmitterAsyncResource`.
139 - Add tasks wait time accounting in per worker tasks usage.
140 - Add interleaved weighted round robin `INTERLEAVED_WEIGHTED_ROUND_ROBIN` worker choice strategy (experimental).
141
142 ### Changed
143
144 - Renamed worker choice strategy `LESS_BUSY` to `LEAST_BUSY` and `LESS_USED` to `LEAST_USED`.
145
146 ## [2.4.14] - 2023-05-09
147
148 ### Fixed
149
150 - Ensure no undefined task runtime can land in the tasks history.
151 - Fix median computation implementation once again.
152
153 ### Added
154
155 - Unit tests for median and queue implementations.
156
157 ## [2.4.13] - 2023-05-08
158
159 ### Fixed
160
161 - Fix worker choice strategy options validation.
162 - Fix fair share worker choice strategy internals update: ensure virtual task end timestamp is computed at task submission.
163
164 ## [2.4.12] - 2023-05-06
165
166 ### Added
167
168 - Support multiple task functions per worker.
169 - Add custom worker weights support to worker choice strategies options.
170
171 ### Changed
172
173 - Use O(1) queue implementation for tasks queueing.
174
175 ### Fixed
176
177 - Fix median computation implementation.
178 - Fix fair share worker choice strategy internals update.
179
180 ## [2.4.11] - 2023-04-23
181
182 ### Changed
183
184 - Optimize free worker finding in worker choice strategies.
185
186 ## [2.4.10] - 2023-04-15
187
188 ### Fixed
189
190 - Fix typescript type definition for worker function: ensure the input data is optional.
191 - Fix typescript type definition for pool execute(): ensure the input data is optional.
192
193 ## [2.4.9] - 2023-04-15
194
195 ### Added
196
197 - Add tasks queue enablement runtime setter to pool.
198 - Add tasks queue options runtime setter to pool.
199 - Add worker choice strategy options runtime setter to pool.
200
201 ### Changed
202
203 - Remove the tasks queuing experimental status.
204
205 ### Fixed
206
207 - Fix worker function type definition and validation.
208 - Fix worker choice strategy options handling.
209
210 ## [2.4.8] - 2023-04-12
211
212 ### Fixed
213
214 - Fix message between main worker and worker type definition for tasks.
215 - Fix code documentation.
216
217 ## [2.4.7] - 2023-04-11
218
219 ### Added
220
221 - Add worker tasks queue options to pool options.
222
223 ### Fixed
224
225 - Fix missing documentation.
226
227 ## [2.4.6] - 2023-04-10
228
229 ### Fixed
230
231 - Ensure one task at a time is executed per worker with tasks queueing enabled.
232 - Properly count worker executing tasks with tasks queueing enabled.
233
234 ## [2.4.5] - 2023-04-09
235
236 ### Added
237
238 - Use monotonic high resolution timer for worker tasks runtime.
239 - Add worker tasks median runtime to statistics.
240 - Add worker tasks queue (experimental).
241
242 ## [2.4.4] - 2023-04-07
243
244 ### Added
245
246 - Add `PoolEvents` enumeration and `PoolEvent` type.
247
248 ### Fixed
249
250 - Destroy worker only on alive check.
251
252 ## [2.4.3] - 2023-04-07
253
254 ### Fixed
255
256 - Fix typedoc generation with inheritance.
257
258 ## [2.4.2] - 2023-04-06
259
260 ### Added
261
262 - Add `full` event to dynamic pool.
263 - Keep worker choice strategy in memory for conditional reuse.
264
265 ### Fixed
266
267 - Fix possible negative worker key at worker removal in worker choice strategies.
268
269 ## [2.4.1] - 2023-04-05
270
271 ### Changed
272
273 - Optimize worker choice strategy for dynamic pool.
274
275 ### Fixed
276
277 - Ensure dynamic pool does not alter worker choice strategy expected behavior.
278
279 ## [2.4.0] - 2023-04-04
280
281 ### Added
282
283 - Add `LESS_BUSY` worker choice strategy.
284
285 ### Changed
286
287 - Optimize worker storage in pool.
288 - Optimize worker alive status check.
289 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
290 - Optimize `LESS_USED` worker choice strategy.
291 - Update benchmarks versus external threads pools.
292 - Optimize tasks usage statistics requirements for worker choice strategy.
293
294 ### Fixed
295
296 - Ensure trimmable characters are checked at pool initialization.
297 - Fix message id integer overflow.
298 - Fix pool worker removal in worker choice strategy internals.
299 - Fix package publication with pnpm.
300
301 ## [2.4.0-3] - 2023-04-04
302
303 ### Added
304
305 - Add `LESS_BUSY` worker choice strategy.
306
307 ### Changed
308
309 - Optimize worker storage in pool.
310 - Optimize worker alive status check.
311 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
312 - Optimize `LESS_USED` worker choice strategy.
313 - Update benchmarks versus external threads pools.
314
315 ### Fixed
316
317 - Ensure trimmable characters are checked at pool initialization.
318 - Fix message id integer overflow.
319 - Fix pool worker removal in worker choice strategy internals.
320 - Fix package publication with pnpm.
321
322 ## [2.4.0-2] - 2023-04-03
323
324 ### Added
325
326 - Add `LESS_BUSY` worker choice strategy.
327
328 ### Changed
329
330 - Optimize worker storage in pool.
331 - Optimize worker alive status check.
332 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
333 - Optimize `LESS_USED` worker choice strategy.
334
335 ### Fixed
336
337 - Ensure trimmable characters are checked at pool initialization.
338 - Fix message id integer overflow.
339 - Fix pool worker removal in worker choice strategy internals.
340 - Fix package publication with pnpm.
341
342 ## [2.4.0-1] - 2023-04-03
343
344 ### Added
345
346 - Add `LESS_BUSY` worker choice strategy.
347
348 ### Changed
349
350 - Optimize worker storage in pool.
351 - Optimize worker alive status check.
352 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
353 - Optimize `LESS_USED` worker choice strategy.
354
355 ### Fixed
356
357 - Ensure trimmable characters are checked at pool initialization.
358 - Fix message id integer overflow.
359 - Fix pool worker removal in worker choice strategy internals.
360
361 ## [2.4.0-0] - 2023-04-03
362
363 ### Added
364
365 - Add `LESS_BUSY` worker choice strategy.
366
367 ### Changed
368
369 - Optimize worker storage in pool.
370 - Optimize worker alive status check.
371 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
372 - Optimize `LESS_USED` worker choice strategy.
373
374 ### Fixed
375
376 - Ensure trimmable characters are checked at pool initialization.
377 - Fix message id integer overflow.
378 - Fix pool worker removal in worker choice strategy internals.
379
380 ## [2.3.10] - 2023-03-18
381
382 ### Fixed
383
384 - Fix `exports` syntax for ESM and CommonJS.
385
386 ### Changed
387
388 - Permit SemVer pre-release publication.
389
390 ## [2.3.10-2] - 2023-03-18
391
392 ### Fixed
393
394 - Fix `exports` syntax for ESM and CommonJS.
395
396 ## [2.3.10-1] - 2023-03-18
397
398 ### Changed
399
400 - Permit SemVer pre-release publication.
401
402 ## [2.3.10-0] - 2023-03-18
403
404 ### Fixed
405
406 - Fix `exports` syntax for ESM and CommonJS.
407
408 ## [2.3.9] - 2023-03-18
409
410 ### Changed
411
412 - Introduce ESM module support along with CommonJS one.
413
414 ### Fixed
415
416 - Fix brown paper bag bug referencing the same object literal.
417
418 ## [2.3.8] - 2023-03-18
419
420 ### Changed
421
422 - Switch internal benchmarking code to benny.
423 - Switch to TypeScript 5.x.x.
424 - Switch rollup bundler plugins to core ones.
425 - Switch to TSDoc syntax.
426 - Enforce conventional commits.
427
428 ### Fixed
429
430 - Fix random integer generator.
431 - Fix worker choice strategy pool type identification at initialization.
432
433 ## [2.3.7] - 2022-10-23
434
435 ### Changed
436
437 - Switch to open collective FOSS project funding platform.
438 - Switch to ts-standard linter configuration on TypeScript code.
439
440 ### Fixed
441
442 - Fixed missing async on pool execute method.
443 - Fixed typing in TypeScript example.
444 - Fixed types in unit tests.
445
446 ## [2.3.6] - 2022-10-22
447
448 ### Changed
449
450 - Cleanup pool attributes and methods.
451 - Refine error types thrown.
452
453 ### Fixed
454
455 - Fix continuous integration build on windows.
456 - Fix code coverage reporting by using c8 instead of nyc.
457
458 ## [2.3.5] - 2022-10-21
459
460 ### Changed
461
462 - Improve benchmarks: add IO intensive task workload, add task size option, integrate code into linter.
463 - Optimize tasks usage lookup implementation.
464
465 ### Fixed
466
467 - Fix missed pool event emitter type export.
468 - Fix typedoc documentation generation.
469
470 ## [2.3.4] - 2022-10-17
471
472 ### Added
473
474 - Fully automate release process with release-it.
475
476 ### Changed
477
478 - Optimize fair share task scheduling algorithm implementation.
479 - Update benchmarks versus external pools results with latest version.
480
481 ## [2.3.3] - 2022-10-15
482
483 ### Added
484
485 - Add support for [cluster settings](https://nodejs.org/api/cluster.html#cluster_cluster_settings) in cluster pool options.
486
487 ## [2.3.2] - 2022-10-14
488
489 ### Changed
490
491 - Optimize fair share worker selection strategy implementation.
492
493 ### Fixed
494
495 - Fix WRR worker selection strategy: ensure the condition triggering the round robin can be fulfilled.
496
497 ## [2.3.1] - 2022-10-13
498
499 ### Added
500
501 - Pool worker choice strategies:
502 - `WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN` strategy based on weighted round robin scheduling algorithm using tasks execution time for now.
503 - `WorkerChoiceStrategies.FAIR_SHARE` strategy based on fair share scheduling algorithm using tasks execution time for now.
504
505 ## [2.2.2] - 2022-10-09
506
507 ### Fixed
508
509 - Fixed `README.md` file.
510
511 ## [2.2.1] - 2022-10-08
512
513 ### Added
514
515 - Dynamic worker choice strategy change at runtime.
516
517 ## [2.2.0] - 2022-01-05
518
519 ### Breaking Changes
520
521 - Support only NodeJS version 16.x.x for cluster pool: upstream cluster API have changed on that version.
522
523 ## [2.1.0] - 2021-08-29
524
525 ### Added
526
527 - Add an optional pool option `messageHandler` to `PoolOptions<Worker>` for registering a message handler callback on each worker.
528
529 ### Breaking Changes
530
531 - `AbstractWorker` class `maxInactiveTime`, `killBehavior` and `async` attributes have been removed in favour of the same ones in the worker options `opts` public attribute.
532 - `AbstractWorker` class `lastTask` attribute have been renamed to `lastTaskTimestamp`.
533 - `AbstractWorker` class `interval` attribute have been renamed to `aliveInterval`.
534 - `AbstractWorker` class cannot be instantiated without specifying the `mainWorker` argument referencing the main worker.
535
536 ## [2.0.2] - 2021-05-12
537
538 ### Bug fixes
539
540 - Fix `busy` event emission on fixed pool type
541
542 ## [2.0.1] - 2021-03-16
543
544 ### Bug fixes
545
546 - Check if pool options are properly set.
547 - `busy` event is emitted on all pool types.
548
549 ## [2.0.0] - 2021-03-01
550
551 ### Bug fixes
552
553 - Now a thread/process by default is not deleted when the task submitted take more time than maxInactiveTime configured (issue #70).
554
555 ### Breaking Changes
556
557 - `FullPool` event is now renamed to `busy`.
558 - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`.
559 _Find more details on our JSDoc._
560
561 - `maxTasks` option on `FixedThreadPool` and `DynamicThreadPool` is now removed since is no more needed.
562
563 - We changed some internal structures, but you shouldn't be too affected by them as these are internal changes.
564
565 ### Pool options types declaration merge
566
567 `FixedThreadPoolOptions` and `DynamicThreadPoolOptions` type declarations have been merged to `PoolOptions<Worker>`.
568
569 #### New `export` strategy
570
571 ```js
572 // Before
573 const DynamicThreadPool = require('poolifier/lib/dynamic')
574 // After
575 const { DynamicThreadPool } = require('poolifier/lib/dynamic')
576 ```
577
578 But you should always prefer just using
579
580 ```js
581 const { DynamicThreadPool } = require('poolifier')
582 ```
583
584 #### New type definitions for input data and response
585
586 For cluster worker and worker-thread pools, you can now only send and receive structured-cloneable data.
587 _This is not a limitation by poolifier but NodeJS._
588
589 #### Public property replacements
590
591 `numWorkers` property is now `numberOfWorkers`
592
593 #### Internal (protected) properties and methods renaming
594
595 These properties are not intended for end users
596
597 - `id` => `nextMessageId`
598
599 These methods are not intended for end users
600
601 - `_chooseWorker` => `chooseWorker`
602 - `_newWorker` => `createWorker`
603 - `_execute` => `internalExecute`
604 - `_chooseWorker` => `chooseWorker`
605 - `_checkAlive` => `checkAlive`
606 - `_run` => `run`
607 - `_runAsync` => `runAsync`
608
609 ## [1.1.0] - 2020-05-21
610
611 ### Added
612
613 - ThreadWorker support async functions as option
614 - Various external library patches
615
616 ## [1.0.0] - 2020-01-24
617
618 ### Added
619
620 - FixedThreadPool implementation
621 - DynamicThreadPool implementation
622 - WorkerThread implementation to improve developer experience