Skip to content

Commit cbbdc29

Browse files
bzozjoaocgreis
authored andcommitted
benchmark: fix child-process-read on Windows
Under Windows 'ipc' communication requires the other process to format its messages with 'IPC framing protocol'. Otherwise, an assert is triggered in libuv. This commit changes child-process-read benchmark to use stdout to communicate with parent process. It also adds child-process-read-ipc.js to benchmark IPC communication using child node process. PR-URL: #6971 Reviewed-By: João Reis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0cd0118 commit cbbdc29

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
if (process.argv[2] === 'child')
3+
{
4+
const len = +process.argv[3];
5+
const msg = `"${'.'.repeat(len)}"`;
6+
while (true) {
7+
process.send(msg);
8+
}
9+
} else {
10+
const common = require('../common.js');
11+
const bench = common.createBenchmark(main, {
12+
len: [64, 256, 1024, 4096, 32768],
13+
dur: [5]
14+
});
15+
const spawn = require('child_process').spawn;
16+
function main(conf) {
17+
bench.start();
18+
19+
const dur = +conf.dur;
20+
const len = +conf.len;
21+
22+
const options = { 'stdio': ['ignore', 'ignore', 'ignore', 'ipc'] };
23+
const child = spawn(process.argv[0],
24+
[process.argv[1], 'child', len], options);
25+
26+
var bytes = 0;
27+
child.on('message', function(msg) {
28+
bytes += msg.length;
29+
});
30+
31+
setTimeout(function() {
32+
child.kill();
33+
const gbits = (bytes * 8) / (1024 * 1024 * 1024);
34+
bench.end(gbits);
35+
}, dur * 1000);
36+
}
37+
}

benchmark/child_process/child-process-read.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
'use strict';
22
const common = require('../common.js');
3+
const os = require('os');
4+
5+
var messagesLength = [64, 256, 1024, 4096];
6+
// Windows does not support that long arguments
7+
if (os.platform() !== 'win32')
8+
messagesLength.push(32768);
9+
310
const bench = common.createBenchmark(main, {
4-
len: [64, 256, 1024, 4096, 32768],
11+
len: messagesLength,
512
dur: [5]
613
});
714

@@ -13,11 +20,11 @@ function main(conf) {
1320
const len = +conf.len;
1421

1522
const msg = '"' + Array(len).join('.') + '"';
16-
const options = {'stdio': ['ignore', 'ipc', 'ignore']};
23+
const options = { 'stdio': ['ignore', 'pipe', 'ignore'] };
1724
const child = spawn('yes', [msg], options);
1825

1926
var bytes = 0;
20-
child.on('message', function(msg) {
27+
child.stdout.on('data', function(msg) {
2128
bytes += msg.length;
2229
});
2330

0 commit comments

Comments
 (0)