| 1 | // IMPORT LIBRARIES |
| 2 | const Pool = require('worker-threads-pool') |
| 3 | // FINISH IMPORT LIBRARIES |
| 4 | const size = Number(process.env.POOL_SIZE) |
| 5 | const iterations = Number(process.env.NUM_ITERATIONS) |
| 6 | const data = { |
| 7 | test: 'MYBENCH', |
| 8 | taskType: process.env['TASK_TYPE'] |
| 9 | } |
| 10 | |
| 11 | const pool = new Pool({ max: size }) |
| 12 | |
| 13 | async function run () { |
| 14 | const promises = [] |
| 15 | for (let i = 0; i < iterations; i++) { |
| 16 | promises.push( |
| 17 | pool.acquire( |
| 18 | './workers/worker-threads-pool/function-to-bench-worker.js', |
| 19 | { |
| 20 | workerData: data |
| 21 | } |
| 22 | ) |
| 23 | ) |
| 24 | } |
| 25 | await Promise.all(promises) |
| 26 | process.exit() |
| 27 | } |
| 28 | |
| 29 | run() |