mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Improve server-stress benchmark comment (#6405)
This commit is contained in:
parent
4a18d27f97
commit
13f6f591e3
3 changed files with 37 additions and 10 deletions
|
@ -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}`;
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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==}
|
||||
|
|
Loading…
Reference in a new issue