From: Jérôme Benoit Date: Fri, 20 Oct 2023 17:18:20 +0000 (+0200) Subject: refactor: cleanup benchmarking code X-Git-Tag: v3.0.4~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=49d60f11b30f7cdc9aca21379272a9ae89abe927;p=poolifier.git refactor: cleanup benchmarking code Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 054e2488..4986348d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Switch to Bencher for benchmarking: [https://bencher.dev/perf/poolifier](https://bencher.dev/perf/poolifier). - Use builtin retry mechanism in worker choice strategies instead of custom one. ## [3.0.3] - 2023-10-19 diff --git a/benchmarks/README.md b/benchmarks/README.md index 2008e9f0..ca2b0667 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -43,4 +43,4 @@ Read the [README.md](https://github.com/poolifier/benchmark#readme) to know how To run the internal benchmark, you just need to navigate to the root of poolifier cloned repository and run `pnpm benchmark`. -### [Results](https://poolifier.github.io/benchmark-results/dev/bench) +### [Results](https://bencher.dev/perf/poolifier) diff --git a/benchmarks/benchmarks-utils.js b/benchmarks/benchmarks-utils.js index 48311a3f..678b41d7 100644 --- a/benchmarks/benchmarks-utils.js +++ b/benchmarks/benchmarks-utils.js @@ -76,12 +76,15 @@ const runPoolifierPool = async (pool, { taskExecutions, workerData }) => { const runPoolifierPoolBenchmark = async ( name, - pool, + workerType, + poolType, + poolSize, { taskExecutions, workerData } ) => { + const pool = buildPoolifierPool(workerType, poolType, poolSize) + const suite = new Benchmark.Suite(name) return await new Promise((resolve, reject) => { try { - const suite = new Benchmark.Suite(name) for (const workerChoiceStrategy of Object.values( WorkerChoiceStrategies )) { @@ -151,12 +154,16 @@ const runPoolifierPoolBenchmark = async ( LIST_FORMATTER.format(this.filter('fastest').map('name')) ) await pool.destroy() - pool = undefined resolve() }) .run({ async: true }) } catch (error) { - reject(error) + pool + .destroy() + .then(() => { + return reject(error) + }) + .catch(() => {}) } }) } @@ -249,7 +256,6 @@ const executeTaskFunction = data => { module.exports = { LIST_FORMATTER, - buildPoolifierPool, executeTaskFunction, generateRandomInteger, runPoolifierPoolBenchmark diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 7ef61bc6..368cf29c 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -4,10 +4,7 @@ import { availableParallelism } from '../../lib/index.mjs' import { TaskFunctions } from '../benchmarks-types.js' -import { - buildPoolifierPool, - runPoolifierPoolBenchmark -} from '../benchmarks-utils.js' +import { runPoolifierPoolBenchmark } from '../benchmarks-utils.js' const poolSize = availableParallelism() const taskExecutions = 1 @@ -19,7 +16,9 @@ const workerData = { // FixedThreadPool await runPoolifierPoolBenchmark( 'Poolifier FixedThreadPool', - buildPoolifierPool(WorkerTypes.thread, PoolTypes.fixed, poolSize), + WorkerTypes.thread, + PoolTypes.fixed, + poolSize, { taskExecutions, workerData @@ -29,7 +28,9 @@ await runPoolifierPoolBenchmark( // DynamicThreadPool await runPoolifierPoolBenchmark( 'Poolifier DynamicThreadPool', - buildPoolifierPool(WorkerTypes.thread, PoolTypes.dynamic, poolSize), + WorkerTypes.thread, + PoolTypes.dynamic, + poolSize, { taskExecutions, workerData @@ -39,7 +40,9 @@ await runPoolifierPoolBenchmark( // FixedClusterPool await runPoolifierPoolBenchmark( 'Poolifier FixedClusterPool', - buildPoolifierPool(WorkerTypes.cluster, PoolTypes.fixed, poolSize), + WorkerTypes.cluster, + PoolTypes.fixed, + poolSize, { taskExecutions, workerData @@ -49,7 +52,9 @@ await runPoolifierPoolBenchmark( // DynamicClusterPool await runPoolifierPoolBenchmark( 'Poolifier DynamicClusterPool', - buildPoolifierPool(WorkerTypes.cluster, PoolTypes.dynamic, poolSize), + WorkerTypes.cluster, + PoolTypes.dynamic, + poolSize, { taskExecutions, workerData