Improve server-stress benchmark comment (#6405)

This commit is contained in:
Bjorn Lu 2023-03-03 11:55:31 +08:00 committed by GitHub
parent 4a18d27f97
commit 13f6f591e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 10 deletions

View file

@ -3,6 +3,8 @@ import { fileURLToPath } from 'url';
import autocannon from 'autocannon'; import autocannon from 'autocannon';
import { execaCommand } from 'execa'; import { execaCommand } from 'execa';
import { waitUntilBusy } from 'port-authority'; import { waitUntilBusy } from 'port-authority';
import { markdownTable } from 'markdown-table';
import pb from 'pretty-bytes';
import { astroBin } from './_util.js'; import { astroBin } from './_util.js';
const port = 4321; const port = 4321;
@ -45,14 +47,7 @@ export async function run(projectDir, outputFile) {
console.log('Result preview:'); console.log('Result preview:');
console.log('='.repeat(10)); console.log('='.repeat(10));
console.log(`#### Server stress\n\n`); console.log(`#### Server stress\n\n`);
let text = autocannon.printResult(result); console.log(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('='.repeat(10)); console.log('='.repeat(10));
console.log('Done!'); console.log('Done!');
@ -83,3 +78,33 @@ async function benchmarkCannon() {
autocannon.track(instance, { renderResultsTable: false }); 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}`;
}

View file

@ -13,6 +13,7 @@
"execa": "^6.1.0", "execa": "^6.1.0",
"markdown-table": "^3.0.3", "markdown-table": "^3.0.3",
"mri": "^1.2.0", "mri": "^1.2.0",
"port-authority": "^2.0.1" "port-authority": "^2.0.1",
"pretty-bytes": "^6.0.0"
} }
} }

View file

@ -72,6 +72,7 @@ importers:
markdown-table: ^3.0.3 markdown-table: ^3.0.3
mri: ^1.2.0 mri: ^1.2.0
port-authority: ^2.0.1 port-authority: ^2.0.1
pretty-bytes: ^6.0.0
dependencies: dependencies:
'@astrojs/node': link:../packages/integrations/node '@astrojs/node': link:../packages/integrations/node
astro: link:../packages/astro astro: link:../packages/astro
@ -80,6 +81,7 @@ importers:
markdown-table: 3.0.3 markdown-table: 3.0.3
mri: 1.2.0 mri: 1.2.0
port-authority: 2.0.1 port-authority: 2.0.1
pretty-bytes: 6.1.0
examples/basics: examples/basics:
specifiers: specifiers:
@ -13377,7 +13379,6 @@ packages:
/pretty-bytes/6.1.0: /pretty-bytes/6.1.0:
resolution: {integrity: sha512-Rk753HI8f4uivXi4ZCIYdhmG1V+WKzvRMg/X+M42a6t7D07RcmopXJMDNk6N++7Bl75URRGsb40ruvg7Hcp2wQ==} resolution: {integrity: sha512-Rk753HI8f4uivXi4ZCIYdhmG1V+WKzvRMg/X+M42a6t7D07RcmopXJMDNk6N++7Bl75URRGsb40ruvg7Hcp2wQ==}
engines: {node: ^14.13.1 || >=16.0.0} engines: {node: ^14.13.1 || >=16.0.0}
dev: true
/pretty-format/3.8.0: /pretty-format/3.8.0:
resolution: {integrity: sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==} resolution: {integrity: sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==}