Skip to content

Instantly share code, notes, and snippets.

@stagas
Created May 12, 2012 09:43
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 stagas/2665565 to your computer and use it in GitHub Desktop.
Save stagas/2665565 to your computer and use it in GitHub Desktop.
var n = +(process.argv[2] || 10000)
var cp = require('child_process')
var child = cp.fork(__dirname + '/worker.js')
console.log('trying', n, 'messages')
var total = n
child.on('message', function () {
if (!--total) console.log('completed %d roundtrips', n - total)
else if (!(total % 1000)) console.log('%d roundtrips', n - total)
})
for (var i = n; i--;) {
child.send('a')
}
var r = 0
process.on('message', function () {
process.send('b')
if (!(r % 1000)) console.log('received: %d', ++r)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment