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