dynamicClusterTest,
dynamicClusterTestLessRecentlyUsed
} = require('./cluster/dynamic')
-const { fixedClusterTest } = require('./cluster/fixed')
+const {
+ fixedClusterTest,
+ fixedClusterTestLessRecentlyUsed
+} = require('./cluster/fixed')
const {
dynamicThreadTest,
dynamicThreadTestLessRecentlyUsed
} = require('./thread/dynamic')
-const { fixedThreadTest } = require('./thread/fixed')
+const {
+ fixedThreadTest,
+ fixedThreadTestLessRecentlyUsed
+} = require('./thread/fixed')
+const { LIST_FORMATTER } = require('./benchmark-utils')
const suite = new Benchmark.Suite('poolifier')
-const LIST_FORMATTER = new Intl.ListFormat('en-US', {
- style: 'long',
- type: 'conjunction'
-})
-
// Wait some seconds before start, pools need to load threads !!!
setTimeout(async () => {
test()
async function test () {
// Add tests
suite
- .add('Poolifier:Static:ThreadPool', async function () {
+ .add('Poolifier:Fixed:ThreadPool', async function () {
await fixedThreadTest()
})
+ .add('Poolifier:Fixed:ThreadPool:LessRecentlyUsed', async function () {
+ await fixedThreadTestLessRecentlyUsed()
+ })
.add('Poolifier:Dynamic:ThreadPool', async function () {
await dynamicThreadTest()
})
.add('Poolifier:Dynamic:ThreadPool:LessRecentlyUsed', async function () {
await dynamicThreadTestLessRecentlyUsed()
})
- .add('Poolifier:Static:ClusterPool', async function () {
+ .add('Poolifier:Fixed:ClusterPool', async function () {
await fixedClusterTest()
})
+ .add('Poolifier:Fixed:ClusterPool:LessRecentlyUsed', async function () {
+ await fixedClusterTestLessRecentlyUsed()
+ })
.add('Poolifier:Dynamic:ClusterPool', async function () {
await dynamicClusterTest()
})
// eslint-disable-next-line no-process-exit
process.exit()
})
- .run({ async: true, queued: true })
+ .run({ async: true })
}
async function runPoolifierTest (pool, { tasks, workerData }) {
return new Promise((resolve, reject) => {
let executions = 0
- for (let i = 0; i <= tasks; i++) {
+ for (let i = 1; i <= tasks; i++) {
pool
.execute(workerData)
.then(res => {
return Math.floor(Math.random() * max + 1)
}
-module.exports = { runPoolifierTest, generateRandomInteger }
+const LIST_FORMATTER = new Intl.ListFormat('en-US', {
+ style: 'long',
+ type: 'conjunction'
+})
+
+module.exports = { generateRandomInteger, LIST_FORMATTER, runPoolifierTest }
const Benchmark = require('benchmark')
+const { LIST_FORMATTER } = require('./benchmark-utils')
const suite = new Benchmark.Suite()
-const LIST_FORMATTER = new Intl.ListFormat('en-US', {
- style: 'long',
- type: 'conjunction'
-})
+function generateWorkersArray (numberOfWorkers) {
+ return [...Array(numberOfWorkers).keys()]
+}
-const workers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+const workers = generateWorkersArray(60)
let nextWorkerIndex = 0
-const { FixedClusterPool } = require('../../../lib/index')
+const {
+ FixedClusterPool,
+ WorkerChoiceStrategies
+} = require('../../../lib/index')
const { runPoolifierTest } = require('../benchmark-utils')
const size = 30
'./benchmarks/internal/cluster/worker.js'
)
+const fixedPoolLessRecentlyUsed = new FixedClusterPool(
+ size,
+ './benchmarks/internal/cluster/worker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+)
+
async function fixedClusterTest (
{ tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
) {
return runPoolifierTest(fixedPool, { tasks, workerData })
}
-module.exports = { fixedClusterTest }
+async function fixedClusterTestLessRecentlyUsed (
+ { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
+) {
+ return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData })
+}
+
+module.exports = { fixedClusterTest, fixedClusterTestLessRecentlyUsed }
const Benchmark = require('benchmark')
-const { generateRandomInteger } = require('./benchmark-utils')
+const { generateRandomInteger, LIST_FORMATTER } = require('./benchmark-utils')
const suite = new Benchmark.Suite()
-const LIST_FORMATTER = new Intl.ListFormat('en-US', {
- style: 'long',
- type: 'conjunction'
-})
-
-const tasksMap = new Map([
- [0, generateRandomInteger(10)],
- [1, generateRandomInteger(10)],
- [2, generateRandomInteger(10)],
- [3, generateRandomInteger(10)],
- [4, generateRandomInteger(10)],
- [5, generateRandomInteger(10)],
- [6, generateRandomInteger(10)],
- [7, generateRandomInteger(10)],
- [8, generateRandomInteger(10)],
- [9, generateRandomInteger(10)],
- [10, generateRandomInteger(10)],
- [11, generateRandomInteger(10)],
- [12, generateRandomInteger(10)],
- [13, generateRandomInteger(10)],
- [14, generateRandomInteger(10)],
- [15, generateRandomInteger(10)],
- [16, generateRandomInteger(10)],
- [17, generateRandomInteger(10)],
- [18, generateRandomInteger(10)],
- [19, generateRandomInteger(10)],
- [20, generateRandomInteger(10)],
- [21, generateRandomInteger(10)],
- [22, generateRandomInteger(10)],
- [23, generateRandomInteger(10)],
- [24, generateRandomInteger(10)],
- [25, generateRandomInteger(10)],
- [26, generateRandomInteger(10)],
- [27, generateRandomInteger(10)],
- [28, generateRandomInteger(10)],
- [29, generateRandomInteger(10)]
-])
+function generateRandomTasksMap (
+ numberOfWorkers,
+ maxNumberOfTasksPerWorker = 10
+) {
+ const tasksArray = []
+ for (let i = 0; i < numberOfWorkers; i++) {
+ const task = [i, generateRandomInteger(maxNumberOfTasksPerWorker)]
+ tasksArray.push(task)
+ }
+ return new Map(tasksArray)
+}
+
+const tasksMap = generateRandomTasksMap(60, 20)
function loopSelect (tasksMap) {
let minValue = Infinity
return leftIndex + Math.floor((rightIndex - leftIndex) / 2)
}
+const randomPivotIndexSelect = (leftIndex, rightIndex) => {
+ return generateRandomInteger(leftIndex, rightIndex)
+}
+
function swap (array, index1, index2) {
const tmp = array[index1]
array[index1] = array[index2]
const pivotValue = array[pivotIndex]
swap(array, pivotIndex, rightIndex)
let storeIndex = leftIndex
- for (let i = leftIndex; i < rightIndex; i += 1) {
+ for (let i = leftIndex; i < rightIndex; i++) {
if (compare(array[i], pivotValue)) {
swap(array, storeIndex, i)
- storeIndex += 1
+ storeIndex++
}
}
swap(array, rightIndex, storeIndex)
(a, b) => {
return a[1] < b[1]
},
- (leftIndex, rightIndex) => {
- return generateRandomInteger(leftIndex, rightIndex)
- }
+ randomPivotIndexSelect
)
}
(a, b) => {
return a[1] < b[1]
},
- (leftIndex, rightIndex) => {
- return generateRandomInteger(leftIndex, rightIndex)
- }
+ randomPivotIndexSelect
)
}
-const { FixedThreadPool } = require('../../../lib/index')
+const {
+ FixedThreadPool,
+ WorkerChoiceStrategies
+} = require('../../../lib/index')
const { runPoolifierTest } = require('../benchmark-utils')
const size = 30
'./benchmarks/internal/thread/worker.js'
)
+const fixedPoolLessRecentlyUsed = new FixedThreadPool(
+ size,
+ './benchmarks/internal/thread/worker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+)
+
async function fixedThreadTest (
{ tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
) {
return runPoolifierTest(fixedPool, { tasks, workerData })
}
-module.exports = { fixedThreadTest }
+async function fixedThreadTestLessRecentlyUsed (
+ { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
+) {
+ return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData })
+}
+
+module.exports = { fixedThreadTest, fixedThreadTestLessRecentlyUsed }
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
},
- "benchmark": {
- "version": "2.1.4",
- "resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz",
- "integrity": "sha1-CfPeMckWQl1JjMLuVloOvzwqVik=",
- "requires": {
- "lodash": "^4.17.4",
- "platform": "^1.3.3"
- }
- },
"callsites": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz",
"resolved": "https://registry.npmjs.org/eventemitter-asyncresource/-/eventemitter-asyncresource-1.0.0.tgz",
"integrity": "sha512-39F7TBIV0G7gTelxwbEqnwhp90eqCPON1k0NwNfwhgKn4Co4ybUbj2pECcXT0B3ztRKZ7Pw1JujUUgmQJHcVAQ=="
},
+ "find-up": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz",
+ "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==",
+ "requires": {
+ "locate-path": "^6.0.0",
+ "path-exists": "^4.0.0"
+ }
+ },
"hdr-histogram-js": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/hdr-histogram-js/-/hdr-histogram-js-2.0.1.tgz",
"symbol-observable": "^1.1.0"
}
},
- "lodash": {
- "version": "4.17.21",
- "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
- "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
+ "locate-path": {
+ "version": "6.0.0",
+ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz",
+ "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==",
+ "requires": {
+ "p-locate": "^5.0.0"
+ }
},
"microjob": {
"version": "0.7.0",
"wrappy": "1"
}
},
+ "p-limit": {
+ "version": "3.1.0",
+ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
+ "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==",
+ "requires": {
+ "yocto-queue": "^0.1.0"
+ }
+ },
+ "p-locate": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz",
+ "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==",
+ "requires": {
+ "p-limit": "^3.0.2"
+ }
+ },
"pako": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
"integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
},
+ "path-exists": {
+ "version": "4.0.0",
+ "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz",
+ "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w=="
+ },
"piscina": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/piscina/-/piscina-2.2.0.tgz",
"nice-napi": "^1.0.2"
}
},
- "platform": {
- "version": "1.3.6",
- "resolved": "https://registry.npmjs.org/platform/-/platform-1.3.6.tgz",
- "integrity": "sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg=="
+ "pkg-dir": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-5.0.0.tgz",
+ "integrity": "sha512-NPE8TDbzl/3YQYY7CSS228s3g2ollTFnc+Qi3tqmqJp9Vg2ovUpixcJEo2HJScN2Ez+kEaal6y70c0ehqJBJeA==",
+ "requires": {
+ "find-up": "^5.0.0"
+ }
},
"poolifier": {
"version": "2.0.0",
"tiny-worker": ">= 2"
}
},
+ "threadwork": {
+ "version": "0.6.0",
+ "resolved": "https://registry.npmjs.org/threadwork/-/threadwork-0.6.0.tgz",
+ "integrity": "sha512-NzKDArTtcSAq0jlMdiC04+fuls5nWn1ziptmMTBwPyjKxZk+aQvw/LVVf3IW3tUKz4vLGJ2XE+PXDMoJuoNEfQ==",
+ "requires": {
+ "callsites": "^3.1.0",
+ "pkg-dir": "^5.0.0"
+ }
+ },
"tiny-worker": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/tiny-worker/-/tiny-worker-2.3.0.tgz",
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
+ },
+ "yocto-queue": {
+ "version": "0.1.0",
+ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
+ "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
}
}
}
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
- "benchmark": "^2.1.4",
"microjob": "0.7.0",
"node-worker-threads-pool": "1.4.3",
"piscina": "2.2.0",
"poolifier": "2.0.0",
"threads": "1.6.3",
+ "threadwork": "0.6.0",
"worker-threads-pool": "2.0.0",
"workerpool": "6.1.0"
}
const start = Date.now()
const iterations = 1000
-for (let i = 0; i <= iterations; i++) {
+for (let i = 1; i <= iterations; i++) {
pool
.execute({})
.then(res => {
const start = Date.now()
const iterations = 1000
-for (let i = 0; i <= iterations; i++) {
+for (let i = 1; i <= iterations; i++) {
pool
.execute({})
.then(res => {
}
},
"@babel/compat-data": {
- "version": "7.13.6",
- "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.13.6.tgz",
- "integrity": "sha512-VhgqKOWYVm7lQXlvbJnWOzwfAQATd2nV52koT0HZ/LdDH0m4DUDwkKYsH+IwpXb+bKPyBJzawA4I6nBKqZcpQw==",
+ "version": "7.13.8",
+ "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.13.8.tgz",
+ "integrity": "sha512-EaI33z19T4qN3xLXsGf48M2cDqa6ei9tPZlfLdb2HC+e/cFtREiRd8hdSqDbwdLB0/+gLwqJmCYASH0z2bUdog==",
"dev": true
},
"@babel/core": {
- "version": "7.13.1",
- "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.13.1.tgz",
- "integrity": "sha512-FzeKfFBG2rmFtGiiMdXZPFt/5R5DXubVi82uYhjGX4Msf+pgYQMCFIqFXZWs5vbIYbf14VeBIgdGI03CDOOM1w==",
+ "version": "7.13.8",
+ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.13.8.tgz",
+ "integrity": "sha512-oYapIySGw1zGhEFRd6lzWNLWFX2s5dA/jm+Pw/+59ZdXtjyIuwlXbrId22Md0rgZVop+aVoqow2riXhBLNyuQg==",
"dev": true,
"requires": {
"@babel/code-frame": "^7.12.13",
"@babel/generator": "^7.13.0",
- "@babel/helper-compilation-targets": "^7.13.0",
+ "@babel/helper-compilation-targets": "^7.13.8",
"@babel/helper-module-transforms": "^7.13.0",
"@babel/helpers": "^7.13.0",
- "@babel/parser": "^7.13.0",
+ "@babel/parser": "^7.13.4",
"@babel/template": "^7.12.13",
"@babel/traverse": "^7.13.0",
"@babel/types": "^7.13.0",
"gensync": "^1.0.0-beta.2",
"json5": "^2.1.2",
"lodash": "^4.17.19",
- "semver": "7.0.0",
+ "semver": "^6.3.0",
"source-map": "^0.5.0"
},
"dependencies": {
}
},
"@babel/parser": {
- "version": "7.13.4",
- "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.4.tgz",
- "integrity": "sha512-uvoOulWHhI+0+1f9L4BoozY7U5cIkZ9PgJqvb041d6vypgUmtVPG4vmGm4pSggjl8BELzvHyUeJSUyEMY6b+qA==",
+ "version": "7.13.9",
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.9.tgz",
+ "integrity": "sha512-nEUfRiARCcaVo3ny3ZQjURjHQZUo/JkEw7rLlSZy/psWGnvwXFtPcr6jb7Yb41DVW5LTe6KRq9LGleRNsg1Frw==",
"dev": true
},
"json5": {
}
},
"semver": {
- "version": "7.0.0",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz",
- "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==",
+ "version": "6.3.0",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
},
"source-map": {
}
},
"@babel/generator": {
- "version": "7.13.0",
- "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.13.0.tgz",
- "integrity": "sha512-zBZfgvBB/ywjx0Rgc2+BwoH/3H+lDtlgD4hBOpEv5LxRnYsm/753iRuLepqnYlynpjC3AdQxtxsoeHJoEEwOAw==",
+ "version": "7.13.9",
+ "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.13.9.tgz",
+ "integrity": "sha512-mHOOmY0Axl/JCTkxTU6Lf5sWOg/v8nUa+Xkt4zMTftX0wqmb6Sh7J8gvcehBw7q0AhrhAR+FDacKjCZ2X8K+Sw==",
"dev": true,
"requires": {
"@babel/types": "^7.13.0",
}
},
"@babel/helper-compilation-targets": {
- "version": "7.13.0",
- "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.13.0.tgz",
- "integrity": "sha512-SOWD0JK9+MMIhTQiUVd4ng8f3NXhPVQvTv7D3UN4wbp/6cAHnB2EmMaU1zZA2Hh1gwme+THBrVSqTFxHczTh0Q==",
+ "version": "7.13.8",
+ "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.13.8.tgz",
+ "integrity": "sha512-pBljUGC1y3xKLn1nrx2eAhurLMA8OqBtBP/JwG4U8skN7kf8/aqwwxpV1N6T0e7r6+7uNitIa/fUxPFagSXp3A==",
"dev": true,
"requires": {
- "@babel/compat-data": "^7.13.0",
+ "@babel/compat-data": "^7.13.8",
"@babel/helper-validator-option": "^7.12.17",
"browserslist": "^4.14.5",
- "semver": "7.0.0"
+ "semver": "^6.3.0"
},
"dependencies": {
"semver": {
- "version": "7.0.0",
- "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz",
- "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==",
+ "version": "6.3.0",
+ "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
+ "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
}
}
}
},
"@babel/highlight": {
- "version": "7.12.13",
- "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.12.13.tgz",
- "integrity": "sha512-kocDQvIbgMKlWxXe9fof3TQ+gkIPOUSEYhJjqUjvKMez3krV7vbzYCDq39Oj11UAVK7JqPVGQPlgE85dPNlQww==",
+ "version": "7.13.8",
+ "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.13.8.tgz",
+ "integrity": "sha512-4vrIhfJyfNf+lCtXC2ck1rKSzDwciqF7IWFhXXrSOUC2O5DrVp+w4c6ed4AllTxhTkUP5x2tYj41VaxdVMMRDw==",
"dev": true,
"requires": {
"@babel/helper-validator-identifier": "^7.12.11",
}
},
"@babel/parser": {
- "version": "7.13.4",
- "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.4.tgz",
- "integrity": "sha512-uvoOulWHhI+0+1f9L4BoozY7U5cIkZ9PgJqvb041d6vypgUmtVPG4vmGm4pSggjl8BELzvHyUeJSUyEMY6b+qA==",
+ "version": "7.13.9",
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.9.tgz",
+ "integrity": "sha512-nEUfRiARCcaVo3ny3ZQjURjHQZUo/JkEw7rLlSZy/psWGnvwXFtPcr6jb7Yb41DVW5LTe6KRq9LGleRNsg1Frw==",
"dev": true
}
}
}
},
"@babel/parser": {
- "version": "7.13.4",
- "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.4.tgz",
- "integrity": "sha512-uvoOulWHhI+0+1f9L4BoozY7U5cIkZ9PgJqvb041d6vypgUmtVPG4vmGm4pSggjl8BELzvHyUeJSUyEMY6b+qA==",
+ "version": "7.13.9",
+ "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.13.9.tgz",
+ "integrity": "sha512-nEUfRiARCcaVo3ny3ZQjURjHQZUo/JkEw7rLlSZy/psWGnvwXFtPcr6jb7Yb41DVW5LTe6KRq9LGleRNsg1Frw==",
"dev": true
},
"globals": {
"dev": true
},
"caniuse-lite": {
- "version": "1.0.30001191",
- "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001191.tgz",
- "integrity": "sha512-xJJqzyd+7GCJXkcoBiQ1GuxEiOBCLQ0aVW9HMekifZsAVGdj5eJ4mFB9fEhSHipq9IOk/QXFJUiIr9lZT+EsGw==",
+ "version": "1.0.30001196",
+ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001196.tgz",
+ "integrity": "sha512-CPvObjD3ovWrNBaXlAIGWmg2gQQuJ5YhuciUOjPRox6hIQttu8O+b51dx6VIpIY9ESd2d0Vac1RKpICdG4rGUg==",
"dev": true
},
"chalk": {
"dev": true
},
"colorette": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.1.tgz",
- "integrity": "sha512-puCDz0CzydiSYOrnXpz/PKd69zRrribezjtE9yd4zvytoRc8+RY/KJPvtPFKZS3E3wP6neGyMe0vOTlHO5L3Pw==",
+ "version": "1.2.2",
+ "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.2.2.tgz",
+ "integrity": "sha512-MKGMzyfeuutC/ZJ1cba9NqcNpfeqMUcYmyF1ZFY6/Cn7CNSAKx6a+s48sqLqyAiZuaP2TcqMhoo+dlwFnVxT9w==",
"dev": true
},
"colors": {
"dev": true
},
"electron-to-chromium": {
- "version": "1.3.673",
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.673.tgz",
- "integrity": "sha512-ms+QR2ckfrrpEAjXweLx6kNCbpAl66DcW//3BZD4BV5KhUgr0RZRce1ON/9J3QyA3JO28nzgb5Xv8DnPr05ILg==",
+ "version": "1.3.682",
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.682.tgz",
+ "integrity": "sha512-zok2y37qR00U14uM6qBz/3iIjWHom2eRfC2S1StA0RslP7x34jX+j4mxv80t8OEOHLJPVG54ZPeaFxEI7gPrwg==",
"dev": true
},
"emoji-regex": {
}
},
"es-abstract": {
- "version": "1.18.0-next.2",
- "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0-next.2.tgz",
- "integrity": "sha512-Ih4ZMFHEtZupnUh6497zEL4y2+w8+1ljnCyaTa+adcoafI1GOvMwFlDjBLfWR7y9VLfrjRJe9ocuHY1PSR9jjw==",
+ "version": "1.18.0",
+ "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.18.0.tgz",
+ "integrity": "sha512-LJzK7MrQa8TS0ja2w3YNLzUgJCGPdPOV1yVvezjNnS89D+VR08+Szt2mz3YB2Dck/+w5tfIq/RoUAFqJJGM2yw==",
"dev": true,
"requires": {
"call-bind": "^1.0.2",
"es-to-primitive": "^1.2.1",
"function-bind": "^1.1.1",
- "get-intrinsic": "^1.0.2",
+ "get-intrinsic": "^1.1.1",
"has": "^1.0.3",
- "has-symbols": "^1.0.1",
- "is-callable": "^1.2.2",
+ "has-symbols": "^1.0.2",
+ "is-callable": "^1.2.3",
"is-negative-zero": "^2.0.1",
- "is-regex": "^1.1.1",
+ "is-regex": "^1.1.2",
+ "is-string": "^1.0.5",
"object-inspect": "^1.9.0",
"object-keys": "^1.1.1",
"object.assign": "^4.1.2",
- "string.prototype.trimend": "^1.0.3",
- "string.prototype.trimstart": "^1.0.3"
+ "string.prototype.trimend": "^1.0.4",
+ "string.prototype.trimstart": "^1.0.4",
+ "unbox-primitive": "^1.0.0"
}
},
"es-to-primitive": {
}
},
"glob-parent": {
- "version": "5.1.1",
- "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
- "integrity": "sha512-FnI+VGOpnlGHWZxthPGR+QhR78fuiK0sNLkHQv+bL9fQi57lNNdquIbna/WrfROrolq8GK5Ek6BiMwqL/voRYQ==",
+ "version": "5.1.2",
+ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz",
+ "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==",
"dev": true,
"requires": {
"is-glob": "^4.0.1"
"function-bind": "^1.1.1"
}
},
+ "has-bigints": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.1.tgz",
+ "integrity": "sha512-LSBS2LjbNBTf6287JEbEzvJgftkF5qFkmCo9hDRpAzKhUOlJ+hx8dd4USs00SgsUNwc4617J9ki5YtEClM2ffA==",
+ "dev": true
+ },
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"dev": true
},
"has-symbols": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz",
- "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==",
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz",
+ "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==",
"dev": true
},
"hasha": {
"integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=",
"dev": true
},
+ "is-bigint": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.1.tgz",
+ "integrity": "sha512-J0ELF4yHFxHy0cmSxZuheDOz2luOdVvqjwmEcj8H/L1JHeuEDSDbeRP+Dk9kFVk5RTFzbucJ2Kb9F7ixY2QaCg==",
+ "dev": true
+ },
"is-binary-path": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz",
"binary-extensions": "^2.0.0"
}
},
+ "is-boolean-object": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.0.tgz",
+ "integrity": "sha512-a7Uprx8UtD+HWdyYwnD1+ExtTgqQtD2k/1yJgtXP6wnMm8byhkoTZRl+95LLThpzNZJ5aEvi46cdH+ayMFRwmA==",
+ "dev": true,
+ "requires": {
+ "call-bind": "^1.0.0"
+ }
+ },
"is-buffer": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz",
"integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
"dev": true
},
+ "is-number-object": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.4.tgz",
+ "integrity": "sha512-zohwelOAur+5uXtk8O3GPQ1eAcu4ZX3UwxQhUlfFFMNpUd83gXgjbhJh6HmB6LUNV/ieOLQuDwJO3dWJosUeMw==",
+ "dev": true
+ },
"is-path-cwd": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-path-cwd/-/is-path-cwd-2.2.0.tgz",
"is-core-module": "^2.1.0",
"path-parse": "^1.0.6"
}
+ },
+ "string-width": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
+ "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==",
+ "dev": true,
+ "requires": {
+ "emoji-regex": "^8.0.0",
+ "is-fullwidth-code-point": "^3.0.0",
+ "strip-ansi": "^6.0.0"
+ }
}
}
},
"dev": true
},
"string-width": {
- "version": "4.2.0",
- "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
- "integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==",
+ "version": "4.2.2",
+ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.2.tgz",
+ "integrity": "sha512-XBJbT3N4JhVumXE0eoLU9DCjcaF92KLNqTmFCnG1pf8duUxFGwtP6AD6nkjw9a3IdiRtL3E2w3JDiE/xi3vOeA==",
"dev": true,
"requires": {
"emoji-regex": "^8.0.0",
},
"dependencies": {
"ajv": {
- "version": "7.1.1",
- "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.1.1.tgz",
- "integrity": "sha512-ga/aqDYnUy/o7vbsRTFhhTsNeXiYb5JWDIcRIeZfwRNCefwjNTVYCGdGSUrEmiu3yDK3vFvNbgJxvrQW4JXrYQ==",
+ "version": "7.2.0",
+ "resolved": "https://registry.npmjs.org/ajv/-/ajv-7.2.0.tgz",
+ "integrity": "sha512-51Na3IUg3uOACsQ7hzTUCjSzGy8xROySgI8tmNJ+y9JF2hfDS6qkTP7+Ep3htUtSQG1t17QMbe+jZFTlaU4dDQ==",
"dev": true,
"requires": {
"fast-deep-equal": "^3.1.1",
"dev": true
},
"uglify-js": {
- "version": "3.12.8",
- "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.12.8.tgz",
- "integrity": "sha512-fvBeuXOsvqjecUtF/l1dwsrrf5y2BCUk9AOJGzGcm6tE7vegku5u/YvqjyDaAGr422PLoLnrxg3EnRvTqsdC1w==",
+ "version": "3.13.0",
+ "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.0.tgz",
+ "integrity": "sha512-TWYSWa9T2pPN4DIJYbU9oAjQx+5qdV5RUDxwARg8fmJZrD/V27Zj0JngW5xg1DFz42G0uDYl2XhzF6alSzD62w==",
"dev": true,
"optional": true
},
+ "unbox-primitive": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.0.tgz",
+ "integrity": "sha512-P/51NX+JXyxK/aigg1/ZgyccdAxm5K1+n8+tvqSntjOivPt19gvm1VC49RWYetsiub8WViUchdxl/KWHHB0kzA==",
+ "dev": true,
+ "requires": {
+ "function-bind": "^1.1.1",
+ "has-bigints": "^1.0.0",
+ "has-symbols": "^1.0.0",
+ "which-boxed-primitive": "^1.0.1"
+ }
+ },
"unherit": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/unherit/-/unherit-1.1.3.tgz",
"dev": true
},
"v8-compile-cache": {
- "version": "2.2.0",
- "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz",
- "integrity": "sha512-gTpR5XQNKFwOd4clxfnhaqvfqMpqEwr4tOtCyz4MtYZX2JYhfr1JvBFKdS+7K/9rfpZR3VLX+YWBbKoxCgS43Q==",
+ "version": "2.3.0",
+ "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz",
+ "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==",
"dev": true
},
"validate-npm-package-license": {
"isexe": "^2.0.0"
}
},
+ "which-boxed-primitive": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz",
+ "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==",
+ "dev": true,
+ "requires": {
+ "is-bigint": "^1.0.1",
+ "is-boolean-object": "^1.1.0",
+ "is-number-object": "^1.0.4",
+ "is-string": "^1.0.5",
+ "is-symbol": "^1.0.3"
+ }
+ },
"which-module": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz",
})
it('Verify that filePath is checked', () => {
+ const expectedError = new Error(
+ 'Please specify a file with a worker implementation'
+ )
expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError(
- new Error('Please specify a file with a worker implementation')
+ expectedError
)
expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
- new Error('Please specify a file with a worker implementation')
+ expectedError
)
})
const longRunningPool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/longRunningWorkerHardBehavior.js'
+ './tests/worker-files/cluster/longRunningWorkerHardBehavior.js',
+ {
+ errorHandler: e => console.error(e),
+ onlineHandler: () => console.log('long running worker is online'),
+ exitHandler: () => console.log('long running worker exited')
+ }
)
expect(longRunningPool.workers.length).toBe(min)
for (let i = 0; i < max * 10; i++) {
const longRunningPool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js'
+ './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js',
+ {
+ errorHandler: e => console.error(e),
+ onlineHandler: () => console.log('long running worker is online'),
+ exitHandler: () => console.log('long running worker exited')
+ }
)
expect(longRunningPool.workers.length).toBe(min)
for (let i = 0; i < max * 10; i++) {
1,
'./tests/worker-files/cluster/asyncErrorWorker.js',
{
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const asyncPool = new FixedClusterPool(
'./tests/worker-files/thread/longRunningWorkerHardBehavior.js',
{
errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ onlineHandler: () => console.log('long running worker is online'),
+ exitHandler: () => console.log('long running worker exited')
}
)
expect(longRunningPool.workers.length).toBe(min)
'./tests/worker-files/thread/longRunningWorkerSoftBehavior.js',
{
errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ onlineHandler: () => console.log('long running worker is online'),
+ exitHandler: () => console.log('long running worker exited')
}
)
expect(longRunningPool.workers.length).toBe(min)
1,
'./tests/worker-files/thread/errorWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const asyncErrorPool = new FixedThreadPool(
1,
'./tests/worker-files/thread/asyncErrorWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const asyncPool = new FixedThreadPool(
)
})
- it('Verify that handle Error function is working properly', () => {
+ it('Verify that handleError function is working properly', () => {
const error = new Error('My error')
const worker = new ThreadWorker(() => {})
expect(worker.handleError(error)).toBe(error)
it('Verify that get main worker throw error if main worker is not set', () => {
expect(() =>
new StubPoolWithIsMainWorker(() => {}).getMainWorker()
- ).toThrowError()
+ ).toThrowError(new Error('Main worker was not set'))
})
})