Merge branch 'master' of github.com:jerome-benoit/poolifier
[poolifier.git] / benchmarks / internal / cluster / fixed.js
index 60a5b938f8a5a6f46fc474a1e0e115152dba05e0..7e31a838eceaaa271abcc7cf9a277a70eb6bbc75 100644 (file)
@@ -1,17 +1,75 @@
-const { FixedClusterPool } = require('../../../lib/index')
-const { runTest } = require('../benchmark-utils')
+const {
+  FixedClusterPool,
+  WorkerChoiceStrategies
+} = require('../../../lib/index')
+const { runPoolifierTest } = require('../../benchmarks-utils')
 
 const size = 30
+const numberOfTasks = 1
 
 const fixedPool = new FixedClusterPool(
   size,
   './benchmarks/internal/cluster/worker.js'
 )
 
+const fixedPoolLessUsed = new FixedClusterPool(
+  size,
+  './benchmarks/internal/cluster/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
+)
+
+const fixedPoolLessBusy = new FixedClusterPool(
+  size,
+  './benchmarks/internal/cluster/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+)
+
+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 (
-  { tasks, workerData } = { tasks: 1, workerData: { proof: 'ok' } }
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
 ) {
-  return runTest(fixedPool, { tasks, workerData })
+  return runPoolifierTest(fixedPool, { tasks, workerData })
 }
 
-module.exports = { fixedClusterTest }
+async function fixedClusterTestLessUsed (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
+}
+
+async function fixedClusterTestLessBusy (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolLessBusy, { 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,
+  fixedClusterTestLessUsed,
+  fixedClusterTestLessBusy,
+  fixedClusterTestWeightedRoundRobin,
+  fixedClusterTestFairShare
+}