- [workerpool](https://github.com/josdejong/workerpool)
- [threadwork](https://github.com/kevlened/threadwork)
- [microjob](https://github.com/wilk/microjob)
+- [worker-threads-pool](https://github.com/watson/worker-threads-pool)
Those are our results:
'node dynamic-workerpool.js' \
'node fixed-workerpool.js' \
'node fixed-threadwork.js' \
- 'node fixed-microjob.js'
+ 'node fixed-microjob.js' \
+ 'node fixed-worker-threads-pool.js'
// IMPORT LIBRARIES
const Piscina = require('piscina')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
const piscina = new Piscina({
filename: './workers/piscina/function-to-bench-worker.js',
- minThreads: Number(size),
+ minThreads: size,
maxThreads: size * 3,
idleTimeout: 1000 * 60 // this is the same as poolifier default
})
// IMPORT LIBRARIES
const { DynamicThreadPool } = require('poolifier')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
}
const dynamicPool = new DynamicThreadPool(
- Number(size),
+ size,
size * 3,
'./workers/poolifier/function-to-bench-worker.js'
)
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
}
-const pool = new DynamicPool(Number(size))
+const pool = new DynamicPool(size)
async function run () {
const promises = []
// IMPORT LIBRARIES
const workerpool = require('workerpool')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
{
- minWorkers: Number(size),
+ minWorkers: size,
maxWorkers: size * 3,
workerType: 'thread'
}
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
}
async function run () {
- await start({ maxWorkers: Number(size) })
+ await start({ maxWorkers: size })
const promises = []
for (let i = 0; i < iterations; i++) {
promises.push(
// IMPORT LIBRARIES
const Piscina = require('piscina')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
const piscina = new Piscina({
filename: './workers/piscina/function-to-bench-worker.js',
- minThreads: Number(size),
+ minThreads: size,
idleTimeout: 1000 * 60 // this is the same as poolifier default
})
// IMPORT LIBRARIES
const { FixedThreadPool } = require('poolifier')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
}
const fixedPool = new FixedThreadPool(
- Number(size),
+ size,
'./workers/poolifier/function-to-bench-worker.js'
)
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
--- /dev/null
+// IMPORT LIBRARIES
+const Pool = require('worker-threads-pool')
+// FINISH IMPORT LIBRARIES
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
+const data = {
+ test: 'MYBENCH',
+ taskType: process.env['TASK_TYPE']
+}
+
+const pool = new Pool({ max: size })
+
+async function run () {
+ const promises = []
+ for (let i = 0; i < iterations; i++) {
+ promises.push(
+ pool.acquire(
+ './workers/worker-threads-pool/function-to-bench-worker.js',
+ {
+ workerData: data
+ }
+ )
+ )
+ }
+ await Promise.all(promises)
+ process.exit()
+}
+
+run()
// IMPORT LIBRARIES
const workerpool = require('workerpool')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
{
- minWorkers: Number(size),
- maxWorkers: Number(size),
+ minWorkers: size,
+ maxWorkers: size,
workerType: 'thread'
}
)
}
},
"poolifier": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.0.tgz",
- "integrity": "sha512-17gRE5OJJvTusOdLzykjrNkFoZFUu2GLKXFrqMqx2EhKmIRS1XzVej+LdhUJn+sdsAap/RQDXVW2u0GcSMSuQQ=="
+ "version": "2.0.1",
+ "resolved": "https://registry.npmjs.org/poolifier/-/poolifier-2.0.1.tgz",
+ "integrity": "sha512-klkLv35QVumXKrQj6Totvwqb0lw34j7mIsEm8uZXXHlcpVCvnhhgVFVyuZUOSNTjZnBCaiB0KcLos03cqj38CA=="
},
"symbol-observable": {
"version": "1.2.0",
"microjob": "0.7.0",
"node-worker-threads-pool": "1.4.3",
"piscina": "2.2.0",
- "poolifier": "2.0.0",
+ "poolifier": "2.0.1",
"threads": "1.6.3",
"threadwork": "0.6.0",
"worker-threads-pool": "2.0.0",
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
}
const pool = new StaticPool({
- size: Number(size),
+ size: size,
task: functionToBench
})
// IMPORT LIBRARIES
const { spawn, Thread, Worker } = require('threads')
// FINISH IMPORT LIBRARIES
-const size = process.env.POOL_SIZE
-const iterations = process.env.NUM_ITERATIONS
+const size = Number(process.env.POOL_SIZE)
+const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env['TASK_TYPE']
--- /dev/null
+'use strict'
+const { workerData } = require('worker_threads')
+const functionToBench = require('../../functions/function-to-bench')
+functionToBench(workerData)
"requires": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
+ "fsevents": "~2.3.1",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",