From d4abc60abeea2538c1452ae6d8bd2463bdacc910 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 2 Apr 2023 21:07:39 +0200 Subject: [PATCH] feat: add less busy worker choice strategy to internal benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 2 +- benchmarks/internal/bench.js | 28 ++++++++++++++++++++------ benchmarks/internal/cluster/dynamic.js | 14 +++++++++++++ benchmarks/internal/cluster/fixed.js | 13 ++++++++++++ benchmarks/internal/thread/dynamic.js | 14 +++++++++++++ benchmarks/internal/thread/fixed.js | 13 ++++++++++++ 6 files changed, 77 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e11a8729..79788cf7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] diff --git a/benchmarks/internal/bench.js b/benchmarks/internal/bench.js index a3de2086..21864828 100644 --- a/benchmarks/internal/bench.js +++ b/benchmarks/internal/bench.js @@ -3,25 +3,29 @@ const { dynamicClusterTest, dynamicClusterTestFairShare, dynamicClusterTestLessUsed, - dynamicClusterTestWeightedRoundRobin + dynamicClusterTestWeightedRoundRobin, + dynamicClusterTestLessBusy } = require('./cluster/dynamic') const { fixedClusterTest, fixedClusterTestFairShare, fixedClusterTestLessUsed, - fixedClusterTestWeightedRoundRobin + fixedClusterTestWeightedRoundRobin, + fixedClusterTestLessBusy } = require('./cluster/fixed') const { dynamicThreadTest, dynamicThreadTestFairShare, dynamicThreadTestLessUsed, - dynamicThreadTestWeightedRoundRobin + dynamicThreadTestWeightedRoundRobin, + dynamicThreadTestLessBusy } = require('./thread/dynamic') const { fixedThreadTest, fixedThreadTestFairShare, fixedThreadTestLessUsed, - fixedThreadTestWeightedRoundRobin + fixedThreadTestWeightedRoundRobin, + fixedThreadTestLessBusy } = require('./thread/fixed') const resultsFile = 'poolifier' @@ -35,6 +39,9 @@ Benchmark.suite( Benchmark.add('Poolifier:Fixed:ThreadPool:LessUsed', async () => { await fixedThreadTestLessUsed() }), + Benchmark.add('Poolifier:Fixed:ThreadPool:LessBusy', async () => { + await fixedThreadTestLessBusy() + }), Benchmark.add('Poolifier:Fixed:ThreadPool:WeightedRoundRobin', async () => { await fixedThreadTestWeightedRoundRobin() }), @@ -47,6 +54,9 @@ Benchmark.suite( Benchmark.add('Poolifier:Dynamic:ThreadPool:LessUsed', async () => { await dynamicThreadTestLessUsed() }), + Benchmark.add('Poolifier:Dynamic:ThreadPool:LessBusy', async () => { + await dynamicThreadTestLessBusy() + }), Benchmark.add('Poolifier:Dynamic:ThreadPool:WeightedRoundRobin', async () => { await dynamicThreadTestWeightedRoundRobin() }), @@ -59,8 +69,11 @@ Benchmark.suite( Benchmark.add('Poolifier:Fixed:ClusterPool:LessUsed', async () => { await fixedClusterTestLessUsed() }), + Benchmark.add('Poolifier:Fixed:ClusterPool:LessBusy', async () => { + await fixedClusterTestLessBusy() + }), Benchmark.add('Poolifier:Fixed:ClusterPool:WeightedRoundRobin', async () => { - await fixedClusterTestWeightedRoundRobin + await fixedClusterTestWeightedRoundRobin() }), Benchmark.add('Poolifier:Fixed:ClusterPool:FairShare', async () => { await fixedClusterTestFairShare() @@ -71,10 +84,13 @@ Benchmark.suite( Benchmark.add('Poolifier:Dynamic:ClusterPool:LessUsed', async () => { await dynamicClusterTestLessUsed() }), + Benchmark.add('Poolifier:Dynamic:ClusterPool:LessBusy', async () => { + await dynamicClusterTestLessBusy() + }), Benchmark.add( 'Poolifier:Dynamic:ClusterPool:WeightedRoundRobin', async () => { - await dynamicClusterTestWeightedRoundRobin + await dynamicClusterTestWeightedRoundRobin() } ), Benchmark.add('Poolifier:Dynamic:ClusterPool:FairShare', async () => { diff --git a/benchmarks/internal/cluster/dynamic.js b/benchmarks/internal/cluster/dynamic.js index 60ee14f6..475ba9d7 100644 --- a/benchmarks/internal/cluster/dynamic.js +++ b/benchmarks/internal/cluster/dynamic.js @@ -20,6 +20,13 @@ const dynamicPoolLessUsed = new DynamicClusterPool( { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED } ) +const dynamicPoolLessBusy = new DynamicClusterPool( + size / 2, + size * 3, + './benchmarks/internal/cluster/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY } +) + const dynamicPoolWeightedRoundRobin = new DynamicClusterPool( size / 2, size * 3, @@ -46,6 +53,12 @@ async function dynamicClusterTestLessUsed ( return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData }) } +async function dynamicClusterTestLessBusy ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData }) +} + async function dynamicClusterTestWeightedRoundRobin ( { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } ) { @@ -61,6 +74,7 @@ async function dynamicClusterTestFairShare ( module.exports = { dynamicClusterTest, dynamicClusterTestLessUsed, + dynamicClusterTestLessBusy, dynamicClusterTestWeightedRoundRobin, dynamicClusterTestFairShare } diff --git a/benchmarks/internal/cluster/fixed.js b/benchmarks/internal/cluster/fixed.js index 69e4a148..7e31a838 100644 --- a/benchmarks/internal/cluster/fixed.js +++ b/benchmarks/internal/cluster/fixed.js @@ -18,6 +18,12 @@ const fixedPoolLessUsed = new FixedClusterPool( { 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', @@ -42,6 +48,12 @@ async function fixedClusterTestLessUsed ( 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' } } ) { @@ -57,6 +69,7 @@ async function fixedClusterTestFairShare ( module.exports = { fixedClusterTest, fixedClusterTestLessUsed, + fixedClusterTestLessBusy, fixedClusterTestWeightedRoundRobin, fixedClusterTestFairShare } diff --git a/benchmarks/internal/thread/dynamic.js b/benchmarks/internal/thread/dynamic.js index 04f18406..503ea27c 100644 --- a/benchmarks/internal/thread/dynamic.js +++ b/benchmarks/internal/thread/dynamic.js @@ -20,6 +20,13 @@ const dynamicPoolLessUsed = new DynamicThreadPool( { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED } ) +const dynamicPoolLessBusy = new DynamicThreadPool( + size / 2, + size * 3, + './benchmarks/internal/thread/worker.js', + { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY } +) + const dynamicPoolWeightedRoundRobin = new DynamicThreadPool( size / 2, size * 3, @@ -46,6 +53,12 @@ async function dynamicThreadTestLessUsed ( return runPoolifierTest(dynamicPoolLessUsed, { tasks, workerData }) } +async function dynamicThreadTestLessBusy ( + { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } +) { + return runPoolifierTest(dynamicPoolLessBusy, { tasks, workerData }) +} + async function dynamicThreadTestWeightedRoundRobin ( { tasks, workerData } = { tasks: numberOfTasks, workerData: { proof: 'ok' } } ) { @@ -61,6 +74,7 @@ async function dynamicThreadTestFairShare ( module.exports = { dynamicThreadTest, dynamicThreadTestLessUsed, + dynamicThreadTestLessBusy, dynamicThreadTestWeightedRoundRobin, dynamicThreadTestFairShare } diff --git a/benchmarks/internal/thread/fixed.js b/benchmarks/internal/thread/fixed.js index ee4105be..a4ba580e 100644 --- a/benchmarks/internal/thread/fixed.js +++ b/benchmarks/internal/thread/fixed.js @@ -18,6 +18,12 @@ const fixedPoolLessUsed = new FixedThreadPool( { 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', @@ -42,6 +48,12 @@ async function fixedThreadTestLessUsed ( 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' } } ) { @@ -57,6 +69,7 @@ async function fixedThreadTestFairShare ( module.exports = { fixedThreadTest, fixedThreadTestLessUsed, + fixedThreadTestLessBusy, fixedThreadTestWeightedRoundRobin, fixedThreadTestFairShare } -- 2.34.1