X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fcluster%2Fdynamic.js;h=3c00c50b8c7af84ebfc45f5f6cb4a2c814104c41;hb=e843b9042b77e0e4e17c193820a3e05ffc92cffe;hp=468eee3b68db72e0d67671aeaf493d2e2b50e5ef;hpb=be0676b3936d75f22ce55b0f71a1fb03d008a01c;p=poolifier.git diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js index 468eee3b..3c00c50b 100644 --- a/benchmarks/internal/cluster/dynamic.js +++ b/benchmarks/internal/cluster/dynamic.js @@ -1,34 +1,38 @@ -const { DynamicClusterPool } = require('../../../lib/index') +const { + DynamicClusterPool, + WorkerChoiceStrategies +} = require('../../../lib/index') +const { runPoolifierTest } = require('../benchmark-utils') const size = 30 +const numberOfTasks = 1 const dynamicPool = new DynamicClusterPool( + size / 2, + size * 3, + './benchmarks/internal/cluster/worker.js' +) + +const dynamicPoolLessRecentlyUsed = new DynamicClusterPool( size / 2, size * 3, './benchmarks/internal/cluster/worker.js', - { - maxTasks: 10000 - } + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED } ) async function dynamicClusterTest ( - { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } + { tasks, workerData } = { tasks: numberOfTasks, 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 runPoolifierTest(dynamicPool, { tasks, workerData }) } -module.exports = { dynamicClusterTest } +async function dynamicClusterTestLessRecentlyUsed ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPoolLessRecentlyUsed, { tasks, workerData }) +} + +module.exports = { + dynamicClusterTest, + dynamicClusterTestLessRecentlyUsed +}