+const crypto = require('crypto')
const fs = require('fs')
const {
PoolTypes,
return factorial(n - 1) * n
}
-function readWriteFiles (n) {
- const baseDirectory = '/tmp/poolifier-benchmarks'
- if (fs.existsSync(baseDirectory) === false) {
- fs.mkdirSync(baseDirectory, { recursive: true })
+function readWriteFiles (
+ n,
+ baseDirectory = `/tmp/poolifier-benchmarks/${crypto.randomInt(
+ 281474976710655
+ )}`
+) {
+ if (fs.existsSync(baseDirectory) === true) {
+ fs.rmSync(baseDirectory, { recursive: true })
}
+ fs.mkdirSync(baseDirectory, { recursive: true })
for (let i = 0; i < n; i++) {
const filePath = `${baseDirectory}/${i}`
fs.writeFileSync(filePath, i.toString(), {
})
fs.readFileSync(filePath, 'utf8')
}
+ fs.rmSync(baseDirectory, { recursive: true })
}
function executeWorkerFunction (data) {
* @returns {*} The result.
*/
function functionToBench (data) {
+ const crypto = require('crypto')
const fs = require('fs')
const TaskTypes = {
CPU_INTENSIVE: 'CPU_INTENSIVE',
data = data || {}
data.taskType = data.taskType || TaskTypes.CPU_INTENSIVE
data.taskSize = data.taskSize || 5000
- const baseDirectory = '/tmp/poolifier-benchmarks'
+ const baseDirectory = `/tmp/poolifier-benchmarks/${crypto.randomInt(
+ 281474976710655
+ )}`
switch (data.taskType) {
case TaskTypes.CPU_INTENSIVE:
// CPU intensive task
return { ok: 1 }
case TaskTypes.IO_INTENSIVE:
// IO intensive task
- if (fs.existsSync(baseDirectory) === false) {
- fs.mkdirSync(baseDirectory, { recursive: true })
+ if (fs.existsSync(baseDirectory) === true) {
+ fs.rmSync(baseDirectory, { recursive: true })
}
+ fs.mkdirSync(baseDirectory, { recursive: true })
for (let i = 0; i < data.taskSize; i++) {
const filePath = `${baseDirectory}/${i}`
fs.writeFileSync(filePath, i.toString(), {
})
fs.readFileSync(filePath, 'utf8')
}
+ fs.rmSync(baseDirectory, { recursive: true })
return { ok: 1 }
default:
throw new Error(`Unknown task type: ${data.taskType}`)