123456789101112131415161718192021222324252627282930 |
- #!/usr/bin/env node --harmony --trace_gc
- var cluster = require('cluster');
- var http = require('http');
- if (cluster.isMaster) {
- var num = require('os').cpus().length;
- num = 4;
- for (var i = 0; i < num; i++) {
- cluster.fork();
- }
- cluster.on('exit', function(worker, code, signal) {
- console.error('worker ' + worker.process.pid + ' died');
- cluster.fork();
- });
- cluster.on('listening', function(worker, address) {
- console.log("A worker with #" + worker.id + " is now connected to "
- + address.address + ":" + address.port);
- });
- } else {
- var app = require('./app.js');
- var port = process.env.PORT || '3000';
- app.set('port', port);
- var server = http.createServer(app);
-
- require('./ws.js');
- server.listen(port);
- }
|