http: refactor headersTimeout and requestTimeout logic

PR-URL: https://github.com/nodejs/node/pull/41263
Fixes: https://github.com/nodejs/node/issues/33440
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
This commit is contained in:
Paolo Insogna authored and GitHub committed 2022-04-13 15:47:59 +01:00
1 parent 9d6af7d1fe
commit 3caa2c1a00
33 files changed
+858 -413

No files matched your search

+3 -2
View File
@@ -32,10 +32,11 @@ function main({ len, n, c, duration }) {
send(n);
});
server.listen(common.PORT, () => {
server.listen(0, () => {
bench.http({
connections: c,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+5 -5
View File
@@ -32,7 +32,6 @@ function main({ dur, len, type, method }) {
headers: { 'Connection': 'keep-alive', 'Transfer-Encoding': 'chunked' },
agent: new http.Agent({ maxSockets: 1 }),
host: '127.0.0.1',
port: common.PORT,
path: '/',
method: 'POST'
};
@@ -40,16 +39,17 @@ function main({ dur, len, type, method }) {
const server = http.createServer((req, res) => {
res.end();
});
server.listen(options.port, options.host, () => {
server.listen(0, options.host, () => {
setTimeout(done, dur * 1000);
bench.start();
pummel();
pummel(server.address().port);
});
function pummel() {
function pummel(port) {
options.port = port;
const req = http.request(options, (res) => {
nreqs++;
pummel(); // Line up next request.
pummel(port); // Line up next request.
res.resume();
});
if (method === 'write') {
+3 -2
View File
@@ -48,10 +48,11 @@ function main({ len, type, method, c, duration }) {
fn(res);
});
server.listen(common.PORT, () => {
server.listen(0, () => {
bench.http({
connections: c,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+3 -2
View File
@@ -27,11 +27,12 @@ function main({ len, n, duration }) {
res.writeHead(200, headers);
res.end();
});
server.listen(common.PORT, () => {
server.listen(0, () => {
bench.http({
path: '/',
connections: 10,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+3 -2
View File
@@ -14,7 +14,7 @@ function main({ connections, headers, w, duration }) {
res.end();
});
server.listen(common.PORT, () => {
server.listen(0, () => {
const headers = {
'Content-Type': 'text/plain',
'Accept': 'text/plain',
@@ -34,7 +34,8 @@ function main({ connections, headers, w, duration }) {
path: '/',
connections,
headers,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+3 -4
View File
@@ -1,6 +1,5 @@
'use strict';
const common = require('../common.js');
const PORT = common.PORT;
const bench = common.createBenchmark(main, {
res: ['normal', 'setHeader', 'setHeaderWH'],
@@ -17,16 +16,16 @@ const c = 50;
// setHeader: statusCode = status, setHeader(...) x2
// setHeaderWH: setHeader(...), writeHead(status, ...)
function main({ res, duration }) {
process.env.PORT = PORT;
const server = require('../fixtures/simple-http-server.js')
.listen(PORT)
.listen(0)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`;
bench.http({
path: path,
connections: c,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+3 -2
View File
@@ -13,14 +13,15 @@ const bench = common.createBenchmark(main, {
function main({ type, len, chunks, c, chunkedEnc, duration }) {
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.listen(0)
.on('listening', () => {
const path = `/${type}/${len}/${chunks}/normal/${chunkedEnc}`;
bench.http({
path,
connections: c,
duration
duration,
port: server.address().port,
}, () => {
server.close();
});
+1 -1
View File
@@ -20,7 +20,7 @@ const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
function main({ n }) {
const server = require('../fixtures/simple-http-server.js')
.listen(common.PORT)
.listen(0)
.on('listening', () => {
bench.start();
doBench(server.address(), n, () => {