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