Skip to content

Instantly share code, notes, and snippets.

@jeffreytgilbert
Created April 3, 2014 21:56
Show Gist options
  • Save jeffreytgilbert/9963702 to your computer and use it in GitHub Desktop.
Save jeffreytgilbert/9963702 to your computer and use it in GitHub Desktop.
var
express = require( 'express' ),
connect = require('connect'),
app = express();
count = 0;
app.configure( function() {
app.use(connect.urlencoded());
app.use(connect.json());
});
function log( what ) { console.log( what ); }
app.get( '/', function( req, res ) {
count++;
res.end(count+' bottles of beer on the wall!');
});
app.listen( 8080 );
var cluster = require('cluster')
if ( cluster.isMaster ) {
for ( var i=0; i<8; ++i )
cluster.fork();
} else {
var
express = require( 'express' ),
connect = require( 'connect' ),
app = express(),
count = 0;
app.configure( function() {
app.use(connect.urlencoded());
app.use(connect.json());
});
function log( what ) { console.log( what ); }
app.get( '/', function( req, res ) {
count++;
res.end(count+' bottles of beer on the wall!');
});
app.listen( 8080 );
}
@sam-github
Copy link

Try using strong-supervisor, you can control worker count from command line (or strongops): https://github.com/strongloop/strong-supervisor

Not to tout our modules too much... but better than changing that 8 into other numbers.

@jeffreytgilbert
Copy link
Author

Definitely true. Was just testing the scaling limits of node cluster out of the box on version 0.10, and the performance gains weren't useful because of the native process scheduling. Varnish, nginx, HA proxy, etc are better solutions for this while we wait and see what kind of gains we can get from 0.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment