// IMPORT LIBRARIES
const Piscina = require('piscina')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const piscina = new Piscina({
// IMPORT LIBRARIES
const { DynamicThreadPool } = require('poolifier')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const dynamicPool = new DynamicThreadPool(
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const pool = new DynamicPool(size)
// IMPORT LIBRARIES
const WorkerNodes = require('worker-nodes')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const workerNodes = new WorkerNodes(
// IMPORT LIBRARIES
const workerpool = require('workerpool')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const dataArray = [
+ 'MYBENCH',
+ process.env.TASK_TYPE,
+ parseInt(process.env.TASK_SIZE)
+]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
async function run () {
// IMPORT LIBRARIES
const Piscina = require('piscina')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const piscina = new Piscina({
// IMPORT LIBRARIES
const { FixedThreadPool } = require('poolifier')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const fixedPool = new FixedThreadPool(
// IMPORT LIBRARIES
const threadPool = require('./pool-threadwork')
// FINISH IMPORT LIBRARIES
-const iterations = Number(process.env.NUM_ITERATIONS)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
async function run () {
// IMPORT LIBRARIES
const WorkerNodes = require('worker-nodes')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const workerNodes = new WorkerNodes(
// IMPORT LIBRARIES
const workerpool = require('workerpool')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
-const dataArray = ['MYBENCH', process.env.TASK_TYPE, process.env.TASK_SIZE]
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const dataArray = [
+ 'MYBENCH',
+ process.env.TASK_TYPE,
+ parseInt(process.env.TASK_SIZE)
+]
const workerPool = workerpool.pool(
'./workers/workerpool/function-to-bench-worker.js',
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
+const size = parseInt(process.env.POOL_SIZE)
module.exports = new ThreadPool({ task: functionToBench, size })
// IMPORT FUNCTION TO BENCH
const functionToBench = require('./functions/function-to-bench')
// FINISH IMPORT FUNCTION TO BENCH
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
const pool = new StaticPool({
// IMPORT LIBRARIES
const { spawn, Worker } = require('threads')
// FINISH IMPORT LIBRARIES
-const size = Number(process.env.POOL_SIZE)
-const iterations = Number(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
test: 'MYBENCH',
taskType: process.env.TASK_TYPE,
- taskSize: process.env.TASK_SIZE
+ taskSize: parseInt(process.env.TASK_SIZE)
}
// Threads.js is not really a pool so we need to write few additional code
public readonly filePath: string,
public readonly opts: PoolOptions<Worker>
) {
- if (!this.isMain()) {
+ if (this.isMain() === false) {
throw new Error('Cannot start a pool from a worker!')
}
this.checkNumberOfWorkers(this.numberOfWorkers)
this.createAndSetupWorker()
}
- if (this.opts.enableEvents) {
+ if (this.opts.enableEvents === true) {
this.emitter = new PoolEmitter()
}
this.workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
}
private checkAndEmitBusy (): void {
- if (this.opts.enableEvents && this.busy) {
+ if (this.opts.enableEvents === true && this.busy === true) {
this.emitter?.emit('busy')
}
}
): void {
if (value.data !== undefined && value.id !== undefined) {
// Here you will receive messages
- if (this.opts.async) {
+ if (this.opts.async === true) {
this.runInAsyncScope(this.runAsync.bind(this), this, fn, value)
} else {
this.runInAsyncScope(this.run.bind(this), this, fn, value)