feat(bench): add NestJS (platform-express + platform-fastify) servers

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-07-06 23:30:40 -05:00
1 parent 7593d1425a
commit fe1831a80a
7 files changed
+737 -1

No files matched your search

+6
View File
@@ -174,6 +174,12 @@ function renderMethodology(): string {
'- **Content-type charset asymmetry (disclosed, not controlled)**: green-tea and raw-http send',
' `Content-Type: application/json` while Express and Fastify send `application/json; charset=utf-8`.',
' This is a minor header-byte asymmetry that is disclosed here rather than normalized away.',
'- **NestJS runs on an underlying adapter** (Express or Fastify): the `nestjs-express` / `nestjs-fastify`',
" rows measure Nest's DI / decorator / routing overhead **on top of** that adapter, so compare each",
' against its own base (`express` / `fastify`) rather than against the field. Nest\'s idiomatic',
' `ValidationPipe` / class-validator is **not** used — `/validate` performs the same manual field check',
' as every other server (parity). The same parity controls apply: `etag` and `x-powered-by` are disabled',
' on the underlying Express instance, and `keepAliveTimeout` is 5000 on both adapters.',
'',
].join('\n');
}
+1 -1
View File
@@ -87,7 +87,7 @@ async function measure(port: number, path: string, method: 'GET' | 'POST', body?
}
async function main(): Promise<void> {
const frameworks = ['raw-http', 'fastify', 'express', 'green-tea'];
const frameworks = ['raw-http', 'fastify', 'express', 'green-tea', 'nestjs-express', 'nestjs-fastify'];
const scenarioBlocks: ScenarioBlock[] = SCENARIOS.map((s) => ({
title: s.title,
name: s.name,
+20
View File
@@ -0,0 +1,20 @@
import { Module, Controller, Get, Post, Param, Body, HttpException, MiddlewareConsumer, NestModule } from '@nestjs/common';
@Controller()
export class BenchController {
@Get('hello') hello() { return { hello: 'world' }; }
@Get('users/:id') user(@Param('id') id: string) { return { id }; }
@Get('pipeline') pipeline() { return { hello: 'world', s3: 3 }; }
@Post('validate') validate(@Body() b: any) {
if (!(b && typeof b.email === 'string' && b.email.includes('@'))) throw new HttpException({ error: 'invalid' }, 422);
return { email: b.email };
}
}
// pipeline parity: 3 middleware hops on /pipeline (approximation of 3 @Steps), adapter-agnostic
const mw = (_n: number) => (_req: any, _res: any, next: any) => next();
@Module({ controllers: [BenchController] })
export class BenchModule implements NestModule {
configure(c: MiddlewareConsumer) { c.apply(mw(1), mw(2), mw(3)).forRoutes('pipeline'); }
}
+17
View File
@@ -0,0 +1,17 @@
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import express from 'express';
import { BenchModule } from './_nest-shared';
async function main() {
const inst = express();
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');
const server = app.getHttpServer();
server.keepAliveTimeout = 5000; // parity (works on Node http.Server after listen)
console.log(`READY ${server.address().port}`);
}
main().catch((e) => { console.error(e); process.exit(1); });
+13
View File
@@ -0,0 +1,13 @@
import 'reflect-metadata';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
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');
const server = app.getHttpServer();
console.log(`READY ${(server.address() as any).port}`);
}
main().catch((e) => { console.error(e); process.exit(1); });