X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Finternal%2Fcluster%2Fdynamic.js;h=105bbdaa9d77eef540cfa361e6d794095b400363;hb=refs%2Ftags%2Fv2.3.10;hp=7e607c87059229431490d29e1cee0b56b5e2d51c;hpb=1927ee6758147bb8a2479b987322564cea20992b;p=poolifier.git diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js index 7e607c87..105bbdaa 100644 --- a/benchmarks/internal/cluster/dynamic.js +++ b/benchmarks/internal/cluster/dynamic.js @@ -1,6 +1,11 @@ -const { DynamicClusterPool } = require('../../../lib/index') +const { + DynamicClusterPool, + WorkerChoiceStrategies +} = require('../../../lib/index') +const { runPoolifierTest } = require('../../benchmarks-utils') const size = 30 +const numberOfTasks = 1 const dynamicPool = new DynamicClusterPool( size / 2, @@ -8,24 +13,54 @@ 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 } +) + +const dynamicPoolWeightedRoundRobin = new DynamicClusterPool( + size / 2, + size * 3, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } +) + +const dynamicPoolFairShare = new DynamicClusterPool( + size / 2, + size * 3, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } +) + async function dynamicClusterTest ( - { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } } + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPool, { tasks, workerData }) +} + +async function dynamicClusterTestLessRecentlyUsed ( + { 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(dynamicPoolLessRecentlyUsed, { tasks, workerData }) } -module.exports = { dynamicClusterTest } +async function dynamicClusterTestWeightedRoundRobin ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPoolWeightedRoundRobin, { tasks, workerData }) +} + +async function dynamicClusterTestFairShare ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPoolFairShare, { tasks, workerData }) +} + +module.exports = { + dynamicClusterTest, + dynamicClusterTestLessRecentlyUsed, + dynamicClusterTestWeightedRoundRobin, + dynamicClusterTestFairShare +}