node/test/sequential/test-net-bytes-per-incoming-chunk-overhead.js
Ben L. Titzer 2550ddb049
test: increase limit for network space overhead test
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>
2019-07-15 00:29:19 +02:00

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`);
});