Files
Tim Perry 214cf0693b http: improve performance with known-length calls to end()
This boosts RPS performance for the common API case where you call
`res.end(data)` with the entire response by up to 9%.

Signed-off-by: Tim Perry <pimterry@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/65466
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-08-24 09:54:15 +00:00

36 lines
766 B
JavaScript

// Responses sent as a single res.end(string) with a known Content-Length -
// the shape a JSON or HTML endpoint produces.
'use strict';
const common = require('../common.js');
const bench = common.createBenchmark(main, {
len: [4, 64, 1024, 16384, 102400],
c: [50],
duration: 5,
});
function main({ len, c, duration }) {
const http = require('http');
const body = 'a'.repeat(len);
const headers = {
'Content-Type': 'text/plain',
'Content-Length': `${len}`,
};
const server = http.createServer((req, res) => {
res.writeHead(200, headers);
res.end(body);
});
server.listen(0, () => {
bench.http({
connections: c,
duration,
port: server.address().port,
}, () => {
server.close();
});
});
}