3 All notable changes to this project will be documented in this file.
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).
12 - Add source maps to npm package to ease debugging.
16 - Continuous benchmarking versus other worker pools: [https://poolifier.github.io/benchmark](https://poolifier.github.io/benchmark).
18 ## [2.7.1] - 2023-09-20
22 - Ensure worker message listener used one time are removed after usage.
24 ## [2.7.0] - 2023-09-19
28 - Fix task stealing related tasks queue options handling at runtime.
32 - Rename `listTaskFunctions()` to `listTaskFunctionNames()` in pool and worker API.
36 - Add `hasTaskFunction()`, `addTaskFunction()`, `removeTaskFunction()`, `setDefaultTaskFunction()` methods to pool API: [PR #1148](https://github.com/poolifier/poolifier/pull/1148).
37 - Stricter worker constructor arguments validation.
39 ## [2.6.45] - 2023-09-17
43 - Disable publication on GitHub packages registry on release until authentication issue is fixed.
47 - Add `startWorkers` to pool options to whether start the minimum number of workers at pool creation or not.
48 - Add `start()` method to pool API to start the minimum number of workers.
49 - Add `taskStealing` and `tasksStealingOnPressure` to tasks queue options to whether enable task stealing or not and whether enable tasks stealing on back pressure or not.
50 - Continuous internal benchmarking: [https://poolifier.github.io/benchmark-results/dev/bench](https://poolifier.github.io/benchmark-results/dev/bench).
52 ## [2.6.44] - 2023-09-08
56 - Use a dedicated PAT to publish on GitHub packages registry.
60 - Publish on GitHub packages registry on release.
64 - Switch from rome to biome: [PR #1128](https://github.com/poolifier/poolifier/pull/1128).
66 ## [2.6.43] - 2023-09-08
70 - Publish on GitHub packages registry on release.
74 - Switch from rome to biome: [PR #1128](https://github.com/poolifier/poolifier/pull/1128).
76 ## [2.6.42] - 2023-09-06
80 - Optimize hot code paths implementation: avoid unnecessary branching, add and use optimized helpers (min, max), use reduce() array helper, ...
82 ## [2.6.41] - 2023-09-03
86 - Optimize worker choice strategies implementation.
88 ## [2.6.40] - 2023-09-01
92 - Do not pre-choose in WRR worker choice strategy to avoid bias.
93 - Avoid array out of bound in worker choice strategies after worker node removal.
95 ## [2.6.39] - 2023-08-30
99 - Fix race condition in worker choice strategies at worker node info querying while not yet initialized.
101 ## [2.6.38] - 2023-08-30
105 - Bundle typescript types declaration into one file.
109 - Improve interleaved weighted round robin worker choice strategy implementation.
111 ## [2.6.37] - 2023-08-28
115 - Ensure unused worker usage statistics are deleted at runtime.
119 - Rename worker choice strategy options `choiceRetries` to `retries`.
120 - Avoid unnecessary branching in worker choice strategies.
122 ## [2.6.36] - 2023-08-27
126 - Fix pool `execute()` arguments check.
130 - Make continuous tasks stealing algorithm less aggressive.
131 - Fine tune tasks stealing algorithm under back pressure.
133 ## [2.6.35] - 2023-08-25
137 - Don't account worker usage statistics for tasks that have failed.
138 - Fix pool information runtime and wait time median computation.
142 - Update simple moving average implementation to use a circular buffer.
143 - Update simple moving median implementation to use a circular buffer.
144 - Account for stolen tasks in worker usage statistics and pool information.
148 - Continuous tasks stealing algorithm.
150 ## [2.6.34] - 2023-08-24
154 - Avoid cascading tasks stealing under back pressure.
158 - Add fastpath to queued tasks rescheduling.
160 ## [2.6.33] - 2023-08-24
164 - Fix queued tasks rescheduling.
168 - Rename tasks queue options `queueMaxSize` to `size`.
172 - Task stealing scheduling algorithm if tasks queueing is enabled.
174 ## [2.6.32] - 2023-08-23
178 - Ensure no task can be executed when the pool is destroyed.
182 - Add `queueMaxSize` option to tasks queue options.
183 - Add O(1) deque implementation implemented with doubly linked list and use it for tasks queueing.
184 - Add tasks stealing algorithm when a worker node queue is back pressured if tasks queueing is enabled.
186 ## [2.6.31] - 2023-08-20
190 - Fix worker choice strategy retries mechanism in some edge cases.
194 - Make orthogonal worker choice strategies tasks distribution and created dynamic worker usage.
195 - Remove the experimental status of the `LEAST_ELU` worker choice strategy.
197 ## [2.6.30] - 2023-08-19
201 - Ensure pool event `backPressure` is emitted.
202 - Ensure pool event `full` is emitted only once.
203 - Ensure worker node cannot be instantiated without proper arguments.
205 ## [2.6.29] - 2023-08-18
209 - Fix race condition between ready and task functions worker message handling at startup.
210 - Fix duplicate task function worker usage statistics computation per task function.
211 - Update task function worker usage statistics if and only if there's at least two different task functions.
212 - Fix race condition at task function worker usage executing task computation leading to negative value.
216 - 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).
217 - Use back pressure detection in worker choice strategies.
218 - Add worker choice strategies retries mechanism if no worker is eligible.
220 ## [2.6.28] - 2023-08-16
224 - Ensure pool workers are properly initialized.
228 - HTTP server pool examples: express-cluster, express-hybrid.
232 - Remove now useless branching in worker hot code path.
234 ## [2.6.27] - 2023-08-15
238 - Add `KillHandler` type definition to exported types.
242 - Add `destroy` event to pool API.
244 ## [2.6.26] - 2023-08-15
248 - Add kill handler to worker options allowing to execute custom code when worker is killed.
249 - Add `listTaskFunctions()` method to pool API.
250 - SMTP client pool example: nodemailer.
252 ## [2.6.25] - 2023-08-13
256 - HTTP server pool examples: fastify-cluster, fastify-hybrid.
257 - WebSocket server pool examples: ws-cluster, ws-hybrid.
259 ## [2.6.24] - 2023-08-12
263 - Add array of transferable objects to the `execute()` method arguments.
264 - WebSocket server pool examples: ws-worker_threads.
266 ## [2.6.23] - 2023-08-11
270 - 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.
274 - HTTP client pool examples: fetch, node-fetch and axios with multiple task functions.
275 - HTTP server pool examples: express-worker_threads, fastify-worker_threads.
277 ## [2.6.22] - 2023-08-10
281 - Add missing `types` field to package.json `exports`.
285 - Structure markdown documentation (PR #811).
287 ## [2.6.21] - 2023-08-03
291 - Improve code documentation.
292 - Code refactoring and cleanup for better maintainability and readability.
294 ## [2.6.20] - 2023-07-21
298 - Fix queued tasks redistribution on error task execution starvation.
299 - Ensure tasks queueing per worker condition is untangled from the pool busyness semantic.
303 - Drastically reduce lookups by worker in the worker nodes.
305 ## [2.6.19] - 2023-07-20
309 - Dedicated internal communication channel for worker_threads pools.
311 ## [2.6.18] - 2023-07-19
315 - Code refactoring and cleanup for better maintainability and readability. Bundle size is a bit smaller.
317 ## [2.6.17] - 2023-07-16
321 - Add `listTaskFunctions()` method to worker API.
323 ## [2.6.16] - 2023-07-12
327 - Fix pool startup detection.
328 - Fix worker task functions handling.
330 ## [2.6.15] - 2023-07-11
334 - Take into account worker node readiness in worker choice strategies.
336 ## [2.6.14] - 2023-07-10
340 - Fix task function statistics tracking.
342 ## [2.6.13] - 2023-07-10
346 - Add per task function statistics tracking.
347 - Add public methods to manipulate the worker task functions at runtime.
349 ## [2.6.12] - 2023-07-09
353 - Workaround import issue with `node:os` module in node 16.x.x.
355 ## [2.6.11] - 2023-07-09
359 - Fix pool readiness semantic.
361 ## [2.6.10] - 2023-07-08
365 - Ensure workers are not recreated on error at pool startup.
369 - Add `ready` and `strategy` fields to pool information.
370 - Add pool event `ready` to notify when the number of workers created in the pool has reached the maximum size expected and are ready.
371 - Add dynamic pool sizing checks.
373 ## [2.6.9] - 2023-07-07
377 - Recreate the right worker type on uncaught exception.
381 - Add minimum and maximum to internal measurement statistics.
382 - Add `runTime` and `waitTime` to pool information.
383 - Check worker inactive time only on dynamic worker.
385 ## [2.6.8] - 2023-07-03
389 - Brown paper bag release to fix version handling in pool information.
391 ## [2.6.7] - 2023-07-03
395 - Ensure worker queued tasks at error are reassigned to other pool workers.
399 - Add pool `utilization` ratio to pool information.
400 - Add `version` to pool information.
401 - Add worker information to worker nodes.
403 ## [2.6.6] - 2023-07-01
407 - Add safe helper `availableParallelism()` to help sizing the pool.
411 - Ensure message handler is only registered in worker.
413 ## [2.6.5] - 2023-06-27
417 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
421 - Artificial version bump to 2.6.5 to workaround publication issue.
422 - Ensure cluster pool `destroy()` gracefully shutdowns worker's server.
423 - Ensure pool event is emitted before task error promise rejection.
424 - Fix queued tasks count computation.
428 - Remove unneeded worker_threads worker `MessageChannel` internal usage for IPC.
430 ## [2.6.4] - 2023-06-27
434 - Cluster pools tasks execution are not working by using ESM files extension: https://github.com/poolifier/poolifier/issues/782
438 - Ensure cluster pool `destroy()` gracefully shutdowns worker's server.
439 - Ensure pool event is emitted before task error promise rejection.
440 - Fix queued tasks count computation.
444 - Remove unneeded worker_threads worker `MessageChannel` internal usage for IPC.
446 ## [2.6.3] - 2023-06-19
450 - Ensure no tasks are queued when trying to soft kill a dynamic worker.
451 - Update strategies internals after statistics computation.
455 - Optimize O(1) queue implementation.
457 ## [2.6.2] - 2023-06-12
461 - Fix new worker use after creation in dynamic pool given the current worker choice strategy.
463 ## [2.6.1] - 2023-06-10
467 - Add worker choice strategy documentation: [README.md](./docs/worker-choice-strategies.md).
471 - Fix average statistics computation: ensure failed tasks are not accounted.
473 ## [2.6.0] - 2023-06-09
477 - Add `LEAST_ELU` worker choice strategy (experimental).
478 - Add tasks ELU instead of runtime support to `FAIR_SHARE` worker choice strategy.
482 - Refactor pool worker node usage internals.
483 - Breaking change: refactor worker choice strategy statistics requirements: the syntax of the worker choice strategy options has changed.
484 - Breaking change: pool information `info` property object fields have been renamed.
488 - Fix wait time accounting.
489 - Ensure worker choice strategy `LEAST_BUSY` accounts also tasks wait time.
490 - Ensure worker choice strategy `LEAST_USED` accounts also queued tasks.
492 ## [2.5.4] - 2023-06-07
496 - Add Event Loop Utilization (ELU) statistics to worker tasks usage.
500 - Compute statistics at the worker level only if needed.
501 - Add `worker_threads` options to thread pool options.
505 - Make the `LEAST_BUSY` strategy only relies on task runtime.
507 ## [2.5.3] - 2023-06-04
511 - Refine pool information content.
512 - Limit pool internals public exposure.
514 ## [2.5.2] - 2023-06-02
518 - Add `taskError` pool event for task execution error.
519 - Add pool information `info` property to pool.
520 - Emit pool information on `busy` and `full` pool events.
522 ## [2.5.1] - 2023-06-01
526 - Add pool option `restartWorkerOnError` to restart worker on uncaught error. Default to `true`.
527 - Add `error` pool event for uncaught worker error.
529 ## [2.5.0] - 2023-05-31
533 - Switch pool event emitter to `EventEmitterAsyncResource`.
534 - Add tasks wait time accounting in per worker tasks usage.
535 - Add interleaved weighted round robin `INTERLEAVED_WEIGHTED_ROUND_ROBIN` worker choice strategy (experimental).
539 - Renamed worker choice strategy `LESS_BUSY` to `LEAST_BUSY` and `LESS_USED` to `LEAST_USED`.
541 ## [2.4.14] - 2023-05-09
545 - Ensure no undefined task runtime can land in the tasks history.
546 - Fix median computation implementation once again.
550 - Unit tests for median and queue implementations.
552 ## [2.4.13] - 2023-05-08
556 - Fix worker choice strategy options validation.
557 - Fix fair share worker choice strategy internals update: ensure virtual task end timestamp is computed at task submission.
559 ## [2.4.12] - 2023-05-06
563 - Support multiple task functions per worker.
564 - Add custom worker weights support to worker choice strategies options.
568 - Use O(1) queue implementation for tasks queueing.
572 - Fix median computation implementation.
573 - Fix fair share worker choice strategy internals update.
575 ## [2.4.11] - 2023-04-23
579 - Optimize free worker finding in worker choice strategies.
581 ## [2.4.10] - 2023-04-15
585 - Fix typescript type definition for task function: ensure the input data is optional.
586 - Fix typescript type definition for pool execute(): ensure the input data is optional.
588 ## [2.4.9] - 2023-04-15
592 - Add tasks queue enablement runtime setter to pool.
593 - Add tasks queue options runtime setter to pool.
594 - Add worker choice strategy options runtime setter to pool.
598 - Remove the tasks queuing experimental status.
602 - Fix task function type definition and validation.
603 - Fix worker choice strategy options handling.
605 ## [2.4.8] - 2023-04-12
609 - Fix message between main worker and worker type definition for tasks.
610 - Fix code documentation.
612 ## [2.4.7] - 2023-04-11
616 - Add worker tasks queue options to pool options.
620 - Fix missing documentation.
622 ## [2.4.6] - 2023-04-10
626 - Ensure one task at a time is executed per worker with tasks queueing enabled.
627 - Properly count worker executing tasks with tasks queueing enabled.
629 ## [2.4.5] - 2023-04-09
633 - Use monotonic high resolution timer for worker tasks runtime.
634 - Add worker tasks median runtime to statistics.
635 - Add worker tasks queue (experimental).
637 ## [2.4.4] - 2023-04-07
641 - Add `PoolEvents` enumeration and `PoolEvent` type.
645 - Destroy worker only on alive check.
647 ## [2.4.3] - 2023-04-07
651 - Fix typedoc generation with inheritance.
653 ## [2.4.2] - 2023-04-06
657 - Add `full` event to dynamic pool.
658 - Keep worker choice strategy in memory for conditional reuse.
662 - Fix possible negative worker key at worker removal in worker choice strategies.
664 ## [2.4.1] - 2023-04-05
668 - Optimize worker choice strategy for dynamic pool.
672 - Ensure dynamic pool does not alter worker choice strategy expected behavior.
674 ## [2.4.0] - 2023-04-04
678 - Add `LESS_BUSY` worker choice strategy.
682 - Optimize worker storage in pool.
683 - Optimize worker alive status check.
684 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
685 - Optimize `LESS_USED` worker choice strategy.
686 - Update benchmark versus external threads pools.
687 - Optimize tasks usage statistics requirements for worker choice strategy.
691 - Ensure trimmable characters are checked at pool initialization.
692 - Fix message id integer overflow.
693 - Fix pool worker removal in worker choice strategy internals.
694 - Fix package publication with pnpm.
696 ## [2.4.0-3] - 2023-04-04
700 - Add `LESS_BUSY` worker choice strategy.
704 - Optimize worker storage in pool.
705 - Optimize worker alive status check.
706 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
707 - Optimize `LESS_USED` worker choice strategy.
708 - Update benchmark versus external threads pools.
712 - Ensure trimmable characters are checked at pool initialization.
713 - Fix message id integer overflow.
714 - Fix pool worker removal in worker choice strategy internals.
715 - Fix package publication with pnpm.
717 ## [2.4.0-2] - 2023-04-03
721 - Add `LESS_BUSY` worker choice strategy.
725 - Optimize worker storage in pool.
726 - Optimize worker alive status check.
727 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
728 - Optimize `LESS_USED` worker choice strategy.
732 - Ensure trimmable characters are checked at pool initialization.
733 - Fix message id integer overflow.
734 - Fix pool worker removal in worker choice strategy internals.
735 - Fix package publication with pnpm.
737 ## [2.4.0-1] - 2023-04-03
741 - Add `LESS_BUSY` worker choice strategy.
745 - Optimize worker storage in pool.
746 - Optimize worker alive status check.
747 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
748 - Optimize `LESS_USED` worker choice strategy.
752 - Ensure trimmable characters are checked at pool initialization.
753 - Fix message id integer overflow.
754 - Fix pool worker removal in worker choice strategy internals.
756 ## [2.4.0-0] - 2023-04-03
760 - Add `LESS_BUSY` worker choice strategy.
764 - Optimize worker storage in pool.
765 - Optimize worker alive status check.
766 - BREAKING CHANGE: Rename worker choice strategy `LESS_RECENTLY_USED` to `LESS_USED`.
767 - Optimize `LESS_USED` worker choice strategy.
771 - Ensure trimmable characters are checked at pool initialization.
772 - Fix message id integer overflow.
773 - Fix pool worker removal in worker choice strategy internals.
775 ## [2.3.10] - 2023-03-18
779 - Fix package.json `exports` syntax for ESM and CommonJS.
783 - Permit SemVer pre-release publication.
785 ## [2.3.10-2] - 2023-03-18
789 - Fix package.json `exports` syntax for ESM and CommonJS.
791 ## [2.3.10-1] - 2023-03-18
795 - Permit SemVer pre-release publication.
797 ## [2.3.10-0] - 2023-03-18
801 - Fix package.json `exports` syntax for ESM and CommonJS.
803 ## [2.3.9] - 2023-03-18
807 - Introduce ESM module support along with CommonJS one.
811 - Fix brown paper bag bug referencing the same object literal.
813 ## [2.3.8] - 2023-03-18
817 - Switch internal benchmarking code to benny.
818 - Switch to TypeScript 5.x.x.
819 - Switch rollup bundler plugins to core ones.
820 - Switch to TSDoc syntax.
821 - Enforce conventional commits.
825 - Fix random integer generator.
826 - Fix worker choice strategy pool type identification at initialization.
828 ## [2.3.7] - 2022-10-23
832 - Switch to open collective FOSS project funding platform.
833 - Switch to ts-standard linter configuration on TypeScript code.
837 - Fixed missing async on pool execute method.
838 - Fixed typing in TypeScript example.
839 - Fixed types in unit tests.
841 ## [2.3.6] - 2022-10-22
845 - Cleanup pool attributes and methods.
846 - Refine error types thrown.
850 - Fix continuous integration build on windows.
851 - Fix code coverage reporting by using c8 instead of nyc.
853 ## [2.3.5] - 2022-10-21
857 - Improve benchmarks: add IO intensive task workload, add task size option, integrate code into linter.
858 - Optimize tasks usage lookup implementation.
862 - Fix missed pool event emitter type export.
863 - Fix typedoc documentation generation.
865 ## [2.3.4] - 2022-10-17
869 - Fully automate release process with release-it.
873 - Optimize fair share task scheduling algorithm implementation.
874 - Update benchmark versus external pools results with latest version.
876 ## [2.3.3] - 2022-10-15
880 - Add support for [cluster settings](https://nodejs.org/api/cluster.html#cluster_cluster_settings) in cluster pool options.
882 ## [2.3.2] - 2022-10-14
886 - Optimize fair share worker selection strategy implementation.
890 - Fix WRR worker selection strategy: ensure the condition triggering the round robin can be fulfilled.
892 ## [2.3.1] - 2022-10-13
896 - Pool worker choice strategies:
897 - `WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN` strategy based on weighted round robin scheduling algorithm using tasks execution time for now.
898 - `WorkerChoiceStrategies.FAIR_SHARE` strategy based on fair share scheduling algorithm using tasks execution time for now.
900 ## [2.2.2] - 2022-10-09
904 - Fixed `README.md` file.
906 ## [2.2.1] - 2022-10-08
910 - Dynamic worker choice strategy change at runtime.
912 ## [2.2.0] - 2022-01-05
916 - Support only Node.js version 16.x.x for cluster pool: upstream cluster API have changed on that version.
918 ## [2.1.0] - 2021-08-29
922 - Add an optional pool option `messageHandler` to `PoolOptions<Worker>` for registering a message handler callback on each worker.
926 - `AbstractWorker` class `maxInactiveTime`, `killBehavior` and `async` attributes have been removed in favour of the same ones in the worker options `opts` public attribute.
927 - `AbstractWorker` class `lastTask` attribute have been renamed to `lastTaskTimestamp`.
928 - `AbstractWorker` class `interval` attribute have been renamed to `aliveInterval`.
929 - `AbstractWorker` class cannot be instantiated without specifying the `mainWorker` argument referencing the main worker.
931 ## [2.0.2] - 2021-05-12
935 - Fix `busy` event emission on fixed pool type
937 ## [2.0.1] - 2021-03-16
941 - Check if pool options are properly set.
942 - `busy` event is emitted on all pool types.
944 ## [2.0.0] - 2021-03-01
948 - Now a thread/process by default is not deleted when the task submitted take more time than maxInactiveTime configured (issue #70).
952 - `FullPool` event is now renamed to `busy`.
953 - `maxInactiveTime` on `ThreadWorker` default behavior is now changed, if you want to keep the old behavior set `killBehavior` to `KillBehaviors.HARD`.
954 _Find more details on our JSDoc._
956 - `maxTasks` option on `FixedThreadPool` and `DynamicThreadPool` is now removed since is no more needed.
958 - We changed some internal structures, but you shouldn't be too affected by them as these are internal changes.
960 ### Pool options types declaration merge
962 `FixedThreadPoolOptions` and `DynamicThreadPoolOptions` type declarations have been merged to `PoolOptions<Worker>`.
964 #### New `export` strategy
968 const DynamicThreadPool = require('poolifier/lib/dynamic')
970 const { DynamicThreadPool } = require('poolifier/lib/dynamic')
973 But you should always prefer just using
976 const { DynamicThreadPool } = require('poolifier')
979 #### New type definitions for input data and response
981 For cluster worker and worker-thread pools, you can now only send and receive structured-cloneable data.
982 _This is not a limitation by poolifier but Node.js._
984 #### Public property replacements
986 `numWorkers` property is now `numberOfWorkers`
988 #### Internal (protected) properties and methods renaming
990 These properties are not intended for end users
992 - `id` => `nextMessageId`
994 These methods are not intended for end users
996 - `_chooseWorker` => `chooseWorker`
997 - `_newWorker` => `createWorker`
998 - `_execute` => `internalExecute`
999 - `_chooseWorker` => `chooseWorker`
1000 - `_checkAlive` => `checkAlive`
1002 - `_runAsync` => `runAsync`
1004 ## [1.1.0] - 2020-05-21
1008 - ThreadWorker support async functions as option
1009 - Various external library patches
1011 ## [1.0.0] - 2020-01-24
1015 - FixedThreadPool implementation
1016 - DynamicThreadPool implementation
1017 - WorkerThread implementation to improve developer experience