feat: add less busy worker choice strategy
[poolifier.git] / benchmarks / internal / cluster / fixed.js
index fc4cc3ac8dc545ba4b8d530401b19ac396f1f02c..69e4a14870013bd5f3136d8ecb25309c9d93c163 100644 (file)
@@ -2,7 +2,7 @@ const {
   FixedClusterPool,
   WorkerChoiceStrategies
 } = require('../../../lib/index')
-const { runPoolifierTest } = require('../benchmark-utils')
+const { runPoolifierTest } = require('../../benchmarks-utils')
 
 const size = 30
 const numberOfTasks = 1
@@ -12,10 +12,22 @@ const fixedPool = new FixedClusterPool(
   './benchmarks/internal/cluster/worker.js'
 )
 
-const fixedPoolLessRecentlyUsed = new FixedClusterPool(
+const fixedPoolLessUsed = new FixedClusterPool(
   size,
   './benchmarks/internal/cluster/worker.js',
-  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_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',
+  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
 )
 
 async function fixedClusterTest (
@@ -24,10 +36,27 @@ async function fixedClusterTest (
   return runPoolifierTest(fixedPool, { tasks, workerData })
 }
 
-async function fixedClusterTestLessRecentlyUsed (
+async function fixedClusterTestLessUsed (
   { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
 ) {
-  return runPoolifierTest(fixedPoolLessRecentlyUsed, { tasks, workerData })
+  return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
 }
 
-module.exports = { fixedClusterTest, fixedClusterTestLessRecentlyUsed }
+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,
+  fixedClusterTestLessUsed,
+  fixedClusterTestWeightedRoundRobin,
+  fixedClusterTestFairShare
+}