Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
process.send blocks in node.js
$ node test
create: 678ms
send: 4445ms
200 ms passed, or not :/
got message: 5 MB
get: 4472ms
var MB = 1024 * 1024;
if (process.argv[2] === 'child') {
// create a 5 MB template
console.time('create');
var t = '', i = (MB * 5);
while(i--) {
t += 'a';
}
console.timeEnd('create');
setTimeout(function () {
console.log('200 ms passed, or not :/');
}, 200);
// start timer
process.send('a');
console.time('send');
process.send(t);
console.timeEnd('send');
} else {
var fork = require('child_process').fork;
var child = fork(process.argv[1], ['child']);
child.on('message', function (msg) {
var l = msg.length;
if (l === 1) {
console.time('get');
}
else {
console.log('got message: ' + (msg.length / MB) + ' MB');
console.timeEnd('get');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.