} from '../lib/index.mjs'
import { TaskFunctions } from './benchmarks-types.mjs'
-export const runTest = async (pool, { taskExecutions, workerData }) => {
+export const buildPoolifierPool = (
+ workerType,
+ poolType,
+ poolSize,
+ poolOptions
+) => {
+ switch (poolType) {
+ case PoolTypes.fixed:
+ switch (workerType) {
+ case WorkerTypes.thread:
+ return new FixedThreadPool(
+ poolSize,
+ './benchmarks/internal/thread-worker.mjs',
+ poolOptions
+ )
+ case WorkerTypes.cluster:
+ return new FixedClusterPool(
+ poolSize,
+ './benchmarks/internal/cluster-worker.mjs',
+ poolOptions
+ )
+ }
+ break
+ case PoolTypes.dynamic:
+ switch (workerType) {
+ case WorkerTypes.thread:
+ return new DynamicThreadPool(
+ Math.floor(poolSize / 2),
+ poolSize,
+ './benchmarks/internal/thread-worker.mjs',
+ poolOptions
+ )
+ case WorkerTypes.cluster:
+ return new DynamicClusterPool(
+ Math.floor(poolSize / 2),
+ poolSize,
+ './benchmarks/internal/cluster-worker.mjs',
+ poolOptions
+ )
+ }
+ break
+ }
+}
+
+export const runPoolifierTest = async (
+ pool,
+ { taskExecutions, workerData }
+) => {
return new Promise((resolve, reject) => {
let executions = 0
for (let i = 1; i <= taskExecutions; i++) {
})
}
+export const executeAsyncFn = async fn => {
+ try {
+ await fn()
+ } catch (e) {
+ console.error(e)
+ // eslint-disable-next-line n/no-process-exit
+ process.exit(1)
+ }
+}
+
export const generateRandomInteger = (
max = Number.MAX_SAFE_INTEGER,
min = 0
throw new Error('Unknown task function')
}
}
-
-export const buildPool = (workerType, poolType, poolSize, poolOptions) => {
- switch (poolType) {
- case PoolTypes.fixed:
- switch (workerType) {
- case WorkerTypes.thread:
- return new FixedThreadPool(
- poolSize,
- './benchmarks/internal/thread-worker.mjs',
- poolOptions
- )
- case WorkerTypes.cluster:
- return new FixedClusterPool(
- poolSize,
- './benchmarks/internal/cluster-worker.mjs',
- poolOptions
- )
- }
- break
- case PoolTypes.dynamic:
- switch (workerType) {
- case WorkerTypes.thread:
- return new DynamicThreadPool(
- Math.floor(poolSize / 2),
- poolSize,
- './benchmarks/internal/thread-worker.mjs',
- poolOptions
- )
- case WorkerTypes.cluster:
- return new DynamicClusterPool(
- Math.floor(poolSize / 2),
- poolSize,
- './benchmarks/internal/cluster-worker.mjs',
- poolOptions
- )
- }
- break
- }
-}
availableParallelism
} from '../../lib/index.mjs'
import { TaskFunctions } from '../benchmarks-types.mjs'
-import { buildPool, runTest } from '../benchmarks-utils.mjs'
+import { buildPoolifierPool, runPoolifierTest } from '../benchmarks-utils.mjs'
const poolSize = availableParallelism()
const pools = []
for (const measurement of [Measurements.runTime, Measurements.elu]) {
pools.push([
`${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}|measurement:${measurement}`,
- buildPool(workerType, poolType, poolSize, {
+ buildPoolifierPool(workerType, poolType, poolSize, {
workerChoiceStrategy,
workerChoiceStrategyOptions: {
measurement
} else {
pools.push([
`${poolType}|${workerType}|${workerChoiceStrategy}|tasks queue:${enableTasksQueue}`,
- buildPool(workerType, poolType, poolSize, {
+ buildPoolifierPool(workerType, poolType, poolSize, {
workerChoiceStrategy,
enableTasksQueue
})
const addPools = pools =>
pools.map(([name, pool]) => {
return add(name, async () => {
- await runTest(pool, {
+ await runPoolifierTest(pool, {
taskExecutions,
workerData
})
-// IMPORT LIBRARIES
import { DynamicPool } from 'node-worker-threads-pool'
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-// FINISH IMPORT FUNCTION TO BENCH
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import Piscina from 'piscina'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import { DynamicThreadPool } from 'poolifier'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import Tinypool from 'tinypool'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
'use strict'
-// IMPORT LIBRARIES
const WorkerNodes = require('worker-nodes')
-// FINISH IMPORT LIBRARIES
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
-// IMPORT LIBRARIES
import workerpool from 'workerpool'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const dataArray = [
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import { ThreadPool } from 'nanothreads'
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-// FINISH IMPORT FUNCTION TO BENCH
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import Piscina from 'piscina'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import { FixedThreadPool } from 'poolifier'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import Tinypool from 'tinypool'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)
'use strict'
-// IMPORT LIBRARIES
const WorkerNodes = require('worker-nodes')
-// FINISH IMPORT LIBRARIES
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
-// IMPORT LIBRARIES
import workerpool from 'workerpool'
-// FINISH IMPORT LIBRARIES
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const dataArray = [
process.exit()
}
-await run()
+await executeAsyncFn(run)
-// IMPORT LIBRARIES
import { StaticPool } from 'node-worker-threads-pool'
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
+import { executeAsyncFn } from '../benchmarks-utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-// FINISH IMPORT FUNCTION TO BENCH
+
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-await run()
+await executeAsyncFn(run)