summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-03-03 11:55:31 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-03 11:55:31 +0800
commit13f6f591e352696558b58de160672d7dc6aa1771 (patch)
tree44e7346f33eab49414b3150f97d755a7af33d137
parent4a18d27f978506dee04ec17c26b66cf50789ad5e (diff)
downloadastro-13f6f591e352696558b58de160672d7dc6aa1771.tar.gz
astro-13f6f591e352696558b58de160672d7dc6aa1771.tar.zst
astro-13f6f591e352696558b58de160672d7dc6aa1771.zip
Improve server-stress benchmark comment (#6405)
-rw-r--r--benchmark/bench/server-stress.js41
-rw-r--r--benchmark/package.json3
-rw-r--r--pnpm-lock.yaml3
3 files changed, 37 insertions, 10 deletions
diff --git a/benchmark/bench/server-stress.js b/benchmark/bench/server-stress.js
index 6237b2e5f..1bb64375e 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 4233cbba9..34b486e97 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 1fc7b08aa..b548db06a 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==}