fix: fix availableParallelism() usage for pool min size
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 20:52:20 +0000 (22:52 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 3 Jul 2023 20:52:20 +0000 (22:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
README.md
benchmarks/benchmarks-utils.mjs
examples/dynamicExample.js
examples/typescript/pool.ts

index 3001f098fdb0ba551ea6416bbabe5ab4b8d408f1..91112b67b071406e59e0fc8f04f814fd13e08454 100644 (file)
--- 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')
 })
index 225143f1a1b4d1d483342ad19903e0f4affaec07..56767597b41ff848012c31d9e1f1a92d6415e8e8 100644 (file)
@@ -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
index 6af045601025e3edac7c95a0b670b85b9c37f1f3..bb457af892ff2ff913ecd6317290e016f3ccd63d 100644 (file)
@@ -5,7 +5,7 @@ const {
 } = require('poolifier')
 
 const pool = new DynamicThreadPool(
-  availableParallelism() / 2,
+  Math.floor(availableParallelism() / 2),
   availableParallelism(),
   './yourWorker.js',
   {
index b6bb4da3427a93132842e5953cd6fa858d52408d..54b437ab31b2f1d7785439c5ce9007167e554331 100644 (file)
@@ -20,7 +20,7 @@ export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
 )
 
 export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
-  availableParallelism() / 2,
+  Math.floor(availableParallelism() / 2),
   availableParallelism(),
   join(__dirname, 'worker.js'),
   {