X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=benchmarks%2Finternal%2Fcluster%2Fdynamic.js;h=7ad9dd282d5e27a7afcdcd10e9a0d4c860e4e75c;hb=015cd3c7998314810359dcd1941466e09d6147f7;hp=7e607c87059229431490d29e1cee0b56b5e2d51c;hpb=1927ee6758147bb8a2479b987322564cea20992b;p=poolifier.git diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js index 7e607c87..7ad9dd28 100644 --- a/benchmarks/internal/cluster/dynamic.js +++ b/benchmarks/internal/cluster/dynamic.js @@ -1,4 +1,8 @@ -const { DynamicClusterPool } = require('../../../lib/index') +const { + DynamicClusterPool, + WorkerChoiceStrategies +} = require('../../../lib/index') +const { runTest } = require('../benchmark-utils') const size = 30 @@ -8,24 +12,26 @@ const dynamicPool = new DynamicClusterPool( './benchmarks/internal/cluster/worker.js' ) +const dynamicPoolLessRecentlyUsed = new DynamicClusterPool( + size / 2, + size * 3, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED } +) + async function dynamicClusterTest ( { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } ) { - return new Promise((resolve, reject) => { - let executions = 0 - for (let i = 0; i <= tasks; i++) { - dynamicPool - .execute(workerData) - .then(res => { - executions++ - if (executions === tasks) { - return resolve('FINISH') - } - return null - }) - .catch(err => console.error(err)) - } - }) + return runTest(dynamicPool, { tasks, workerData }) } -module.exports = { dynamicClusterTest } +async function dynamicClusterTestLessRecentlyUsed ( + { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } +) { + return runTest(dynamicPoolLessRecentlyUsed, { tasks, workerData }) +} + +module.exports = { + dynamicClusterTest, + dynamicClusterTestLessRecentlyUsed +}