mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Increase the default HTTP/2 stream window from 64KB (65535) to 4MB (4194304) and the default local connection window to 32MB (33554432). The default 64KB window limits throughput on high-latency connections to window_size / RTT. With a 250ms RTT, throughput is limited to 256KB/s. The new defaults improve throughput to 16MB/s (128Mbps) for the stream window and 128MB/s (1Gbps) for the connection window. Fixes: https://github.com/nodejs/node/issues/38426 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64623 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
77 lines
2.5 KiB
JavaScript
77 lines
2.5 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const fixtures = require('../common/fixtures');
|
|
const http2 = require('http2');
|
|
|
|
// This test assesses whether long-running writes can complete
|
|
// or timeout because the session or stream are not aware that the
|
|
// backing stream is still writing.
|
|
// To simulate a slow client, we write a really large chunk and
|
|
// then proceed through the following cycle:
|
|
// 1) Receive first 'data' event and record currently written size
|
|
// 2) Once we've read up to currently written size recorded above,
|
|
// we pause the stream and wait longer than the server timeout
|
|
// 3) Socket.prototype._onTimeout triggers and should confirm
|
|
// that the backing stream is still active and writing
|
|
// 4) Our timer fires, we resume the socket and start at 1)
|
|
|
|
const writeSize = 33554432;
|
|
const minReadSize = 500000;
|
|
const serverTimeout = common.platformTimeout(500);
|
|
let offsetTimeout = common.platformTimeout(100);
|
|
const server = http2.createSecureServer({
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem'),
|
|
});
|
|
const onTimeout = common.mustCallAtLeast(0);
|
|
server.on('stream', common.mustCall((stream) => {
|
|
const content = Buffer.alloc(writeSize, 0x44);
|
|
|
|
stream.respond({
|
|
'Content-Type': 'application/octet-stream',
|
|
'Content-Length': content.length.toString(),
|
|
'Vary': 'Accept-Encoding',
|
|
});
|
|
|
|
stream.write(content);
|
|
stream.setTimeout(serverTimeout);
|
|
stream.on('timeout', onTimeout);
|
|
stream.end();
|
|
}));
|
|
server.setTimeout(serverTimeout);
|
|
server.on('timeout', onTimeout);
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const client = http2.connect(`https://localhost:${server.address().port}`,
|
|
{ rejectUnauthorized: false });
|
|
|
|
const req = client.request({ ':path': '/' });
|
|
req.end();
|
|
|
|
const resume = () => req.resume();
|
|
let receivedBufferLength = 0;
|
|
let firstReceivedAt;
|
|
req.on('data', common.mustCallAtLeast((buf) => {
|
|
if (receivedBufferLength === 0) {
|
|
firstReceivedAt = Date.now();
|
|
}
|
|
receivedBufferLength += buf.length;
|
|
if (receivedBufferLength >= minReadSize &&
|
|
receivedBufferLength < writeSize) {
|
|
receivedBufferLength = 0;
|
|
req.pause();
|
|
setTimeout(
|
|
resume,
|
|
serverTimeout + offsetTimeout - (Date.now() - firstReceivedAt)
|
|
);
|
|
offsetTimeout = 0;
|
|
}
|
|
}, 1));
|
|
req.on('end', common.mustCall(() => {
|
|
client.close();
|
|
server.close();
|
|
}));
|
|
}));
|