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