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