1234567891011121314151617181920212223242526272829 |
- #!/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);
- server.listen(port);
- }
|