From 3e3e2e5d21de35aa2dec6125168f8a416da3503e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 30 Apr 2024 19:01:00 +0200 Subject: [PATCH] docs: document added fine grained priority and scheduling features MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 9 ++++++++- README.md | 2 +- docs/api.md | 6 +++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb7ce9f0..fad95b95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,11 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Support per task function(s) priority and worker choice strategy definition via a task function object: `{ taskFunction: (data?: Data) => Response | Promise, priority?: number, strategy?: WorkerChoiceStrategy }`. +- Add priority queue based tasks queueing. One priority queue is divided into prioritized buckets to avoid queued tasks starvation under load. - BREAKING CHANGE: `listTaskFunctionNames()` to `listTaskFunctionsProperties()` in pool and worker API returning registered task functions properties. +- BREAKING CHANGE: `strategy` field in pool information renamed to `defaultStrategy`. + +### Fixed + +- Ensure worker choice strategy options changes at runtime are propagated to poolifier workers. ## [3.1.30] - 2024-04-22 -### Fixed: +### Fixed - Fix `transferList` argument type definition. diff --git a/README.md b/README.md index 07ca9076..ec5db156 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Please consult our [general guidelines](#general-guidelines). - Proper integration with Node.js [async_hooks](https://nodejs.org/api/async_hooks.html) :white_check_mark: - Support for CommonJS, ESM and TypeScript :white_check_mark: - Support for [worker_threads](https://nodejs.org/api/worker_threads.html) and [cluster](https://nodejs.org/api/cluster.html) Node.js modules :white_check_mark: -- Support for multiple task functions :white_check_mark: +- Support for multiple task functions with per task function queuing priority and tasks distribution strategy :white_check_mark: - Support for task functions [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) operations at runtime :white_check_mark: - Support for sync and async task functions :white_check_mark: - Tasks distribution strategies :white_check_mark: diff --git a/docs/api.md b/docs/api.md index 731104f4..db56dc43 100644 --- a/docs/api.md +++ b/docs/api.md @@ -62,7 +62,7 @@ This method is available on both pool implementations and returns a boolean. ### `pool.addTaskFunction(name, fn)` `name` (mandatory) The task function name. -`fn` (mandatory) The task function. +`fn` (mandatory) The task function `(data?: Data) => Response | Promise` or task function object `{ taskFunction: (data?: Data) => Response | Promise, priority?: number, strategy?: WorkerChoiceStrategy }`. Priority range is the same as Unix nice levels. This method is available on both pool implementations and returns a boolean promise. @@ -149,7 +149,7 @@ An object with these properties: ### `class YourWorker extends ThreadWorker/ClusterWorker` -`taskFunctions` (mandatory) The task function or task functions object `{ name_1: fn_1, ..., name_n: fn_n }` that you want to execute on the worker. +`taskFunctions` (mandatory) The task function or task functions object `Record Response | Promise | { taskFunction: (data?: Data) => Response | Promise, priority?: number, strategy?: WorkerChoiceStrategy }>` that you want to execute on the worker. Priority range is the same as Unix nice levels. `opts` (optional) An object with these properties: - `killBehavior` (optional) - Dictates if your worker will be deleted in case a task is active on it. @@ -176,7 +176,7 @@ This method is available on both worker implementations and returns `{ status: b #### `YourWorker.addTaskFunction(name, fn)` `name` (mandatory) The task function name. -`fn` (mandatory) The task function. +`fn` (mandatory) The task function `(data?: Data) => Response | Promise` or task function object `{ taskFunction: (data?: Data) => Response | Promise, priority?: number, strategy?: WorkerChoiceStrategy }`. Priority range is the same as Unix nice levels. This method is available on both worker implementations and returns `{ status: boolean, error?: Error }`. -- 2.34.1