X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fcluster%2Ffixed.js;h=fc4cc3ac8dc545ba4b8d530401b19ac396f1f02c;hb=85ff0ff051cf39e2a7ce2de2e644330364ed6065;hp=1fd8d6797c62e1db75e362225e07958d4c5f9dd7;hpb=1927ee6758147bb8a2479b987322564cea20992b;p=poolifier.git diff --git a/benchmarks/internal/cluster/fixed.js b/benchmarks/internal/cluster/fixed.js index 1fd8d679..fc4cc3ac 100644 --- a/benchmarks/internal/cluster/fixed.js +++ b/benchmarks/internal/cluster/fixed.js @@ -1,32 +1,33 @@ -const { FixedClusterPool } = require('../../../lib/index') +const { + FixedClusterPool, + WorkerChoiceStrategies +} = require('../../../lib/index') +const { runPoolifierTest } = require('../benchmark-utils') const size = 30 +const numberOfTasks = 1 const fixedPool = new FixedClusterPool( size, './benchmarks/internal/cluster/worker.js' ) +const fixedPoolLessRecentlyUsed = new FixedClusterPool( + size, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED } +) + async function fixedClusterTest ( - { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(fixedPool, { tasks, workerData }) +} + +async function fixedClusterTestLessRecentlyUsed ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } ) { - return new Promise((resolve, reject) => { - let executions = 0 - for (let i = 0; i <= tasks; i++) { - fixedPool - .execute(workerData) - .then(res => { - executions++ - if (executions === tasks) { - return resolve('FINISH') - } - return null - }) - .catch(err => { - console.error(err) - }) - } - }) + return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData }) } -module.exports = { fixedClusterTest } +module.exports = { fixedClusterTest, fixedClusterTestLessRecentlyUsed }