docs: add scope on pool public API
[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 ### Fixed
11
12 - Fix race condition between ready and task functions worker message handling at startup.
13 - Fix duplicate task usage statistics computation per task function.
14
15 ## [2.6.28] - 2023-08-16
16
17 ### Fixed
18
19 - Ensure pool workers are properly initialized.
20
21 ### Added
22
23 - HTTP server pool examples: express-cluster, express-hybrid.
24
25 ### Changed
26
27 - Remove now useless branching in worker hot code path.
28
29 ## [2.6.27] - 2023-08-15
30
31 ### Fixed
32
33 - Add `KillHandler` type definition to exported types.
34
35 ### Added
36
37 - Add `destroy` event to pool API.
38
39 ## [2.6.26] - 2023-08-15
40
41 ### Added
42
43 - Add kill handler to worker options allowing to execute custom code when worker is killed.
44 - Add `listTaskFunctions()` method to pool API.
45 - SMTP server pool example: nodemailer.
46
47 ## [2.6.25] - 2023-08-13
48
49 ### Added
50
51 - HTTP server pool examples: fastify-cluster, fastify-hybrid.
52 - WebSocket server pool examples: ws-cluster, ws-hybrid.
53
54 ## [2.6.24] - 2023-08-12
55
56 ### Added
57
58 - Add array of transferable objects to the `execute()` method arguments.
59 - WebSocket server pool examples: ws-worker_threads.
60
61 ## [2.6.23] - 2023-08-11
62
63 ### Fixed
64
65 - Fix pool busyness semantic when tasks queueing is enabled: the pool is busy when the number of executing tasks on each worker has reached the maximum tasks concurrency per worker.
66
67 ### Added
68
69 - HTTP client pool examples: fetch, node-fetch and axios with multiple task functions.
70 - HTTP server pool examples: express-worker_threads, fastify-worker_threads.
71
72 ## [2.6.22] - 2023-08-10
73
74 ### Fixed
75
76 - Add missing `types` field to package.json `exports`.
77
78 ### Changed
79
80 - Structure markdown documentation (PR #811).
81
82 ## [2.6.21] - 2023-08-03
83
84 ### Changed
85
86 - Improve code documentation.
87 - Code refactoring and cleanup for better maintainability and readability.
88
89 ## [2.6.20] - 2023-07-21
90
91 ### Fixed
92
93 - Fix queued tasks redistribution on error task execution starvation.
94 - Ensure task queueing per worker condition is untangled from the pool busyness semantic.
95
96 ### Changed
97
98 - Drastically reduce lookups by worker in the worker nodes.
99
100 ## [2.6.19] - 2023-07-20
101
102 ### Added
103
104 - Dedicated internal communication channel for worker_threads pools.
105
106 ## [2.6.18] - 2023-07-19
107
108 ### Changed
109
110 - Code refactoring and cleanup for better maintainability and readability. Bundle size is a bit smaller.
111
112 ## [2.6.17] - 2023-07-16
113
114 ### Added
115
116 - Add `listTaskFunctions()` method to worker API.
117
118 ## [2.6.16] - 2023-07-12
119
120 ### Fixed
121
122 - Fix pool startup detection.
123 - Fix worker task functions handling.
124
125 ## [2.6.15] - 2023-07-11
126
127 ### Added
128
129 - Take into account worker node readiness in worker choice strategies.
130
131 ## [2.6.14] - 2023-07-10
132
133 ### Fixed
134
135 - Fix task function statistics tracking.
136
137 ## [2.6.13] - 2023-07-10
138
139 ### Added
140
141 - Add per task function statistics tracking.
142 - Add public methods to manipulate the worker task functions at runtime.
143
144 ## [2.6.12] - 2023-07-09
145
146 ### Fixed
147
148 - Workaround import issue with `node:os` module in node 16.x.x.
149
150 ## [2.6.11] - 2023-07-09
151
152 ### Fixed
153
154 - Fix pool readiness semantic.
155
156 ## [2.6.10] - 2023-07-08
157
158 ### Fixed
159
160 - Ensure workers are not recreated on error at pool startup.
161
162 ### Added
163
164 - Add `ready` and `strategy` fields to pool information.
165 - Add pool event `ready` to notify when the number of workers created in the pool has reached the maximum size expected and are ready.
166 - Add dynamic pool sizing checks.
167
168 ## [2.6.9] - 2023-07-07
169
170 ### Fixed
171
172 - Recreate the right worker type on uncaught exception.
173
174 ### Added
175
176 - Add minimum and maximum to internal measurement statistics.
177 - Add `runTime` and `waitTime` to pool information.
178 - Check worker inactive time only on dynamic worker.
179
180 ## [2.6.8] - 2023-07-03
181
182 ### Fixed
183
184 - Brown paper bag release to fix version handling in pool information.
185
186 ## [2.6.7] - 2023-07-03
187
188 ### Fixed
189
190 - Ensure worker queued tasks at error are reassigned to other pool workers.
191
192 ### Added
193
194 - Add pool `utilization` ratio to pool information.
195 - Add `version` to pool information.
196 - Add worker information to worker nodes.
197
198 ## [2.6.6] - 2023-07-01
199
200 ### Added
201
202 - Add safe helper `availableParallelism` to help sizing the pool.
203
204 ### Fixed
205
206 - Ensure message handler is only registered in worker.
207
208 ## [2.6.5] - 2023-06-27
209
210 ### Known issues
211
212 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
213
214 ### Fixed
215
216 - Artificial version bump to 2.6.5 to workaround publication issue.
217 - Ensure cluster pool destroy() gracefully shutdowns worker's server.
218 - Ensure pool event is emitted before task error promise rejection.
219 - Fix queued tasks count computation.
220
221 ### Removed
222
223 - Remove unneeded worker_threads worker `MessageChannel` internal usage for IPC.
224
225 ## [2.6.4] - 2023-06-27
226
227 ### Known issues
228
229 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
230
231 ### Fixed
232
233 - Ensure cluster pool destroy() gracefully shutdowns worker's server.
234 - Ensure pool event is emitted before task error promise rejection.
235 - Fix queued tasks count computation.
236
237 ### Removed
238
239 - Remove unneeded worker_threads worker `MessageChannel` internal usage for IPC.
240
241 ## [2.6.3] - 2023-06-19
242
243 ### Fixed
244
245 - Ensure no tasks are queued when trying to soft kill a dynamic worker.
246 - Update strategies internals after statistics computation.
247
248 ### Changed
249
250 - Optimize O(1) queue implementation.
251
252 ## [2.6.2] - 2023-06-12
253
254 ### Fixed
255
256 - Fix new worker use after creation in dynamic pool given the current worker choice strategy.
257
258 ## [2.6.1] - 2023-06-10
259
260 ### Added
261
262 - Add worker choice strategy documentation: [README.md](./docs/worker-choice-strategies.md).
263
264 ### Fixed
265
266 - Fix average statistics computation: ensure failed tasks are not accounted.
267
268 ## [2.6.0] - 2023-06-09
269
270 ### Added
271
272 - Add `LEAST_ELU` worker choice strategy (experimental).
273 - Add tasks ELU instead of runtime support to `FAIR_SHARE` worker choice strategy.
274
275 ### Changed
276
277 - Refactor pool worker node usage internals.
278 - Breaking change: refactor worker choice strategy statistics requirements: the syntax of the worker choice strategy options has changed.
279 - Breaking change: pool information `info` property object fields have been renamed.
280
281 ### Fixed
282
283 - Fix wait time accounting.
284 - Ensure worker choice strategy `LEAST_BUSY` accounts also tasks wait time.
285 - Ensure worker choice strategy `LEAST_USED` accounts also queued tasks.
286
287 ## [2.5.4] - 2023-06-07
288
289 ### Added
290
291 - Add Event Loop Utilization (ELU) statistics to worker tasks usage.
292
293 ### Changed
294
295 - Compute statistics at the worker level only if needed.
296 - Add `worker_threads` options to thread pool options.
297
298 ### Fixed
299
300 - Make the `LEAST_BUSY` strategy only relies on task runtime.
301
302 ## [2.5.3] - 2023-06-04
303
304 ### Changed
305
306 - Refine pool information content.
307 - Limit pool internals public exposure.
308
309 ## [2.5.2] - 2023-06-02
310
311 ### Added
312
313 - Add `taskError` pool event for task execution error.
314 - Add pool information `info` property to pool.
315 - Emit pool information on `busy` and `full` pool events.
316
317 ## [2.5.1] - 2023-06-01
318
319 ### Added
320
321 - Add pool option `restartWorkerOnError` to restart worker on uncaught error. Default to `true`.
322 - Add `error` pool event for uncaught worker error.
323
324 ## [2.5.0] - 2023-05-31
325
326 ### Added
327
328 - Switch pool event emitter to `EventEmitterAsyncResource`.
329 - Add tasks wait time accounting in per worker tasks usage.
330 - Add interleaved weighted round robin `INTERLEAVED_WEIGHTED_ROUND_ROBIN` worker choice strategy (experimental).
331
332 ### Changed
333
334 - Renamed worker choice strategy `LESS_BUSY` to `LEAST_BUSY` and `LESS_USED` to `LEAST_USED`.
335
336 ## [2.4.14] - 2023-05-09
337
338 ### Fixed
339
340 - Ensure no undefined task runtime can land in the tasks history.
341 - Fix median computation implementation once again.
342
343 ### Added
344
345 - Unit tests for median and queue implementations.
346
347 ## [2.4.13] - 2023-05-08
348
349 ### Fixed
350
351 - Fix worker choice strategy options validation.
352 - Fix fair share worker choice strategy internals update: ensure virtual task end timestamp is computed at task submission.
353
354 ## [2.4.12] - 2023-05-06
355
356 ### Added
357
358 - Support multiple task functions per worker.
359 - Add custom worker weights support to worker choice strategies options.
360
361 ### Changed
362
363 - Use O(1) queue implementation for tasks queueing.
364
365 ### Fixed
366
367 - Fix median computation implementation.
368 - Fix fair share worker choice strategy internals update.
369
370 ## [2.4.11] - 2023-04-23
371
372 ### Changed
373
374 - Optimize free worker finding in worker choice strategies.
375
376 ## [2.4.10] - 2023-04-15
377
378 ### Fixed
379
380 - Fix typescript type definition for task function: ensure the input data is optional.
381 - Fix typescript type definition for pool execute(): ensure the input data is optional.
382
383 ## [2.4.9] - 2023-04-15
384
385 ### Added
386
387 - Add tasks queue enablement runtime setter to pool.
388 - Add tasks queue options runtime setter to pool.
389 - Add worker choice strategy options runtime setter to pool.
390
391 ### Changed
392
393 - Remove the tasks queuing experimental status.
394
395 ### Fixed
396
397 - Fix task function type definition and validation.
398 - Fix worker choice strategy options handling.
399
400 ## [2.4.8] - 2023-04-12
401
402 ### Fixed
403
404 - Fix message between main worker and worker type definition for tasks.
405 - Fix code documentation.
406
407 ## [2.4.7] - 2023-04-11
408
409 ### Added
410
411 - Add worker tasks queue options to pool options.
412
413 ### Fixed
414
415 - Fix missing documentation.
416
417 ## [2.4.6] - 2023-04-10
418
419 ### Fixed
420
421 - Ensure one task at a time is executed per worker with tasks queueing enabled.
422 - Properly count worker executing tasks with tasks queueing enabled.
423
424 ## [2.4.5] - 2023-04-09
425
426 ### Added
427
428 - Use monotonic high resolution timer for worker tasks runtime.
429 - Add worker tasks median runtime to statistics.
430 - Add worker tasks queue (experimental).
431
432 ## [2.4.4] - 2023-04-07
433
434 ### Added
435
436 - Add `PoolEvents` enumeration and `PoolEvent` type.
437
438 ### Fixed
439
440 - Destroy worker only on alive check.
441
442 ## [2.4.3] - 2023-04-07
443
444 ### Fixed
445
446 - Fix typedoc generation with inheritance.
447
448 ## [2.4.2] - 2023-04-06
449
450 ### Added
451
452 - Add `full` event to dynamic pool.
453 - Keep worker choice strategy in memory for conditional reuse.
454
455 ### Fixed
456
457 - Fix possible negative worker key at worker removal in worker choice strategies.
458
459 ## [2.4.1] - 2023-04-05
460
461 ### Changed
462
463 - Optimize worker choice strategy for dynamic pool.
464
465 ### Fixed
466
467 - Ensure dynamic pool does not alter worker choice strategy expected behavior.
468
469 ## [2.4.0] - 2023-04-04
470
471 ### Added
472
473 - Add `LESS_BUSY` worker choice strategy.
474
475 ### Changed
476
477 - Optimize worker storage in pool.
478 - Optimize worker alive status check.
479 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
480 - Optimize `LESS_USED` worker choice strategy.
481 - Update benchmarks versus external threads pools.
482 - Optimize tasks usage statistics requirements for worker choice strategy.
483
484 ### Fixed
485
486 - Ensure trimmable characters are checked at pool initialization.
487 - Fix message id integer overflow.
488 - Fix pool worker removal in worker choice strategy internals.
489 - Fix package publication with pnpm.
490
491 ## [2.4.0-3] - 2023-04-04
492
493 ### Added
494
495 - Add `LESS_BUSY` worker choice strategy.
496
497 ### Changed
498
499 - Optimize worker storage in pool.
500 - Optimize worker alive status check.
501 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
502 - Optimize `LESS_USED` worker choice strategy.
503 - Update benchmarks versus external threads pools.
504
505 ### Fixed
506
507 - Ensure trimmable characters are checked at pool initialization.
508 - Fix message id integer overflow.
509 - Fix pool worker removal in worker choice strategy internals.
510 - Fix package publication with pnpm.
511
512 ## [2.4.0-2] - 2023-04-03
513
514 ### Added
515
516 - Add `LESS_BUSY` worker choice strategy.
517
518 ### Changed
519
520 - Optimize worker storage in pool.
521 - Optimize worker alive status check.
522 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
523 - Optimize `LESS_USED` worker choice strategy.
524
525 ### Fixed
526
527 - Ensure trimmable characters are checked at pool initialization.
528 - Fix message id integer overflow.
529 - Fix pool worker removal in worker choice strategy internals.
530 - Fix package publication with pnpm.
531
532 ## [2.4.0-1] - 2023-04-03
533
534 ### Added
535
536 - Add `LESS_BUSY` worker choice strategy.
537
538 ### Changed
539
540 - Optimize worker storage in pool.
541 - Optimize worker alive status check.
542 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
543 - Optimize `LESS_USED` worker choice strategy.
544
545 ### Fixed
546
547 - Ensure trimmable characters are checked at pool initialization.
548 - Fix message id integer overflow.
549 - Fix pool worker removal in worker choice strategy internals.
550
551 ## [2.4.0-0] - 2023-04-03
552
553 ### Added
554
555 - Add `LESS_BUSY` worker choice strategy.
556
557 ### Changed
558
559 - Optimize worker storage in pool.
560 - Optimize worker alive status check.
561 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
562 - Optimize `LESS_USED` worker choice strategy.
563
564 ### Fixed
565
566 - Ensure trimmable characters are checked at pool initialization.
567 - Fix message id integer overflow.
568 - Fix pool worker removal in worker choice strategy internals.
569
570 ## [2.3.10] - 2023-03-18
571
572 ### Fixed
573
574 - Fix package.json `exports` syntax for ESM and CommonJS.
575
576 ### Changed
577
578 - Permit SemVer pre-release publication.
579
580 ## [2.3.10-2] - 2023-03-18
581
582 ### Fixed
583
584 - Fix package.json `exports` syntax for ESM and CommonJS.
585
586 ## [2.3.10-1] - 2023-03-18
587
588 ### Changed
589
590 - Permit SemVer pre-release publication.
591
592 ## [2.3.10-0] - 2023-03-18
593
594 ### Fixed
595
596 - Fix package.json `exports` syntax for ESM and CommonJS.
597
598 ## [2.3.9] - 2023-03-18
599
600 ### Changed
601
602 - Introduce ESM module support along with CommonJS one.
603
604 ### Fixed
605
606 - Fix brown paper bag bug referencing the same object literal.
607
608 ## [2.3.8] - 2023-03-18
609
610 ### Changed
611
612 - Switch internal benchmarking code to benny.
613 - Switch to TypeScript 5.x.x.
614 - Switch rollup bundler plugins to core ones.
615 - Switch to TSDoc syntax.
616 - Enforce conventional commits.
617
618 ### Fixed
619
620 - Fix random integer generator.
621 - Fix worker choice strategy pool type identification at initialization.
622
623 ## [2.3.7] - 2022-10-23
624
625 ### Changed
626
627 - Switch to open collective FOSS project funding platform.
628 - Switch to ts-standard linter configuration on TypeScript code.
629
630 ### Fixed
631
632 - Fixed missing async on pool execute method.
633 - Fixed typing in TypeScript example.
634 - Fixed types in unit tests.
635
636 ## [2.3.6] - 2022-10-22
637
638 ### Changed
639
640 - Cleanup pool attributes and methods.
641 - Refine error types thrown.
642
643 ### Fixed
644
645 - Fix continuous integration build on windows.
646 - Fix code coverage reporting by using c8 instead of nyc.
647
648 ## [2.3.5] - 2022-10-21
649
650 ### Changed
651
652 - Improve benchmarks: add IO intensive task workload, add task size option, integrate code into linter.
653 - Optimize tasks usage lookup implementation.
654
655 ### Fixed
656
657 - Fix missed pool event emitter type export.
658 - Fix typedoc documentation generation.
659
660 ## [2.3.4] - 2022-10-17
661
662 ### Added
663
664 - Fully automate release process with release-it.
665
666 ### Changed
667
668 - Optimize fair share task scheduling algorithm implementation.
669 - Update benchmarks versus external pools results with latest version.
670
671 ## [2.3.3] - 2022-10-15
672
673 ### Added
674
675 - Add support for [cluster settings](https://nodejs.org/api/cluster.html#cluster_cluster_settings) in cluster pool options.
676
677 ## [2.3.2] - 2022-10-14
678
679 ### Changed
680
681 - Optimize fair share worker selection strategy implementation.
682
683 ### Fixed
684
685 - Fix WRR worker selection strategy: ensure the condition triggering the round robin can be fulfilled.
686
687 ## [2.3.1] - 2022-10-13
688
689 ### Added
690
691 - Pool worker choice strategies:
692 - `WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN` strategy based on weighted round robin scheduling algorithm using tasks execution time for now.
693 - `WorkerChoiceStrategies.FAIR_SHARE` strategy based on fair share scheduling algorithm using tasks execution time for now.
694
695 ## [2.2.2] - 2022-10-09
696
697 ### Fixed
698
699 - Fixed `README.md` file.
700
701 ## [2.2.1] - 2022-10-08
702
703 ### Added
704
705 - Dynamic worker choice strategy change at runtime.
706
707 ## [2.2.0] - 2022-01-05
708
709 ### Breaking Changes
710
711 - Support only Node.js version 16.x.x for cluster pool: upstream cluster API have changed on that version.
712
713 ## [2.1.0] - 2021-08-29
714
715 ### Added
716
717 - Add an optional pool option `messageHandler` to `PoolOptions<Worker>` for registering a message handler callback on each worker.
718
719 ### Breaking Changes
720
721 - `AbstractWorker` class `maxInactiveTime`, `killBehavior` and `async` attributes have been removed in favour of the same ones in the worker options `opts` public attribute.
722 - `AbstractWorker` class `lastTask` attribute have been renamed to `lastTaskTimestamp`.
723 - `AbstractWorker` class `interval` attribute have been renamed to `aliveInterval`.
724 - `AbstractWorker` class cannot be instantiated without specifying the `mainWorker` argument referencing the main worker.
725
726 ## [2.0.2] - 2021-05-12
727
728 ### Bug fixes
729
730 - Fix `busy` event emission on fixed pool type
731
732 ## [2.0.1] - 2021-03-16
733
734 ### Bug fixes
735
736 - Check if pool options are properly set.
737 - `busy` event is emitted on all pool types.
738
739 ## [2.0.0] - 2021-03-01
740
741 ### Bug fixes
742
743 - Now a thread/process by default is not deleted when the task submitted take more time than maxInactiveTime configured (issue #70).
744
745 ### Breaking Changes
746
747 - `FullPool` event is now renamed to `busy`.
748 - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`.
749 _Find more details on our JSDoc._
750
751 - `maxTasks` option on `FixedThreadPool` and `DynamicThreadPool` is now removed since is no more needed.
752
753 - We changed some internal structures, but you shouldn't be too affected by them as these are internal changes.
754
755 ### Pool options types declaration merge
756
757 `FixedThreadPoolOptions` and `DynamicThreadPoolOptions` type declarations have been merged to `PoolOptions<Worker>`.
758
759 #### New `export` strategy
760
761 ```js
762 // Before
763 const DynamicThreadPool = require('poolifier/lib/dynamic')
764 // After
765 const { DynamicThreadPool } = require('poolifier/lib/dynamic')
766 ```
767
768 But you should always prefer just using
769
770 ```js
771 const { DynamicThreadPool } = require('poolifier')
772 ```
773
774 #### New type definitions for input data and response
775
776 For cluster worker and worker-thread pools, you can now only send and receive structured-cloneable data.
777 _This is not a limitation by poolifier but Node.js._
778
779 #### Public property replacements
780
781 `numWorkers` property is now `numberOfWorkers`
782
783 #### Internal (protected) properties and methods renaming
784
785 These properties are not intended for end users
786
787 - `id` => `nextMessageId`
788
789 These methods are not intended for end users
790
791 - `_chooseWorker` => `chooseWorker`
792 - `_newWorker` => `createWorker`
793 - `_execute` => `internalExecute`
794 - `_chooseWorker` => `chooseWorker`
795 - `_checkAlive` => `checkAlive`
796 - `_run` => `run`
797 - `_runAsync` => `runAsync`
798
799 ## [1.1.0] - 2020-05-21
800
801 ### Added
802
803 - ThreadWorker support async functions as option
804 - Various external library patches
805
806 ## [1.0.0] - 2020-01-24
807
808 ### Added
809
810 - FixedThreadPool implementation
811 - DynamicThreadPool implementation
812 - WorkerThread implementation to improve developer experience