Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "piscina", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A fast, efficient Node.js Worker Thread Pool implementation", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -24,3 +24,3 @@ /// <reference types="node" /> | ||
idleTimeout?: number; | ||
maxQueue?: number; | ||
maxQueue?: number | 'auto'; | ||
concurrentTasksPerWorker?: number; | ||
@@ -27,0 +27,0 @@ useAtomics?: boolean; |
@@ -205,2 +205,5 @@ "use strict"; | ||
} | ||
if (options.maxQueue === 'auto') { | ||
this.options.maxQueue = this.options.maxThreads ** 2; | ||
} | ||
this._ensureMinimumWorkers(); | ||
@@ -452,2 +455,3 @@ } | ||
if (options.maxQueue !== undefined && | ||
options.maxQueue !== 'auto' && | ||
(typeof options.maxQueue !== 'number' || options.maxQueue < 0)) { | ||
@@ -454,0 +458,0 @@ throw new TypeError('options.maxQueue must be a non-negative integer'); |
{ | ||
"name": "piscina", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A fast, efficient Node.js Worker Thread Pool implementation", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -157,3 +157,3 @@ # piscina - the node.js worker pool | ||
filename: resolve(__dirname, 'worker.js'), | ||
maxQueue: 8 | ||
maxQueue: 'auto' | ||
}); | ||
@@ -171,7 +171,6 @@ | ||
performance.mark('A'); | ||
stream | ||
.on('data', (data) => { | ||
pool.runTask(data); | ||
if (pool.queueSize === maxQueue) { | ||
if (pool.queueSize === pool.options.maxQueue) { | ||
console.log('pausing...', counter, pool.queueSize); | ||
@@ -220,5 +219,8 @@ stream.pause(); | ||
shut down. By default, this is immediate. | ||
* `maxQueue`: (`number`) The maximum number of tasks that may be scheduled | ||
to run, but not yet running due to lack of available threads, at a given | ||
time. By default, there is no limit. | ||
* `maxQueue`: (`number` | `string`) The maximum number of tasks that may be | ||
scheduled to run, but not yet running due to lack of available threads, at | ||
a given time. By default, there is no limit. The special value `'auto'` | ||
may be used to have Piscina calculate the maximum as the square of `maxThreads`. | ||
When `'auto'` is used, the calculated `maxQueue` value may be found by checking | ||
the [`options.maxQueue`](#property-options-readonly) property. | ||
* `concurrentTasksPerWorker`: (`number`) Specifies how many tasks can share | ||
@@ -428,4 +430,29 @@ a single Worker thread simultaneously. The default is `1`. This generally | ||
Piscina provides the ability to configure the minimum and | ||
maximum number of worker threads active in the pool, as well as | ||
set limits on the number of tasks that may be queued up waiting | ||
for a free worker. It is important to note that setting the | ||
`maxQueue` size too high relative to the number of worker threads | ||
can have a detrimental impact on performance and memory usage. | ||
Setting the `maxQueue` size too small can also be problematic | ||
as doing so could cause your worker threads to become idle and | ||
be shutdown. Our testing has shown that a `maxQueue` size of | ||
approximately the square of the maximum number of threads is | ||
generally sufficient and performs well for many cases, but this | ||
will vary depending on your workload. It will be important to | ||
test and benchmark your worker pools to ensure you've effectively | ||
balanced queue wait times, memory usage, and worker pool utilization. | ||
## Release Notes | ||
### 1.4.0 | ||
* Added `maxQueue = 'auto'` to autocalculate the maximum queue size. | ||
* Added more examples, including an example of implementing a worker | ||
as a Node.js native addon. | ||
### 1.3.0 | ||
* Added the `'drain'` event | ||
### 1.2.0 | ||
@@ -432,0 +459,0 @@ |
@@ -57,3 +57,3 @@ import { Worker, MessageChannel, MessagePort, receiveMessageOnPort } from 'worker_threads'; | ||
idleTimeout? : number, | ||
maxQueue? : number, | ||
maxQueue? : number | 'auto', | ||
concurrentTasksPerWorker? : number, | ||
@@ -73,3 +73,3 @@ useAtomics? : boolean, | ||
idleTimeout : number, | ||
maxQueue : number, | ||
maxQueue : number | 'auto', | ||
concurrentTasksPerWorker : number, | ||
@@ -291,2 +291,5 @@ useAtomics: boolean | ||
} | ||
if (options.maxQueue === 'auto') { | ||
this.options.maxQueue = this.options.maxThreads ** 2; | ||
} | ||
@@ -581,2 +584,3 @@ this._ensureMinimumWorkers(); | ||
if (options.maxQueue !== undefined && | ||
options.maxQueue !== 'auto' && | ||
(typeof options.maxQueue !== 'number' || options.maxQueue < 0)) { | ||
@@ -583,0 +587,0 @@ throw new TypeError('options.maxQueue must be a non-negative integer'); |
@@ -58,3 +58,3 @@ import Piscina from '..'; | ||
test('maxQueue must be non-negative integer', async ({ throws }) => { | ||
test('maxQueue must be non-negative integer', async ({ throws, is }) => { | ||
throws(() => new Piscina(({ | ||
@@ -67,2 +67,5 @@ maxQueue: -1 | ||
}) as any), /options.maxQueue must be a non-negative integer/); | ||
const p = new Piscina({ maxQueue: 'auto', maxThreads: 2 }); | ||
is(p.options.maxQueue, 4); | ||
}); | ||
@@ -69,0 +72,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136744
2430
485