mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
refactor(): Rewrite benchmark script to TS
This commit is contained in:
@@ -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
|
|
||||||
@@ -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
|
|
||||||
@@ -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",
|
||||||
|
|||||||
1
tools/benchmarks/check-benchmarks.ts
Normal file
1
tools/benchmarks/check-benchmarks.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
// TODO: implement @krzkaczor
|
||||||
48
tools/benchmarks/get-benchmarks.ts
Normal file
48
tools/benchmarks/get-benchmarks.ts
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user