poolifier 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,8 +11,8 @@
11
11
  <p align="center">
12
12
  <a href="https://www.npmjs.com/package/poolifier">
13
13
  <img alt="Weekly Downloads" src="https://img.shields.io/npm/dw/poolifier"></a>
14
- <a href="https://github.com/pioardi/node-pool/actions">
15
- <img alt="Actions Status" src="https://github.com/pioardi/node-pool/workflows/NodeCI/badge.svg"></a>
14
+ <a href="https://github.com/poolifier/poolifier/actions">
15
+ <img alt="Actions Status" src="https://github.com/poolifier/poolifier/workflows/NodeCI/badge.svg"></a>
16
16
  <a href="https://sonarcloud.io/dashboard?id=pioardi_poolifier">
17
17
  <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=pioardi_poolifier&metric=alert_status"></a>
18
18
  <a href="https://sonarcloud.io/component_measures/metric/coverage/list?id=pioardi_poolifier">
@@ -29,7 +29,7 @@
29
29
  <img alt="No dependencies" src="https://img.shields.io/static/v1?label=dependencies&message=no%20dependencies&color=brightgreen"></a>
30
30
  </p>
31
31
 
32
- ## Why Poolifier?
32
+ ## Why Poolifier?
33
33
 
34
34
  Poolifier is used to perform CPU intensive and I/O intensive tasks on nodejs servers, it implements worker pools (yes, more worker pool implementations, so you can choose which one fit better for you) using [worker-threads](https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads) and cluster pools using [Node.js cluster](https://nodejs.org/api/cluster.html) modules.
35
35
  With poolifier you can improve your **performance** and resolve problems related to the event loop.
@@ -65,7 +65,7 @@ Please consult our <a href="#general-guidance">general guidelines</a>
65
65
  <span> · </span>
66
66
  <a href="#usage">Usage</a>
67
67
  <span> · </span>
68
- <a href="#node-versions"> Node versions</a>
68
+ <a href="#node-versions">Node versions</a>
69
69
  <span> · </span>
70
70
  <a href="#api">API</a>
71
71
  <span> · </span>
@@ -146,19 +146,27 @@ Remember that workers can only send and receive serializable data.
146
146
 
147
147
  ## Node versions
148
148
 
149
- You can use node versions 12.x, 13.x, 14.x
149
+ You can use node versions 12.x, 13.x, 14.x, 16.x
150
150
 
151
151
  ## API
152
152
 
153
153
  ### `pool = new FixedThreadPool/FixedClusterPool(numberOfThreads/numberOfWorkers, filePath, opts)`
154
154
 
155
- `numberOfThreads/numberOfWorkers` (mandatory) Num of workers for this worker pool
155
+ `numberOfThreads/numberOfWorkers` (mandatory) Number of workers for this pool
156
156
  `filePath` (mandatory) Path to a file with a worker implementation
157
- `opts` (optional) An object with these properties :
157
+ `opts` (optional) An object with these properties:
158
+
159
+ - `errorHandler` (optional) - A function that will listen for error event on each worker
160
+ - `onlineHandler` (optional) - A function that will listen for online event on each worker
161
+ - `exitHandler` (optional) - A function that will listen for exit event on each worker
162
+ - `workerChoiceStrategy` (optional) - The work choice strategy to use in this pool:
163
+
164
+ - `WorkerChoiceStrategies.ROUND_ROBIN`: Submit tasks to worker in this pool in a round robbin fashion
165
+ - `WorkerChoiceStrategies.LESS_RECENTLY_USED`: Submit tasks to the less recently used worker in the pool
166
+
167
+ Default: `WorkerChoiceStrategies.ROUND_ROBIN`
158
168
 
159
- - `errorHandler` - A function that will listen for error event on each worker
160
- - `onlineHandler` - A function that will listen for online event on each worker
161
- - `exitHandler` - A function that will listen for exit event on each worker
169
+ - `enableEvents` (optional) - Events emission enablement in this pool. Default: true
162
170
 
163
171
  ### `pool = new DynamicThreadPool/DynamicClusterPool(min, max, filePath, opts)`
164
172
 
@@ -169,7 +177,7 @@ You can use node versions 12.x, 13.x, 14.x
169
177
 
170
178
  ### `pool.execute(data)`
171
179
 
172
- Execute method is available on both pool implementations (return type : Promise):
180
+ Execute method is available on both pool implementations (return type: Promise):
173
181
  `data` (mandatory) An object that you want to pass to your worker implementation
174
182
 
175
183
  ### `pool.destroy()`
@@ -190,10 +198,10 @@ This method will call the terminate method on each worker.
190
198
 
191
199
  - `async` - true/false, true if your function contains async pieces else false
192
200
  - `killBehavior` - Dictates if your async unit (worker/process) will be deleted in case that a task is active on it.
193
- **SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **won't** be deleted.
194
- **HARD**: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
201
+ **KillBehaviors.SOFT**: If `currentTime - lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker **won't** be deleted.
202
+ **KillBehaviors.HARD**: If `lastActiveTime` is greater than `maxInactiveTime` but a task is still running, then the worker will be deleted.
195
203
  This option only apply to the newly created workers.
196
- Default: `SOFT`
204
+ Default: `KillBehaviors.SOFT`
197
205
 
198
206
  ## General guidance
199
207
 
@@ -205,7 +213,7 @@ We already have a bench folder where you can find some comparisons.
205
213
  Before to jump into each poolifier pool type, let highlight that **Node.js comes with a thread pool already**, the libuv thread pool where some particular tasks already run by default.
206
214
  Please take a look at [which tasks run on the libuv thread pool](https://nodejs.org/en/docs/guides/dont-block-the-event-loop/#what-code-runs-on-the-worker-pool).
207
215
 
208
- Now **if your task runs on libuv thread pool**, you can try to:
216
+ **If your task runs on libuv thread pool**, you can try to:
209
217
 
210
218
  - Tune the libuv thread pool size setting the [UV_THREADPOOL_SIZE](https://nodejs.org/api/cli.html#cli_uv_threadpool_size_size)
211
219
 
@@ -236,7 +244,7 @@ But in general, **always profile your application**
236
244
  ## Contribute
237
245
 
238
246
  See guidelines [CONTRIBUTING](CONTRIBUTING.md)
239
- Choose your task here [2.0.0](https://github.com/pioardi/poolifier/projects/1), propose an idea, a fix, an improvement.
247
+ Choose your task here [2.0.0](https://github.com/poolifier/poolifier/projects/1), propose an idea, a fix, an improvement.
240
248
 
241
249
  ## Team
242
250