From 31a7d5bea6971eff8079efd2a164a66086f6d4b3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 3 Jul 2023 22:52:20 +0200 Subject: [PATCH] fix: fix availableParallelism() usage for pool min size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 2 +- benchmarks/benchmarks-utils.mjs | 4 ++-- examples/dynamicExample.js | 2 +- examples/typescript/pool.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3001f098..91112b67 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', { pool.emitter.on(PoolEvents.busy, () => console.info('Pool is busy')) // or a dynamic worker-threads pool -const pool = new DynamicThreadPool(availableParallelism() / 2, availableParallelism(), './yourWorker.js', { +const pool = new DynamicThreadPool(Math.floor(availableParallelism() / 2), availableParallelism(), './yourWorker.js', { errorHandler: e => console.error(e), onlineHandler: () => console.info('worker is online') }) diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index 225143f1..56767597 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -133,14 +133,14 @@ export const buildPool = (workerType, poolType, poolSize, poolOptions) => { switch (workerType) { case WorkerTypes.thread: return new DynamicThreadPool( - poolSize / 2, + Math.floor(poolSize / 2), poolSize * 3, './benchmarks/internal/thread-worker.mjs', poolOptions ) case WorkerTypes.cluster: return new DynamicClusterPool( - poolSize / 2, + Math.floor(poolSize / 2), poolSize * 3, './benchmarks/internal/cluster-worker.mjs', poolOptions diff --git a/examples/dynamicExample.js b/examples/dynamicExample.js index 6af04560..bb457af8 100644 --- a/examples/dynamicExample.js +++ b/examples/dynamicExample.js @@ -5,7 +5,7 @@ const { } = require('poolifier') const pool = new DynamicThreadPool( - availableParallelism() / 2, + Math.floor(availableParallelism() / 2), availableParallelism(), './yourWorker.js', { diff --git a/examples/typescript/pool.ts b/examples/typescript/pool.ts index b6bb4da3..54b437ab 100644 --- a/examples/typescript/pool.ts +++ b/examples/typescript/pool.ts @@ -20,7 +20,7 @@ export const fixedPool = new FixedThreadPool>( ) export const dynamicPool = new DynamicThreadPool>( - availableParallelism() / 2, + Math.floor(availableParallelism() / 2), availableParallelism(), join(__dirname, 'worker.js'), { -- 2.34.1