X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fcluster%2Ffixed.js;h=388689a3be7e5bc8ba37e38e7b53cd1b902f0d22;hb=2d2e32c20d55c1b81771659fd81004bd7ca34b73;hp=f2b80c7198d71872e6ad858c7db661b1894ee46b;hpb=be0676b3936d75f22ce55b0f71a1fb03d008a01c;p=poolifier.git diff --git a/benchmarks/internal/cluster/fixed.js b/benchmarks/internal/cluster/fixed.js index f2b80c71..388689a3 100644 --- a/benchmarks/internal/cluster/fixed.js +++ b/benchmarks/internal/cluster/fixed.js @@ -1,35 +1,62 @@ -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 } +) + +const fixedPoolWeightedRoundRobin = new FixedClusterPool( + size, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } +) + +const fixedPoolFairShare = new FixedClusterPool( size, './benchmarks/internal/cluster/worker.js', - { - maxTasks: 10000 - } + { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } ) async function fixedClusterTest ( - { 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++) { - fixedPool - .execute(workerData) - .then(res => { - executions++ - if (executions === tasks) { - return resolve('FINISH') - } - return null - }) - .catch(err => { - console.error(err) - }) - } - }) + return runPoolifierTest(fixedPool, { tasks, workerData }) } -module.exports = { fixedClusterTest } +async function fixedClusterTestLessRecentlyUsed ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData }) +} + +async function fixedClusterTestWeightedRoundRobin ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData }) +} + +async function fixedClusterTestFairShare ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(fixedPoolFairShare, { tasks, workerData }) +} + +module.exports = { + fixedClusterTest, + fixedClusterTestLessRecentlyUsed, + fixedClusterTestWeightedRoundRobin, + fixedClusterTestFairShare +}