var cluster = require('cluster'); var http = require('http'); var os = require('os');
var numCPUs = os.cpus().length;
var sleep = function(time_ms){ var startTime = newDate().getTime(); while (newDate().getTime() < startTime + time_ms); }
if (cluster.isMaster) { // Master: // Let's fork as many workers as you have CPU cores
for (var i = 0; i < numCPUs; ++i) { cluster.fork(); } } else { // Worker: // Let's spawn a HTTP server // (Workers can share any TCP connection. // In this case its a HTTP server)