From 13f6f591e352696558b58de160672d7dc6aa1771 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 3 Mar 2023 11:55:31 +0800 Subject: [PATCH] Improve server-stress benchmark comment (#6405) --- benchmark/bench/server-stress.js | 41 +++++++++++++++++++++++++------- benchmark/package.json | 3 ++- pnpm-lock.yaml | 3 ++- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/benchmark/bench/server-stress.js b/benchmark/bench/server-stress.js index 6237b2e5f5..1bb64375eb 100644 --- a/benchmark/bench/server-stress.js +++ b/benchmark/bench/server-stress.js @@ -3,6 +3,8 @@ import { fileURLToPath } from 'url'; import autocannon from 'autocannon'; import { execaCommand } from 'execa'; import { waitUntilBusy } from 'port-authority'; +import { markdownTable } from 'markdown-table'; +import pb from 'pretty-bytes'; import { astroBin } from './_util.js'; const port = 4321; @@ -45,14 +47,7 @@ export async function run(projectDir, outputFile) { console.log('Result preview:'); console.log('='.repeat(10)); console.log(`#### Server stress\n\n`); - let text = autocannon.printResult(result); - // Truncate the logs in CI so that the generated comment from the `!bench` command - // is shortened. Also we only need this information when comparing runs. - // Full log example: https://github.com/mcollina/autocannon#command-line - if (process.env.CI) { - text = text.match(/^.*?requests in.*?read$/m)?.[0]; - } - console.log(text); + console.log(printResult(result)); console.log('='.repeat(10)); console.log('Done!'); @@ -83,3 +78,33 @@ async function benchmarkCannon() { autocannon.track(instance, { renderResultsTable: false }); }); } + +/** + * @param {import('autocannon').Result} output + */ +function printResult(output) { + const { latency: l, requests: r, throughput: t } = output; + + const latencyTable = markdownTable( + [ + ['', 'Avg', 'Stdev', 'Max'], + ['Latency', `${l.average} ms`, `${l.stddev} ms`, `${l.max} ms`], + ], + { + align: ['l', 'r', 'r', 'r'], + } + ); + + const reqAndBytesTable = markdownTable( + [ + ['', 'Avg', 'Stdev', 'Min', 'Total in 30s'], + ['Req/Sec', r.average, r.stddev, r.min, `${(r.total / 1000).toFixed(1)}k requests`], + ['Bytes/Sec', pb(t.average), pb(t.stddev), pb(t.min), `${pb(t.total)} read`], + ], + { + align: ['l', 'r', 'r', 'r', 'r'], + } + ); + + return `${latencyTable}\n\n${reqAndBytesTable}`; +} diff --git a/benchmark/package.json b/benchmark/package.json index 4233cbba91..34b486e978 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -13,6 +13,7 @@ "execa": "^6.1.0", "markdown-table": "^3.0.3", "mri": "^1.2.0", - "port-authority": "^2.0.1" + "port-authority": "^2.0.1", + "pretty-bytes": "^6.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1fc7b08aa3..b548db06ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -72,6 +72,7 @@ importers: markdown-table: ^3.0.3 mri: ^1.2.0 port-authority: ^2.0.1 + pretty-bytes: ^6.0.0 dependencies: '@astrojs/node': link:../packages/integrations/node astro: link:../packages/astro @@ -80,6 +81,7 @@ importers: markdown-table: 3.0.3 mri: 1.2.0 port-authority: 2.0.1 + pretty-bytes: 6.1.0 examples/basics: specifiers: @@ -13377,7 +13379,6 @@ packages: /pretty-bytes/6.1.0: resolution: {integrity: sha512-Rk753HI8f4uivXi4ZCIYdhmG1V+WKzvRMg/X+M42a6t7D07RcmopXJMDNk6N++7Bl75URRGsb40ruvg7Hcp2wQ==} engines: {node: ^14.13.1 || >=16.0.0} - dev: true /pretty-format/3.8.0: resolution: {integrity: sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==}