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