repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge dependabot/npm_and_yarn/examples/typescript/smtp-client-pool/poolifier-3.0...
[poolifier.git]
/
benchmarks
/
benchmarks-utils.js
diff --git
a/benchmarks/benchmarks-utils.js
b/benchmarks/benchmarks-utils.js
index aaf7521ff3044807e02078c2cde0f45c584586b1..a0a42b95d06642cbb8e7aeb282c06e7f20720b16 100644
(file)
--- a/
benchmarks/benchmarks-utils.js
+++ b/
benchmarks/benchmarks-utils.js
@@
-1,6
+1,12
@@
-const crypto = require('node:crypto')
-const assert = require('node:assert')
-const fs = require('node:fs')
+const { randomInt } = require('node:crypto')
+const { strictEqual } = require('node:assert')
+const {
+ existsSync,
+ mkdirSync,
+ readFileSync,
+ rmSync,
+ writeFileSync
+} = require('node:fs')
const Benchmark = require('benchmark')
const {
DynamicClusterPool,
const Benchmark = require('benchmark')
const {
DynamicClusterPool,
@@
-64,7
+70,7
@@
const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
if (executions === taskExecutions) {
resolve({ ok: 1 })
}
if (executions === taskExecutions) {
resolve({ ok: 1 })
}
- return
null
+ return
undefined
})
.catch(err => {
console.error(err)
})
.catch(err => {
console.error(err)
@@
-76,12
+82,15
@@
const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
const runPoolifierPoolBenchmark = async (
name,
const runPoolifierPoolBenchmark = async (
name,
- pool,
+ workerType,
+ poolType,
+ poolSize,
{ taskExecutions, workerData }
) => {
return await new Promise((resolve, reject) => {
{ taskExecutions, workerData }
) => {
return await new Promise((resolve, reject) => {
+ const pool = buildPoolifierPool(workerType, poolType, poolSize)
+ const suite = new Benchmark.Suite(name)
try {
try {
- const suite = new Benchmark.Suite(name)
for (const workerChoiceStrategy of Object.values(
WorkerChoiceStrategies
)) {
for (const workerChoiceStrategy of Object.values(
WorkerChoiceStrategies
)) {
@@
-100,15
+109,12
@@
const runPoolifierPoolBenchmark = async (
measurement
})
pool.enableTasksQueue(enableTasksQueue)
measurement
})
pool.enableTasksQueue(enableTasksQueue)
-
assert.
strictEqual(
+ strictEqual(
pool.opts.workerChoiceStrategy,
workerChoiceStrategy
)
pool.opts.workerChoiceStrategy,
workerChoiceStrategy
)
- assert.strictEqual(
- pool.opts.enableTasksQueue,
- enableTasksQueue
- )
- assert.strictEqual(
+ strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
+ strictEqual(
pool.opts.workerChoiceStrategyOptions.measurement,
measurement
)
pool.opts.workerChoiceStrategyOptions.measurement,
measurement
)
@@
-127,11
+133,11
@@
const runPoolifierPoolBenchmark = async (
async () => {
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
pool.enableTasksQueue(enableTasksQueue)
async () => {
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
pool.enableTasksQueue(enableTasksQueue)
-
assert.
strictEqual(
+ strictEqual(
pool.opts.workerChoiceStrategy,
workerChoiceStrategy
)
pool.opts.workerChoiceStrategy,
workerChoiceStrategy
)
-
assert.
strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
+ strictEqual(pool.opts.enableTasksQueue, enableTasksQueue)
await runPoolifierPool(pool, {
taskExecutions,
workerData
await runPoolifierPool(pool, {
taskExecutions,
workerData
@@
-145,17
+151,32
@@
const runPoolifierPoolBenchmark = async (
.on('cycle', event => {
console.info(event.target.toString())
})
.on('cycle', event => {
console.info(event.target.toString())
})
- .on('complete',
async
function () {
+ .on('complete', function () {
console.info(
'Fastest is ' +
LIST_FORMATTER.format(this.filter('fastest').map('name'))
)
console.info(
'Fastest is ' +
LIST_FORMATTER.format(this.filter('fastest').map('name'))
)
- await pool.destroy()
- resolve()
+ const destroyTimeout = setTimeout(() => {
+ console.error('Pool destroy timeout reached (30s)')
+ resolve()
+ }, 30000)
+ pool
+ .destroy()
+ .then(resolve)
+ .catch(reject)
+ .finally(() => {
+ clearTimeout(destroyTimeout)
+ })
+ .catch(() => {})
})
.run({ async: true })
} catch (error) {
})
.run({ async: true })
} catch (error) {
- reject(error)
+ pool
+ .destroy()
+ .then(() => {
+ return reject(error)
+ })
+ .catch(() => {})
}
})
}
}
})
}
@@
-211,23
+232,21
@@
const factorial = n => {
const readWriteFiles = (
n,
const readWriteFiles = (
n,
- baseDirectory = `/tmp/poolifier-benchmarks/${crypto.randomInt(
- 281474976710655
- )}`
+ baseDirectory = `/tmp/poolifier-benchmarks/${randomInt(281474976710655)}`
) => {
) => {
- if (
fs.
existsSync(baseDirectory) === true) {
-
fs.
rmSync(baseDirectory, { recursive: true })
+ if (existsSync(baseDirectory) === true) {
+ rmSync(baseDirectory, { recursive: true })
}
}
-
fs.
mkdirSync(baseDirectory, { recursive: true })
+ mkdirSync(baseDirectory, { recursive: true })
for (let i = 0; i < n; i++) {
const filePath = `${baseDirectory}/${i}`
for (let i = 0; i < n; i++) {
const filePath = `${baseDirectory}/${i}`
-
fs.
writeFileSync(filePath, i.toString(), {
+ writeFileSync(filePath, i.toString(), {
encoding: 'utf8',
flag: 'a'
})
encoding: 'utf8',
flag: 'a'
})
-
fs.
readFileSync(filePath, 'utf8')
+ readFileSync(filePath, 'utf8')
}
}
-
fs.
rmSync(baseDirectory, { recursive: true })
+ rmSync(baseDirectory, { recursive: true })
return { ok: 1 }
}
return { ok: 1 }
}
@@
-248,7
+267,6
@@
const executeTaskFunction = data => {
module.exports = {
LIST_FORMATTER,
module.exports = {
LIST_FORMATTER,
- buildPoolifierPool,
executeTaskFunction,
generateRandomInteger,
runPoolifierPoolBenchmark
executeTaskFunction,
generateRandomInteger,
runPoolifierPoolBenchmark