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