-examples/typescript/**/*.ts
-benchmarks/versus-external-pools/
docs/
outputs/
lib/
skipWords: [
'browserslist',
'christopher',
+ 'cjs',
'comparator',
'cpu',
'cpus',
+ 'ctx',
'ecma',
'enum',
'fibonacci',
+ 'fs',
'inheritDoc',
'jsdoc',
+ 'microjob',
'num',
'os',
+ 'piscina',
'poolifier',
+ 'poolify',
'readonly',
'serializable',
'sinon',
+ 'threadjs',
+ 'threadwork',
'tsconfig',
'typedoc',
+ 'unlink',
'unregister',
+ 'utf8',
'workerpool'
],
skipIfMatch: ['^@.*', '^plugin:.*']
'jsdoc/require-returns-type': 'off'
}
},
+ {
+ files: ['examples/typescript/**/*.ts'],
+ rules: {
+ 'import/no-unresolved': 'off',
+ 'jsdoc/require-jsdoc': 'off',
+ '@typescript-eslint/no-unsafe-argument': 'off',
+ '@typescript-eslint/no-unsafe-call': 'off',
+ '@typescript-eslint/no-unsafe-assignment': 'off'
+ }
+ },
{
files: ['**/*.js'],
extends: 'plugin:node/recommended'
## [Unreleased]
+### Changed
+
+- Improve benchmarks: add IO intensive task workload, add task size option, integrate into eslint.
+
## [2.3.4] - 2022-10-17
### Added
#!/usr/bin/env bash
-### The -t argument is needed to specify the type of task that you want to benchmark.
-### Supported values are CPU_INTENSIVE
+### The -t argument permit to specify the type of task that you want to benchmark.
+### The -s argument permit to specify the size of task that you want to benchmark.
+### Supported values are CPU_INTENSIVE, IO_INTENSIVE
taskType='CPU_INTENSIVE'
-while getopts t: flag
+taskSize=5000
+while getopts "t:s:h" option
do
- case "${flag}" in
+ case "${option}" in
t)
taskType=${OPTARG}
;;
+ s)
+ taskSize=${OPTARG}
+ ;;
+ *|h)
+ echo "Usage: $0 [-t taskType] [-s taskSize]"
+ exit 1
+ ;;
esac
done
-echo 'Running bench for task type:' $taskType
-export TASK_TYPE=$taskType
+echo 'Running benchmarks for task type:' ${taskType} 'and task size:' ${taskSize}
+export TASK_TYPE=${taskType}
+export TASK_SIZE=${taskSize}
# Execute bench
export NODE_ENV=production
export POOL_SIZE=10
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const piscina = new Piscina({
promises.push(piscina.run(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const dynamicPool = new DynamicThreadPool(
promises.push(dynamicPool.execute(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const pool = new DynamicPool(size)
)
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const workerNodes = new WorkerNodes(
promises.push(workerNodes.call.functionToBench(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
// FINISH IMPORT LIBRARIES
const size = Number(process.env.POOL_SIZE)
const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
+const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
promises.push(workerPool.exec('functionToBench', dataArray))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
async function run () {
data => {
functionToBench(data)
},
- { data: data, ctx: { functionToBench } }
+ { data, ctx: { functionToBench } }
)
)
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const piscina = new Piscina({
promises.push(piscina.run(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const fixedPool = new FixedThreadPool(
promises.push(fixedPool.execute(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
async function run () {
promises.push(threadPool.run(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const workerNodes = new WorkerNodes(
promises.push(workerNodes.call.functionToBench(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
// FINISH IMPORT LIBRARIES
const size = Number(process.env.POOL_SIZE)
const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env['TASK_TYPE']]
+const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
promises.push(workerPool.exec('functionToBench', dataArray))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
+const fs = require('fs')
+
+const TaskTypes = {
+ CPU_INTENSIVE: 'CPU_INTENSIVE',
+ IO_INTENSIVE: 'IO_INTENSIVE'
+}
+
module.exports = function (data) {
+ console.log('functionToBench', data)
data = data || {}
- data.taskType = data.taskType || 'CPU_INTENSIVE'
+ data.taskType = data.taskType || TaskTypes.CPU_INTENSIVE
data.taskSize = data.taskSize || 5000
+ const benchmarksFilePath = '/tmp/poolifier-benchmarks'
switch (data.taskType) {
- case 'CPU_INTENSIVE':
+ case TaskTypes.CPU_INTENSIVE:
// CPU intensive task
for (let i = 0; i < data.taskSize; i++) {
const o = {
JSON.stringify(o)
}
return { ok: 1 }
+ case TaskTypes.IO_INTENSIVE:
+ // IO intensive task
+ for (let i = 0; i < data.taskSize; i++) {
+ fs.writeFileSync(benchmarksFilePath, i.toString(), 'utf8')
+ fs.readFileSync(benchmarksFilePath, 'utf8')
+ fs.unlinkSync(benchmarksFilePath)
+ }
+ return { ok: 1 }
default:
throw new Error(`Unknown task type: ${data.taskType}`)
}
// FINISH IMPORT FUNCTION TO BENCH
const size = Number(process.env.POOL_SIZE)
-module.exports = new ThreadPool({ task: functionToBench, size: size })
+module.exports = new ThreadPool({ task: functionToBench, size })
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
const pool = new StaticPool({
- size: size,
+ size,
task: functionToBench
})
promises.push(pool.exec(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const iterations = Number(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
- taskType: process.env['TASK_TYPE']
+ taskType: process.env.TASK_TYPE,
+ taskSize: process.env.TASK_SIZE
}
// Threads.js is not really a pool so we need to write few additional code
promises.push(worker.exposedFunction(data))
}
await Promise.all(promises)
+ // eslint-disable-next-line no-process-exit
process.exit()
}
const workerpool = require('workerpool')
const functionToBench = require('../../functions/function-to-bench')
-function workerPoolWrapperFunctionToBench (testName, taskType) {
- return functionToBench({ test: testName, taskType: taskType })
+function workerPoolWrapperFunctionToBench (testName, taskType, taskSize) {
+ return functionToBench({
+ test: testName,
+ taskType,
+ taskSize
+ })
}
workerpool.worker({
for (let i = 1; i <= iterations; i++) {
pool
.execute({})
- .then(res => {
+ .then(() => {
resolved++
if (resolved === iterations) {
console.log('Time take is ' + (Date.now() - start))
for (let i = 1; i <= iterations; i++) {
pool
.execute({})
- .then(res => {
+ .then(() => {
resolved++
if (resolved === iterations) {
return console.log('Time take is ' + (Date.now() - start))
import { join } from 'path'
import { DynamicThreadPool, FixedThreadPool } from 'poolifier'
-import { MyData, MyResponse } from './worker'
+import type { MyData, MyResponse } from './worker'
export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
8,
const debug = false
-function yourFunction (data) {
+function yourFunction () {
for (let i = 0; i <= 1000; i++) {
const o = {
a: i
"strict": true,
"importsNotUsedAsValues": "error"
},
- "include": ["src/**/*.ts"],
+ "include": ["**/*.ts"],
"exclude": ["node_modules"]
}