docs: update changelog entries
[poolifier.git] / benchmarks / internal / thread / fixed.js
index 8168a6dc20ca113dad6c8ac532b182ce94ac9ac7..a4ba580e0210710915e184abaeb6951caf1c6fd2 100644 (file)
@@ -1,29 +1,75 @@
-const { FixedThreadPool } = require('../../../lib/index')
+const {
+  FixedThreadPool,
+  WorkerChoiceStrategies
+} = require('../../../lib/index')
+const { runPoolifierTest } = require('../../benchmarks-utils')
 
 const size = 30
+const numberOfTasks = 1
 
-const fixedPool = new FixedThreadPool(size, './worker.js')
+const fixedPool = new FixedThreadPool(
+  size,
+  './benchmarks/internal/thread/worker.js'
+)
+
+const fixedPoolLessUsed = new FixedThreadPool(
+  size,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
+)
+
+const fixedPoolLessBusy = new FixedThreadPool(
+  size,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+)
+
+const fixedPoolWeightedRoundRobin = new FixedThreadPool(
+  size,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
+)
+
+const fixedPoolFairShare = new FixedThreadPool(
+  size,
+  './benchmarks/internal/thread/worker.js',
+  { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
+)
 
 async function fixedThreadTest (
-  { 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 = { fixedThreadTest }
+async function fixedThreadTestLessUsed (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolLessUsed, { tasks, workerData })
+}
+
+async function fixedThreadTestLessBusy (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolLessBusy, { tasks, workerData })
+}
+
+async function fixedThreadTestWeightedRoundRobin (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolWeightedRoundRobin, { tasks, workerData })
+}
+
+async function fixedThreadTestFairShare (
+  { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } }
+) {
+  return runPoolifierTest(fixedPoolFairShare, { tasks, workerData })
+}
+
+module.exports = {
+  fixedThreadTest,
+  fixedThreadTestLessUsed,
+  fixedThreadTestLessBusy,
+  fixedThreadTestWeightedRoundRobin,
+  fixedThreadTestFairShare
+}