test(bench): reach bench servers cross-host + add scale and Bun/Deno servers
CI / build (pull_request) Successful in 59s

Fastify and the Nest adapters bound 127.0.0.1, unreachable from a separate load generator; bind 0.0.0.0 so two-machine benchmarks work.

Adds scale-{green-tea,express} (step-vs-middleware depth sweeps that surfaced the O(n^2)) and green-tea-{bun,deno} (the same app served via serveBun/serveDeno, to benchmark across runtimes).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-17 19:05:52 -05:00
1 parent 642ef109b2
commit 3a4cd5a7ce
7 files changed
+129 -3

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ app.post('/validate', {
if (!b.email.includes('@')) { reply.code(422); return { error: 'invalid' }; }
return { email: b.email };
});
app.listen({ port: 0 }, (err, addr) => {
app.listen({ port: 0, host: '0.0.0.0' }, (err, addr) => {
if (err) { console.error(err); process.exit(1); }
console.log(`READY ${Number(new URL(addr).port)}`);
});
+34
View File
@@ -0,0 +1,34 @@
import 'reflect-metadata';
import { createApp, Step, Route, Get, Post, Module, needs, param, body } from '../../dist/index.mjs';
import { serveBun } from '../../dist/bun.mjs';
// Same BenchModule as green-tea.ts (Node), served via Bun.serve instead of app.listen.
const emailSchema = {
'~standard': { version: 1 as const, vendor: 'bench', validate: (v: any) =>
(v && typeof v.email === 'string' && v.email.includes('@')) ? { value: v } : { issues: [{ message: 'invalid email' }] } },
};
function makeStep(n: number) {
@Step({ provides: `s${n}`, needs: n > 1 ? [`s${n - 1}`] : [] })
class S { run() { return { [`s${n}`]: n }; } }
return S;
}
const steps = [1, 2, 3, 4, 5].map(makeStep);
@Route('/')
class Bench {
@Get('/hello') hello() { return { hello: 'world' }; }
@Get('/users/:id') user(@param('id') id: string) { return { id }; }
@Get('/pipeline') pipeline(@needs('s3') s3: number) { return { hello: 'world', s3 }; }
@Post('/validate') validate(@body(emailSchema) b: any) { return { email: b.email }; }
@Get('/steps/0') steps0() { return { hello: 'world' }; }
@Get('/steps/3') steps3(@needs('s3') s3: number) { return { hello: 'world', s3 }; }
@Get('/steps/5') steps5(@needs('s5') s5: number) { return { hello: 'world', s5 }; }
}
@Module({ mountpoint: '/', steps, controllers: [Bench] })
class BenchModule {}
const app = createApp({ modules: [BenchModule], security: false });
const server = serveBun(app, { port: 0, hostname: '0.0.0.0' });
console.log(`READY ${server.port}`);
+33
View File
@@ -0,0 +1,33 @@
import 'reflect-metadata';
import { createApp, Step, Route, Get, Post, Module, needs, param, body } from '../../dist/index.mjs';
import { serveDeno } from '../../dist/deno.mjs';
// Same BenchModule as green-tea.ts (Node), served via Deno.serve instead of app.listen.
const emailSchema = {
'~standard': { version: 1 as const, vendor: 'bench', validate: (v: any) =>
(v && typeof v.email === 'string' && v.email.includes('@')) ? { value: v } : { issues: [{ message: 'invalid email' }] } },
};
function makeStep(n: number) {
@Step({ provides: `s${n}`, needs: n > 1 ? [`s${n - 1}`] : [] })
class S { run() { return { [`s${n}`]: n }; } }
return S;
}
const steps = [1, 2, 3, 4, 5].map(makeStep);
@Route('/')
class Bench {
@Get('/hello') hello() { return { hello: 'world' }; }
@Get('/users/:id') user(@param('id') id: string) { return { id }; }
@Get('/pipeline') pipeline(@needs('s3') s3: number) { return { hello: 'world', s3 }; }
@Post('/validate') validate(@body(emailSchema) b: any) { return { email: b.email }; }
@Get('/steps/0') steps0() { return { hello: 'world' }; }
@Get('/steps/3') steps3(@needs('s3') s3: number) { return { hello: 'world', s3 }; }
@Get('/steps/5') steps5(@needs('s5') s5: number) { return { hello: 'world', s5 }; }
}
@Module({ mountpoint: '/', steps, controllers: [Bench] })
class BenchModule {}
const app = createApp({ modules: [BenchModule], security: false });
serveDeno(app, { port: 0, hostname: '0.0.0.0', onListen: (a: { port: number }) => console.log(`READY ${a.port}`) });
+1 -1
View File
@@ -9,7 +9,7 @@ async function main() {
inst.disable('x-powered-by');
inst.set('etag', false);
const app = await NestFactory.create(BenchModule, new ExpressAdapter(inst), { logger: false });
await app.listen(0, '127.0.0.1');
await app.listen(0, '0.0.0.0');
const server = app.getHttpServer();
server.keepAliveTimeout = 5000; // parity (works on Node http.Server after listen)
console.log(`READY ${server.address().port}`);
+1 -1
View File
@@ -6,7 +6,7 @@ import { BenchModule } from './_nest-shared';
async function main() {
const adapter = new FastifyAdapter({ logger: false, keepAliveTimeout: 5000 }); // parity via constructor
const app = await NestFactory.create<NestFastifyApplication>(BenchModule, adapter, { logger: false });
await app.listen(0, '127.0.0.1');
await app.listen(0, '0.0.0.0');
const server = app.getHttpServer();
console.log(`READY ${(server.address() as any).port}`);
}
+26
View File
@@ -0,0 +1,26 @@
import express from 'express';
// Express counterpart: /chain/N runs N trivial middlewares before the handler —
// the closest apples-to-apples to green-tea's N chained steps.
const app = express();
app.disable('x-powered-by');
app.set('etag', false);
const mw = (_req: any, _res: any, next: any) => next();
function route(path: string, n: number): void {
const chain = Array.from({ length: n }, () => mw);
app.get(path, ...chain, (_req, res) => { res.json({ ok: 1 }); });
}
route('/chain/0', 0);
route('/chain/10', 10);
route('/chain/25', 25);
route('/chain/50', 50);
route('/chain/75', 75);
route('/chain/100', 100);
const server = app.listen(0, () => {
server.keepAliveTimeout = 5000;
console.log(`READY ${(server.address() as any).port}`);
});
+33
View File
@@ -0,0 +1,33 @@
import 'reflect-metadata';
import { createApp, Step, Route, Get, Module, needs } from '../../src/index';
// 100 chained steps: s1..s100, each needs the previous. A route that @needs the Nth
// pulls exactly N steps transitively — so /chain/100 runs the full 100-deep graph slice.
function makeStep(n: number) {
@Step({ provides: `s${n}`, needs: n > 1 ? [`s${n - 1}`] : [] })
class S { run() { return { [`s${n}`]: n }; } }
return S;
}
const steps = Array.from({ length: 100 }, (_, i) => makeStep(i + 1));
@Route('/chain')
class Chain {
@Get('/0') d0() { return { ok: 1 }; }
@Get('/10') d10(@needs('s10') s: number) { return { s }; }
@Get('/25') d25(@needs('s25') s: number) { return { s }; }
@Get('/50') d50(@needs('s50') s: number) { return { s }; }
@Get('/75') d75(@needs('s75') s: number) { return { s }; }
@Get('/100') d100(@needs('s100') s: number) { return { s }; }
}
@Module({ mountpoint: '/', steps, controllers: [Chain] })
class ScaleModule {}
const app = createApp({ modules: [ScaleModule], security: false });
async function main() {
const server = await app.listen(0);
server.keepAliveTimeout = 5000;
console.log(`READY ${(server.address() as any).port}`);
}
main().catch((e) => { console.error(e); process.exit(1); });