Files
663c9151cf bench: render-pipeline benchmarks and stress routes (2/8) (#89863)
## Summary

Benchmark infrastructure for measuring render pipeline performance.

- **render-pipeline benchmark** (`bench/render-pipeline/`):
`benchmark.ts` for profiling render paths, `analyze-profiles.ts` for CPU
profile analysis
- **Stress routes** (`bench/basic-app/app/streaming/`): light, medium,
heavy, bulk, wide, chunkstorm variants for different streaming load
profiles
- **Basic app harness**: `benchmark.sh` runner script, `next.config.js`
- **Minimal server**: `bench/next-minimal-server/bin/minimal-server.js`
- **Docs**: `bench/BENCHMARKING.md` guide
- **Config**: eslint exclusion for bench paths, package.json bench
scripts

## Test plan

- [ ] No runtime behavior changes
- [ ] Benchmark scripts are standalone tooling

---------

Co-authored-by: Tim Neutkens <[email protected]>
2026-02-17 09:40:26 +01:00

58 lines
1.3 KiB
JavaScript
Executable File

#!/usr/bin/env node
process.env.NODE_ENV = 'production'
require('../../../test/lib/react-channel-require-hook')
console.time('next-cold-start')
const NextServer = require('next/dist/server/next-server').default
const path = require('path')
const appDir = process.cwd()
const distDir = '.next'
const compiledConfig = require(
path.join(appDir, distDir, 'required-server-files.json')
).config
process.chdir(appDir)
const nextServer = new NextServer({
conf: compiledConfig,
dir: appDir,
distDir,
minimalMode: true,
customServer: false,
})
const requestHandler = nextServer.getRequestHandler()
const port = parseInt(process.env.PORT, 10) || 3000
const server = require('http').createServer((req, res) => {
return requestHandler(req, res)
})
server.listen(port, () => {
console.timeEnd('next-cold-start')
console.log('Listening on port ' + port)
})
let shuttingDown = false
function shutdown() {
if (shuttingDown) return
shuttingDown = true
// Allow Node to exit cleanly so --cpu-prof/--heap-prof outputs are flushed.
server.close(() => {
process.exit(0)
})
// Fallback in case active keep-alive connections prevent close callback.
setTimeout(() => {
process.exit(1)
}, 5000).unref()
}
process.on('SIGTERM', shutdown)
process.on('SIGINT', shutdown)