Created
November 18, 2014 21:58
-
-
Save trevnorris/e1d53c124b6c94e3d57c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
var fork = require('child_process').fork; | |
var PORT = 7845; | |
var ITER = 1e4; | |
var MS = 100; | |
var SHUTDOWN = 1000 * 60; | |
var cntr = 0; | |
if (process.argv[2] === 'child') { | |
var server; | |
process.on('message', function removeMe(msg, clusterServer) { | |
if (clusterServer) | |
clusterServer.close(); | |
if (msg === 'stop') | |
process.removeListener('message', removeMe); | |
}); | |
return; | |
} | |
var server = dgram.createSocket('udp4'); | |
var child = fork(__filename, ['child']); | |
var msg = new Buffer('Some bytes'); | |
server.on('listening', function () { | |
setInterval(function() { | |
for (var i = 0; i < ITER; i++) { | |
child.send('server', server); | |
cntr++; | |
} | |
}, MS); | |
setTimeout(shutdown, SHUTDOWN); | |
}); | |
var shutdown = function () { | |
child.send('stop'); | |
process.exit(); | |
}; | |
server.bind(PORT, '127.0.0.1'); | |
process.on('exit', function() { | |
console.log('cntr: ' + cntr); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment