- External pools with which we used to compare the poolifier results:
- <!-- - [node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool): removed because it does not support dynamic modules import or import outside the worker function. The worker function is expected to be self-contained, which makes it difficult to use in real world application without ugly hacks. -->
+ <!-- - [node-worker-threads-pool](https://github.com/SUCHMOKUO/node-worker-threads-pool): removed because it does not support dynamic modules import or import outside the task function. The task function is expected to be self-contained, which makes it difficult to use in real world application without ugly hacks. -->
- [worker-threads-pool](https://github.com/watson/worker-threads-pool): removed because unmaintained since more than 4 years.
- [threadwork](https://github.com/kevlened/threadwork): removed because unmaintained since more than 3 years.
-export const WorkerFunctions = {
+export const TaskFunctions = {
jsonIntegerSerialization: 'jsonIntegerSerialization',
fibonacci: 'fibonacci',
factorial: 'factorial',
PoolTypes,
WorkerTypes
} from '../lib/index.mjs'
-import { WorkerFunctions } from './benchmarks-types.mjs'
+import { TaskFunctions } from './benchmarks-types.mjs'
export const runTest = async (pool, { taskExecutions, workerData }) => {
return new Promise((resolve, reject) => {
return { ok: 1 }
}
-export const executeWorkerFunction = data => {
+export const executeTaskFunction = data => {
switch (data.function) {
- case WorkerFunctions.jsonIntegerSerialization:
+ case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.taskSize || 1000)
- case WorkerFunctions.fibonacci:
+ case TaskFunctions.fibonacci:
return fibonacci(data.taskSize || 1000)
- case WorkerFunctions.factorial:
+ case TaskFunctions.factorial:
return factorial(data.taskSize || 1000)
- case WorkerFunctions.readWriteFiles:
+ case TaskFunctions.readWriteFiles:
return readWriteFiles(data.taskSize || 1000)
default:
- throw new Error('Unknown worker function')
+ throw new Error('Unknown task function')
}
}
WorkerTypes,
availableParallelism
} from '../../lib/index.mjs'
-import { WorkerFunctions } from '../benchmarks-types.mjs'
+import { TaskFunctions } from '../benchmarks-types.mjs'
import { buildPool, runTest } from '../benchmarks-utils.mjs'
const poolSize = availableParallelism()
const taskExecutions = 1
const workerData = {
- function: WorkerFunctions.jsonIntegerSerialization,
+ function: TaskFunctions.jsonIntegerSerialization,
taskSize: 1000
}
const addPools = pools =>
import { isMaster } from 'cluster'
import { ClusterWorker } from '../../lib/index.mjs'
-import { executeWorkerFunction } from '../benchmarks-utils.mjs'
-import { WorkerFunctions } from '../benchmarks-types.mjs'
+import { executeTaskFunction } from '../benchmarks-utils.mjs'
+import { TaskFunctions } from '../benchmarks-types.mjs'
const debug = false
-function workerFunction (data) {
+function taskFunction (data) {
data = data || {}
- data.function = data.function || WorkerFunctions.jsonIntegerSerialization
- const res = executeWorkerFunction(data)
+ data.function = data.function || TaskFunctions.jsonIntegerSerialization
+ const res = executeTaskFunction(data)
debug === true && console.debug('This is the main thread ' + isMaster)
return res
}
-export default new ClusterWorker(workerFunction)
+export default new ClusterWorker(taskFunction)
import { isMainThread } from 'worker_threads'
import { ThreadWorker } from '../../lib/index.mjs'
-import { executeWorkerFunction } from '../benchmarks-utils.mjs'
-import { WorkerFunctions } from '../benchmarks-types.mjs'
+import { executeTaskFunction } from '../benchmarks-utils.mjs'
+import { TaskFunctions } from '../benchmarks-types.mjs'
const debug = false
-function workerFunction (data) {
+function taskFunction (data) {
data = data || {}
- data.function = data.function || WorkerFunctions.jsonIntegerSerialization
- const res = executeWorkerFunction(data)
+ data.function = data.function || TaskFunctions.jsonIntegerSerialization
+ const res = executeTaskFunction(data)
debug === true && console.debug('This is the main thread ' + isMainThread)
return res
}
-export default new ThreadWorker(workerFunction)
+export default new ThreadWorker(taskFunction)
'use strict'
/**
- * The worker function to execute during pools benchmarks.
- * NOTE: This function requires to be self-contained, thread-safe and re-entrant.
+ * The task function to execute during pools benchmarks.
+ * NOTE: This function requires to be self-contained, thread-safe and re-entrant (node-worker-threads-pool requirement).
* @param {*} data The worker data.
* @returns {*} The result.
*/
const { expect } = require('expect')
const { DynamicClusterPool, PoolEvents } = require('../../../lib')
-const { WorkerFunctions } = require('../../test-types')
+const { TaskFunctions } = require('../../test-types')
const { sleep, waitWorkerEvents } = require('../../test-utils')
describe('Dynamic cluster pool test suite', () => {
it('Verify that the function is executed in a worker cluster', async () => {
let result = await pool.execute({
- function: WorkerFunctions.fibonacci
+ function: TaskFunctions.fibonacci
})
expect(result).toBe(75025)
result = await pool.execute({
- function: WorkerFunctions.factorial
+ function: TaskFunctions.factorial
})
expect(result).toBe(9.33262154439441e157)
})
const { expect } = require('expect')
const { FixedClusterPool, PoolEvents } = require('../../../lib')
-const { WorkerFunctions } = require('../../test-types')
+const { TaskFunctions } = require('../../test-types')
const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils')
describe('Fixed cluster pool test suite', () => {
it('Verify that the function is executed in a worker cluster', async () => {
let result = await pool.execute({
- function: WorkerFunctions.fibonacci
+ function: TaskFunctions.fibonacci
})
expect(result).toBe(75025)
result = await pool.execute({
- function: WorkerFunctions.factorial
+ function: TaskFunctions.factorial
})
expect(result).toBe(9.33262154439441e157)
})
const { expect } = require('expect')
const { DynamicThreadPool, PoolEvents } = require('../../../lib')
-const { WorkerFunctions } = require('../../test-types')
+const { TaskFunctions } = require('../../test-types')
const { sleep, waitWorkerEvents } = require('../../test-utils')
describe('Dynamic thread pool test suite', () => {
it('Verify that the function is executed in a worker thread', async () => {
let result = await pool.execute({
- function: WorkerFunctions.fibonacci
+ function: TaskFunctions.fibonacci
})
expect(result).toBe(75025)
result = await pool.execute({
- function: WorkerFunctions.factorial
+ function: TaskFunctions.factorial
})
expect(result).toBe(9.33262154439441e157)
})
const { expect } = require('expect')
const { FixedThreadPool, PoolEvents } = require('../../../lib')
-const { WorkerFunctions } = require('../../test-types')
+const { TaskFunctions } = require('../../test-types')
const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils')
describe('Fixed thread pool test suite', () => {
it('Verify that the function is executed in a worker thread', async () => {
let result = await pool.execute({
- function: WorkerFunctions.fibonacci
+ function: TaskFunctions.fibonacci
})
expect(result).toBe(75025)
result = await pool.execute({
- function: WorkerFunctions.factorial
+ function: TaskFunctions.factorial
})
expect(result).toBe(9.33262154439441e157)
})
-const WorkerFunctions = {
+const TaskFunctions = {
jsonIntegerSerialization: 'jsonIntegerSerialization',
fibonacci: 'fibonacci',
factorial: 'factorial'
}
-module.exports = { WorkerFunctions }
+module.exports = { TaskFunctions }
-const { WorkerFunctions } = require('./test-types')
+const { TaskFunctions } = require('./test-types')
const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => {
return new Promise(resolve => {
return new Promise(resolve => setTimeout(resolve, ms))
}
-const sleepWorkerFunction = async (
+const sleepTaskFunction = async (
data,
ms,
rejection = false,
return factorial(n - 1) * n
}
-const executeWorkerFunction = data => {
+const executeTaskFunction = data => {
switch (data.function) {
- case WorkerFunctions.jsonIntegerSerialization:
+ case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.n || 100)
- case WorkerFunctions.fibonacci:
+ case TaskFunctions.fibonacci:
return fibonacci(data.n || 25)
- case WorkerFunctions.factorial:
+ case TaskFunctions.factorial:
return factorial(data.n || 100)
default:
throw new Error('Unknown worker function')
}
module.exports = {
- executeWorkerFunction,
+ executeTaskFunction,
factorial,
fibonacci,
generateRandomInteger,
jsonIntegerSerialization,
sleep,
- sleepWorkerFunction,
+ sleepTaskFunction,
waitPoolEvents,
waitWorkerEvents
}
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function error (data) {
- return sleepWorkerFunction(
+ return sleepTaskFunction(
data,
2000,
true,
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 2000)
+ return sleepTaskFunction(data, 2000)
}
module.exports = new ClusterWorker(sleep, {
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 50000)
+ return sleepTaskFunction(data, 50000)
}
module.exports = new ClusterWorker(sleep, {
'use strict'
const { ClusterWorker } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 50000)
+ return sleepTaskFunction(data, 50000)
}
module.exports = new ClusterWorker(sleep, {
'use strict'
const { ClusterWorker, KillBehaviors } = require('../../../lib')
-const { executeWorkerFunction } = require('../../test-utils')
-const { WorkerFunctions } = require('../../test-types')
+const { executeTaskFunction } = require('../../test-utils')
+const { TaskFunctions } = require('../../test-types')
function test (data) {
data = data || {}
- data.function = data.function || WorkerFunctions.jsonIntegerSerialization
- return executeWorkerFunction(data)
+ data.function = data.function || TaskFunctions.jsonIntegerSerialization
+ return executeTaskFunction(data)
}
module.exports = new ClusterWorker(test, {
'use strict'
const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function error (data) {
- return sleepWorkerFunction(
+ return sleepTaskFunction(
data,
2000,
true,
'use strict'
const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 2000)
+ return sleepTaskFunction(data, 2000)
}
module.exports = new ThreadWorker(sleep, {
'use strict'
const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 50000)
+ return sleepTaskFunction(data, 50000)
}
module.exports = new ThreadWorker(sleep, {
'use strict'
const { ThreadWorker } = require('../../../lib')
-const { sleepWorkerFunction } = require('../../test-utils')
+const { sleepTaskFunction } = require('../../test-utils')
async function sleep (data) {
- return sleepWorkerFunction(data, 50000)
+ return sleepTaskFunction(data, 50000)
}
module.exports = new ThreadWorker(sleep, {
'use strict'
const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { executeWorkerFunction } = require('../../test-utils')
-const { WorkerFunctions } = require('../../test-types')
+const { executeTaskFunction } = require('../../test-utils')
+const { TaskFunctions } = require('../../test-types')
function test (data) {
data = data || {}
- data.function = data.function || WorkerFunctions.jsonIntegerSerialization
- return executeWorkerFunction(data)
+ data.function = data.function || TaskFunctions.jsonIntegerSerialization
+ return executeTaskFunction(data)
}
module.exports = new ThreadWorker(test, {