39d743ad1293b7c851cd6e4180ae2c8ad6047ff5
1 const Benchmark
= require('benchmark')
2 const suite
= new Benchmark
.Suite()
3 const FixedThreadPool
= require('../lib/fixed')
4 const Pool
= require('worker-threads-pool')
6 const externalPool
= new Pool({ max
: size
})
8 const fixedPool
= new FixedThreadPool(size
,
9 './yourWorker.js', { maxTasks
: 10000 })
10 // const dynamicPool = new DynamicThreadPool(size, size * 2, './yourWorker.js', { maxTasks: 10000 })
11 const workerData
= { proof
: 'ok' }
14 // wait some seconds before start, my pools need to load threads !!!
15 setTimeout(async () => {
19 async
function test () {
21 suite
.add('PioardiStaticPool', async
function () {
23 await fixedPool
.execute(workerData
)
25 .add('ExternalPool', async
function () {
26 await
new Promise((resolve
, reject
) => {
27 externalPool
.acquire('./externalWorker.js', { workerData
: workerData
}, (err
, worker
) => {
31 worker
.on('error', reject
)
32 worker
.on('message', res
=> {
39 .add('PioardiDynamicPool', async function () {
40 await dynamicPool.execute(workerData)
43 .on('cycle', function (event
) {
44 console
.log(String(event
.target
))
46 .on('complete', function () {
47 console
.log(executions
)
48 this.filter('fastest').map('name')
49 console
.log('Fastest is ' + this.filter('fastest').map('name'))
55 process
.on('SIGKILL', () => {
57 externalPool
.destroy()