const WorkerFunctions = {
jsonIntegerSerialization: 'jsonIntegerSerialization',
fibonacci: 'fibonacci',
- factorial: 'factorial'
+ factorial: 'factorial',
+ readWriteFiles: 'readWriteFiles'
}
-module.exports = { WorkerFunctions }
+const PoolTypes = {
+ FIXED: 'fixed',
+ DYNAMIC: 'dynamic'
+}
+
+const WorkerTypes = {
+ THREAD: 'thread',
+ CLUSTER: 'cluster'
+}
+
+module.exports = { PoolTypes, WorkerFunctions, WorkerTypes }
-const { WorkerFunctions } = require('./benchmarks-types')
+const fs = require('fs')
+const {
+ PoolTypes,
+ WorkerFunctions,
+ WorkerTypes
+} = require('./benchmarks-types')
+const {
+ DynamicClusterPool,
+ DynamicThreadPool,
+ FixedClusterPool,
+ FixedThreadPool
+} = require('../lib')
-async function runPoolifierTest (pool, { tasks, workerData }) {
+async function runTest (pool, { taskExecutions, workerData }) {
return new Promise((resolve, reject) => {
let executions = 0
- for (let i = 1; i <= tasks; i++) {
+ for (let i = 1; i <= taskExecutions; i++) {
pool
.execute(workerData)
.then(() => {
++executions
- if (executions === tasks) {
+ if (executions === taskExecutions) {
return resolve({ ok: 1 })
}
return null
})
}
-function jsonIntegerSerialization (n) {
- for (let i = 0; i < n; i++) {
- const o = {
- a: i
- }
- JSON.stringify(o)
- }
-}
-
function generateRandomInteger (max = Number.MAX_SAFE_INTEGER, min = 0) {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
return Math.floor(Math.random() * (max + 1))
}
+function jsonIntegerSerialization (n) {
+ for (let i = 0; i < n; i++) {
+ const o = {
+ a: i
+ }
+ JSON.stringify(o)
+ }
+}
+
/**
* Intentionally inefficient implementation.
*
return factorial(n - 1) * n
}
+function readWriteFiles (n) {
+ const baseDirectory = '/tmp/poolifier-benchmarks'
+ if (fs.existsSync(baseDirectory) === false) {
+ fs.mkdirSync(baseDirectory, { recursive: true })
+ }
+ for (let i = 0; i < n; i++) {
+ const filePath = `${baseDirectory}/${i}`
+ fs.writeFileSync(filePath, i.toString(), {
+ encoding: 'utf8',
+ flag: 'a'
+ })
+ fs.readFileSync(filePath, 'utf8')
+ }
+}
+
function executeWorkerFunction (data) {
switch (data.function) {
case WorkerFunctions.jsonIntegerSerialization:
return fibonacci(data.taskSize || 1000)
case WorkerFunctions.factorial:
return factorial(data.taskSize || 1000)
+ case WorkerFunctions.readWriteFiles:
+ return readWriteFiles(data.taskSize || 1000)
default:
throw new Error('Unknown worker function')
}
}
+function buildPool (poolType, poolSize, workerType, poolOptions) {
+ switch (poolType) {
+ case PoolTypes.FIXED:
+ switch (workerType) {
+ case WorkerTypes.THREAD:
+ return new FixedThreadPool(
+ poolSize,
+ './benchmarks/internal/thread-worker.js',
+ poolOptions
+ )
+ case WorkerTypes.CLUSTER:
+ return new FixedClusterPool(
+ poolSize,
+ './benchmarks/internal/cluster-worker.js',
+ poolOptions
+ )
+ }
+ break
+ case PoolTypes.DYNAMIC:
+ switch (workerType) {
+ case WorkerTypes.THREAD:
+ return new DynamicThreadPool(
+ poolSize / 2,
+ poolSize * 3,
+ './benchmarks/internal/thread-worker.js',
+ poolOptions
+ )
+ case WorkerTypes.CLUSTER:
+ return new DynamicClusterPool(
+ poolSize / 2,
+ poolSize * 3,
+ './benchmarks/internal/cluster-worker.js',
+ poolOptions
+ )
+ }
+ break
+ }
+}
+
module.exports = {
WorkerFunctions,
+ buildPool,
executeWorkerFunction,
generateRandomInteger,
- runPoolifierTest
+ readWriteFiles,
+ runTest
}
const Benchmark = require('benny')
+const { WorkerChoiceStrategies } = require('../../lib')
const {
- dynamicClusterTest,
- dynamicClusterTestFairShare,
- dynamicClusterTestLessUsed,
- dynamicClusterTestWeightedRoundRobin,
- dynamicClusterTestLessBusy
-} = require('./cluster/dynamic')
-const {
- fixedClusterTest,
- fixedClusterTasksQueueTest,
- fixedClusterTestFairShare,
- fixedClusterTestLessUsed,
- fixedClusterTestWeightedRoundRobin,
- fixedClusterTestLessBusy
-} = require('./cluster/fixed')
-const {
- dynamicThreadTest,
- dynamicThreadTestFairShare,
- dynamicThreadTestLessUsed,
- dynamicThreadTestWeightedRoundRobin,
- dynamicThreadTestLessBusy
-} = require('./thread/dynamic')
-const {
- fixedThreadTest,
- fixedThreadTasksQueueTest,
- fixedThreadTestFairShare,
- fixedThreadTestLessUsed,
- fixedThreadTestWeightedRoundRobin,
- fixedThreadTestLessBusy
-} = require('./thread/fixed')
+ PoolTypes,
+ WorkerFunctions,
+ WorkerTypes
+} = require('../benchmarks-types')
+const { buildPool, runTest } = require('../benchmarks-utils')
+
+const poolSize = 30
+const taskExecutions = 1
+const workerData = {
+ function: WorkerFunctions.jsonIntegerSerialization,
+ taskSize: 1000
+}
+const tasksQueuePoolOption = { enableTasksQueue: true }
+const workerChoiceStrategyRoundRobinPoolOption = {
+ workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN
+}
+const workerChoiceStrategyLessUsedPoolOption = {
+ workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED
+}
+const workerChoiceStrategyLessBusyPoolOption = {
+ workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY
+}
+const workerChoiceStrategyWeightedRoundRobinPoolOption = {
+ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+}
+const workerChoiceStrategyFairSharePoolOption = {
+ workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE
+}
+
+const fixedThreadPoolRoundRobin = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyRoundRobinPoolOption
+)
+
+const fixedThreadPoolRoundRobinTasksQueue = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
+)
+
+const fixedThreadPoolLessUsed = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyLessUsedPoolOption
+)
+
+const fixedThreadPoolLessBusy = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyLessBusyPoolOption
+)
+
+const fixedThreadPoolWeightedRoundRobin = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const fixedThreadPoolFairShare = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyFairSharePoolOption
+)
+
+const dynamicThreadPoolRoundRobin = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyRoundRobinPoolOption
+)
+
+const dynamicThreadPoolLessUsed = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyLessUsedPoolOption
+)
+
+const dynamicThreadPoolLessBusy = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyLessBusyPoolOption
+)
+
+const dynamicThreadPoolWeightedRoundRobin = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const dynamicThreadPoolFairShare = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.THREAD,
+ workerChoiceStrategyFairSharePoolOption
+)
+
+const fixedClusterPoolRoundRobin = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyRoundRobinPoolOption
+)
+
+const fixedClusterPoolRoundRobinTasksQueue = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ { ...workerChoiceStrategyRoundRobinPoolOption, ...tasksQueuePoolOption }
+)
+
+const fixedClusterPoolLessUsed = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyLessUsedPoolOption
+)
+
+const fixedClusterPoolLessBusy = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyLessBusyPoolOption
+)
+
+const fixedClusterPoolWeightedRoundRobin = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const fixedClusterPoolFairShare = buildPool(
+ PoolTypes.FIXED,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyFairSharePoolOption
+)
+
+const dynamicClusterPoolRoundRobin = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyRoundRobinPoolOption
+)
+
+const dynamicClusterPoolLessUsed = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyLessUsedPoolOption
+)
+
+const dynamicClusterPoolLessBusy = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyLessBusyPoolOption
+)
+
+const dynamicClusterPoolWeightedRoundRobin = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyWeightedRoundRobinPoolOption
+)
+
+const dynamicClusterPoolFairShare = buildPool(
+ PoolTypes.DYNAMIC,
+ poolSize,
+ WorkerTypes.CLUSTER,
+ workerChoiceStrategyFairSharePoolOption
+)
const resultsFile = 'poolifier'
const resultsFolder = 'benchmarks/internal/results'
Benchmark.suite(
'Poolifier',
- Benchmark.add('Poolifier:Fixed:ThreadPool', async () => {
- await fixedThreadTest()
+ Benchmark.add('Fixed:ThreadPool:RoundRobin', async () => {
+ await runTest(fixedThreadPoolRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ThreadPoolTasksQueue', async () => {
- await fixedThreadTasksQueueTest()
- }),
- Benchmark.add('Poolifier:Fixed:ThreadPool:LessUsed', async () => {
- await fixedThreadTestLessUsed()
+ Benchmark.add(
+ 'Fixed:ThreadPool:RoundRobin:{ enableTasksQueue: true }',
+ async () => {
+ await runTest(fixedThreadPoolRoundRobinTasksQueue, {
+ taskExecutions,
+ workerData
+ })
+ }
+ ),
+ Benchmark.add('Fixed:ThreadPool:LessUsed', async () => {
+ await runTest(fixedThreadPoolLessUsed, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ThreadPool:LessBusy', async () => {
- await fixedThreadTestLessBusy()
+ Benchmark.add('Fixed:ThreadPool:LessBusy', async () => {
+ await runTest(fixedThreadPoolLessBusy, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async () => {
- await fixedThreadTestWeightedRoundRobin()
+ Benchmark.add('Fixed:ThreadPool:WeightedRoundRobin', async () => {
+ await runTest(fixedThreadPoolWeightedRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ThreadPool:FairShare', async () => {
- await fixedThreadTestFairShare()
+ Benchmark.add('Fixed:ThreadPool:FairShare', async () => {
+ await runTest(fixedThreadPoolFairShare, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ThreadPool', async () => {
- await dynamicThreadTest()
+ Benchmark.add('Dynamic:ThreadPool:RoundRobin', async () => {
+ await runTest(dynamicThreadPoolRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ThreadPool:LessUsed', async () => {
- await dynamicThreadTestLessUsed()
+ Benchmark.add('Dynamic:ThreadPool:LessUsed', async () => {
+ await runTest(dynamicThreadPoolLessUsed, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ThreadPool:LessBusy', async () => {
- await dynamicThreadTestLessBusy()
+ Benchmark.add('Dynamic:ThreadPool:LessBusy', async () => {
+ await runTest(dynamicThreadPoolLessBusy, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async () => {
- await dynamicThreadTestWeightedRoundRobin()
+ Benchmark.add('Dynamic:ThreadPool:WeightedRoundRobin', async () => {
+ await runTest(dynamicThreadPoolWeightedRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ThreadPool:FairShare', async () => {
- await dynamicThreadTestFairShare()
+ Benchmark.add('Dynamic:ThreadPool:FairShare', async () => {
+ await runTest(dynamicThreadPoolFairShare, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPool', async () => {
- await fixedClusterTest()
+ Benchmark.add('Fixed:ClusterPool:RoundRobin', async () => {
+ await runTest(fixedClusterPoolRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPoolTasksQueue', async () => {
- await fixedClusterTasksQueueTest()
+ Benchmark.add(
+ 'Fixed:ClusterPool:RoundRobin:{ enableTasksQueue: true }',
+ async () => {
+ await runTest(fixedClusterPoolRoundRobinTasksQueue, {
+ taskExecutions,
+ workerData
+ })
+ }
+ ),
+ Benchmark.add('Fixed:ClusterPool:LessUsed', async () => {
+ await runTest(fixedClusterPoolLessUsed, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPool:LessUsed', async () => {
- await fixedClusterTestLessUsed()
+ Benchmark.add('Fixed:ClusterPool:LessBusy', async () => {
+ await runTest(fixedClusterPoolLessBusy, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPool:LessBusy', async () => {
- await fixedClusterTestLessBusy()
+ Benchmark.add('Fixed:ClusterPool:WeightedRoundRobin', async () => {
+ await runTest(fixedClusterPoolWeightedRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async () => {
- await fixedClusterTestWeightedRoundRobin()
+ Benchmark.add('Fixed:ClusterPool:FairShare', async () => {
+ await runTest(fixedClusterPoolFairShare, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Fixed:ClusterPool:FairShare', async () => {
- await fixedClusterTestFairShare()
+ Benchmark.add('Dynamic:ClusterPool:RoundRobin', async () => {
+ await runTest(dynamicClusterPoolRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ClusterPool', async () => {
- await dynamicClusterTest()
+ Benchmark.add('Dynamic:ClusterPool:LessUsed', async () => {
+ await runTest(dynamicClusterPoolLessUsed, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ClusterPool:LessUsed', async () => {
- await dynamicClusterTestLessUsed()
+ Benchmark.add('Dynamic:ClusterPool:LessBusy', async () => {
+ await runTest(dynamicClusterPoolLessBusy, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add('Poolifier:Dynamic:ClusterPool:LessBusy', async () => {
- await dynamicClusterTestLessBusy()
+ Benchmark.add('Dynamic:ClusterPool:WeightedRoundRobin', async () => {
+ await runTest(dynamicClusterPoolWeightedRoundRobin, {
+ taskExecutions,
+ workerData
+ })
}),
- Benchmark.add(
- 'Poolifier:Dynamic:ClusterPool:WeightedRoundRobin',
- async () => {
- await dynamicClusterTestWeightedRoundRobin()
- }
- ),
- Benchmark.add('Poolifier:Dynamic:ClusterPool:FairShare', async () => {
- await dynamicClusterTestFairShare()
+ Benchmark.add('Dynamic:ClusterPool:FairShare', async () => {
+ await runTest(dynamicClusterPoolFairShare, {
+ taskExecutions,
+ workerData
+ })
}),
Benchmark.cycle(),
Benchmark.complete(),
'use strict'
const { isMaster } = require('cluster')
-const { ClusterWorker } = require('../../../lib/index')
-const { executeWorkerFunction } = require('../../benchmarks-utils')
-const { WorkerFunctions } = require('../../benchmarks-types')
+const { ClusterWorker } = require('../../lib')
+const { executeWorkerFunction } = require('../benchmarks-utils')
+const { WorkerFunctions } = require('../benchmarks-types')
const debug = false
+++ /dev/null
-const {
- DynamicClusterPool,
- WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const dynamicPool = new DynamicClusterPool(
- size / 2,
- size * 3,
- './benchmarks/internal/cluster/worker.js'
-)
-
-const dynamicPoolLessUsed = new DynamicClusterPool(
- size / 2,
- size * 3,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const dynamicPoolLessBusy = new DynamicClusterPool(
- size / 2,
- size * 3,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const dynamicPoolWeightedRoundRobin = new DynamicClusterPool(
- size / 2,
- size * 3,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const dynamicPoolFairShare = new DynamicClusterPool(
- size / 2,
- size * 3,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function dynamicClusterTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPool, { tasks, workerData })
-}
-
-async function dynamicClusterTestLessUsed (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData })
-}
-
-async function dynamicClusterTestLessBusy (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData })
-}
-
-async function dynamicClusterTestWeightedRoundRobin (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function dynamicClusterTestFairShare (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
- dynamicClusterTest,
- dynamicClusterTestLessUsed,
- dynamicClusterTestLessBusy,
- dynamicClusterTestWeightedRoundRobin,
- dynamicClusterTestFairShare
-}
+++ /dev/null
-const {
- FixedClusterPool,
- WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const fixedPool = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js'
-)
-
-const fixedPoolTasksQueue = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js',
- { enableTasksQueue: true }
-)
-
-const fixedPoolLessUsed = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const fixedPoolLessBusy = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const fixedPoolWeightedRoundRobin = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const fixedPoolFairShare = new FixedClusterPool(
- size,
- './benchmarks/internal/cluster/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function fixedClusterTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPool, { tasks, workerData })
-}
-
-async function fixedClusterTasksQueueTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolTasksQueue, { tasks, workerData })
-}
-
-async function fixedClusterTestLessUsed (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
-}
-
-async function fixedClusterTestLessBusy (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolLessBusy, { tasks, workerData })
-}
-
-async function fixedClusterTestWeightedRoundRobin (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function fixedClusterTestFairShare (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
- fixedClusterTest,
- fixedClusterTasksQueueTest,
- fixedClusterTestLessUsed,
- fixedClusterTestLessBusy,
- fixedClusterTestWeightedRoundRobin,
- fixedClusterTestFairShare
-}
'use strict'
const { isMainThread } = require('worker_threads')
-const { ThreadWorker } = require('../../../lib/index')
-const { executeWorkerFunction } = require('../../benchmarks-utils')
-const { WorkerFunctions } = require('../../benchmarks-types')
+const { ThreadWorker } = require('../../lib')
+const { executeWorkerFunction } = require('../benchmarks-utils')
+const { WorkerFunctions } = require('../benchmarks-types')
const debug = false
+++ /dev/null
-const {
- DynamicThreadPool,
- WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const dynamicPool = new DynamicThreadPool(
- size / 2,
- size * 3,
- './benchmarks/internal/thread/worker.js'
-)
-
-const dynamicPoolLessUsed = new DynamicThreadPool(
- size / 2,
- size * 3,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const dynamicPoolLessBusy = new DynamicThreadPool(
- size / 2,
- size * 3,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const dynamicPoolWeightedRoundRobin = new DynamicThreadPool(
- size / 2,
- size * 3,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const dynamicPoolFairShare = new DynamicThreadPool(
- size / 2,
- size * 3,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function dynamicThreadTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPool, { tasks, workerData })
-}
-
-async function dynamicThreadTestLessUsed (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData })
-}
-
-async function dynamicThreadTestLessBusy (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData })
-}
-
-async function dynamicThreadTestWeightedRoundRobin (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function dynamicThreadTestFairShare (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
- dynamicThreadTest,
- dynamicThreadTestLessUsed,
- dynamicThreadTestLessBusy,
- dynamicThreadTestWeightedRoundRobin,
- dynamicThreadTestFairShare
-}
+++ /dev/null
-const {
- FixedThreadPool,
- WorkerChoiceStrategies
-} = require('../../../lib/index')
-const { runPoolifierTest } = require('../../benchmarks-utils')
-
-const size = 30
-const numberOfTasks = 1
-
-const fixedPool = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js'
-)
-
-const fixedPoolTasksQueue = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js',
- { enableTasksQueue: true }
-)
-
-const fixedPoolLessUsed = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
-)
-
-const fixedPoolLessBusy = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
-)
-
-const fixedPoolWeightedRoundRobin = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
-)
-
-const fixedPoolFairShare = new FixedThreadPool(
- size,
- './benchmarks/internal/thread/worker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
-)
-
-async function fixedThreadTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPool, { tasks, workerData })
-}
-
-async function fixedThreadTasksQueueTest (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolTasksQueue, { tasks, workerData })
-}
-
-async function fixedThreadTestLessUsed (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
-}
-
-async function fixedThreadTestLessBusy (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolLessBusy, { tasks, workerData })
-}
-
-async function fixedThreadTestWeightedRoundRobin (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
-}
-
-async function fixedThreadTestFairShare (
- { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
-) {
- return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
-}
-
-module.exports = {
- fixedThreadTest,
- fixedThreadTasksQueueTest,
- fixedThreadTestLessUsed,
- fixedThreadTestLessBusy,
- fixedThreadTestWeightedRoundRobin,
- fixedThreadTestFairShare
-}
FixedThreadPool,
PoolEvents,
WorkerChoiceStrategies
-} = require('../../../lib/index')
+} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')
describe('Abstract pool test suite', () => {
const { expect } = require('expect')
-const { DynamicClusterPool, PoolEvents } = require('../../../lib/index')
+const { DynamicClusterPool, PoolEvents } = require('../../../lib')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { expect } = require('expect')
-const { FixedClusterPool, PoolEvents } = require('../../../lib/index')
+const { FixedClusterPool, PoolEvents } = require('../../../lib')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
DynamicThreadPool,
FixedThreadPool,
FixedClusterPool
-} = require('../../../lib/index')
+} = require('../../../lib')
describe('Selection strategies test suite', () => {
const min = 0
const { expect } = require('expect')
const sinon = require('sinon')
-const { FixedThreadPool } = require('../../../lib/index')
+const { FixedThreadPool } = require('../../../lib')
const {
WeightedRoundRobinWorkerChoiceStrategy
} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
FixedThreadPool,
DynamicThreadPool,
WorkerChoiceStrategies
-} = require('../../../lib/index')
+} = require('../../../lib')
const {
WorkerChoiceStrategyContext
} = require('../../../lib/pools/selection-strategies/worker-choice-strategy-context')
const { expect } = require('expect')
-const { DynamicThreadPool, PoolEvents } = require('../../../lib/index')
+const { DynamicThreadPool, PoolEvents } = require('../../../lib')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
const { expect } = require('expect')
-const { FixedThreadPool, PoolEvents } = require('../../../lib/index')
+const { FixedThreadPool, PoolEvents } = require('../../../lib')
const { WorkerFunctions } = require('../../test-types')
const TestUtils = require('../../test-utils')
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function error (data) {
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
function echo (data) {
return data
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
function test () {}
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
function error () {
throw new Error('Error Message from ClusterWorker')
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ClusterWorker } = require('../../../lib/index')
+const { ClusterWorker } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ClusterWorker, KillBehaviors } = require('../../../lib/index')
+const { ClusterWorker, KillBehaviors } = require('../../../lib')
const { isMaster } = require('cluster')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function error (data) {
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
function echo (data) {
return data
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
function test () {}
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
function error () {
throw new Error('Error Message from ThreadWorker')
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ThreadWorker } = require('../../../lib/index')
+const { ThreadWorker } = require('../../../lib')
const TestUtils = require('../../test-utils')
async function sleep (data) {
'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib/index')
+const { ThreadWorker, KillBehaviors } = require('../../../lib')
const { isMainThread } = require('worker_threads')
const TestUtils = require('../../test-utils')
const { WorkerFunctions } = require('../../test-types')