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