Skip to content

Instantly share code, notes, and snippets.

@AndreasMadsen
Created January 23, 2012 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndreasMadsen/1663885 to your computer and use it in GitHub Desktop.
Save AndreasMadsen/1663885 to your computer and use it in GitHub Desktop.
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