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