refactor(): Rewrite benchmark script to TS

This commit is contained in:
Livio Brunnner
2019-08-29 10:53:15 +02:00
parent f0d0ded2d7
commit ade87e1284
5 changed files with 51 additions and 38 deletions

View File

@@ -1,14 +0,0 @@
#!/usr/bin/env bash
echo 'Library:' $1
node $1 &
pid=$!
sleep 2
wrk 'http://localhost:3000' \
-d 10 \
-c 1024 \
-t 8
kill $pid

View File

@@ -1,23 +0,0 @@
#!/usr/bin/env bash
: > all_output.txt
lib=(express fastify nest nest-fastify)
for item in ${lib[*]}
do
echo '-----------------------' >> all_output.txt
echo $item >> all_output.txt
echo '-----------------------' >> all_output.txt
node $item &
pid=$!
sleep 2
wrk 'http://localhost:3000' \
-d 10 \
-c 1024 \
-t 8 >> all_output.txt
kill $pid
done

View File

@@ -130,7 +130,8 @@
"supertest": "4.0.2", "supertest": "4.0.2",
"ts-node": "8.3.0", "ts-node": "8.3.0",
"tslint": "5.19.0", "tslint": "5.19.0",
"typescript": "3.5.3" "typescript": "3.5.3",
"wrk": "^1.2.0"
}, },
"collective": { "collective": {
"type": "opencollective", "type": "opencollective",

View File

@@ -0,0 +1 @@
// TODO: implement @krzkaczor

View File

@@ -0,0 +1,48 @@
import wrkPkg = require('wrk');
import { spawn } from 'child_process';
import { join } from 'path';
const wrk = (options: any) =>
new Promise((resolve, reject) =>
wrkPkg(options, (err: any, result: any) =>
err ? reject(err) : resolve(result),
),
);
const sleep = (time: number) =>
new Promise(resolve => setTimeout(resolve, time));
const BENCHMARK_PATH = join(__dirname, '../../benchmarks');
const LIBS = ['express', 'fastify', 'nest', 'nest-fastify'];
async function runBenchmarkOfLib(lib: string) {
const libPath = join(BENCHMARK_PATH, `${lib}.js`);
const process = spawn('node', [libPath], {
detached: true,
stdio: 'ignore'
});
process.unref();
await sleep(2000);
const result = await wrk({
threads: 8,
duraton: '10s',
connections: 1024,
url: 'http://localhost:3000',
});
process.kill();
return result;
}
export async function getBenchmarks() {
const results = {};
for await (const lib of LIBS) {
const result = await runBenchmarkOfLib(lib);
results[lib] = result;
}
return results;
}