mirror of
https://github.com/nodejs/node.git
synced 2025-05-07 15:35:41 +00:00

This test imposes a limit on the average bytes of space per chunk for network traffic. However this number depends on VM implementation details, and upcoming changes to V8's array buffer management require a small bump to this limit in this test. PR-URL: https://github.com/nodejs/node/pull/28492 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Flags: --expose-gc
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
// Tests that, when receiving small chunks, we do not keep the full length
|
|
// of the original allocation for the libuv read call in memory.
|
|
|
|
let client;
|
|
let baseRSS;
|
|
const receivedChunks = [];
|
|
const N = 250000;
|
|
|
|
const server = net.createServer(common.mustCall((socket) => {
|
|
baseRSS = process.memoryUsage().rss;
|
|
|
|
socket.setNoDelay(true);
|
|
socket.on('data', (chunk) => {
|
|
receivedChunks.push(chunk);
|
|
if (receivedChunks.length < N) {
|
|
client.write('a');
|
|
} else {
|
|
client.end();
|
|
server.close();
|
|
}
|
|
});
|
|
})).listen(0, common.mustCall(() => {
|
|
client = net.connect(server.address().port);
|
|
client.setNoDelay(true);
|
|
client.write('hello!');
|
|
}));
|
|
|
|
process.on('exit', () => {
|
|
global.gc();
|
|
const bytesPerChunk =
|
|
(process.memoryUsage().rss - baseRSS) / receivedChunks.length;
|
|
// We should always have less than one page (usually ~ 4 kB) per chunk.
|
|
assert(bytesPerChunk < 600, `measured ${bytesPerChunk} bytes per chunk`);
|
|
});
|