Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use Node.js clusters with my simple Express app?
    primarykey
    data
    text
    <p>— I built a simple app that pulls in data (50 items) from a Redis DB and throws it up at localhost. I did an ApacheBench (c = 100, n = 50000) and I'm getting a semi-decent 150 requests/sec on a dual-core T2080 @ 1.73GHz (my 6 y.o laptop), but the proc usage is very disappointing as shown: <img src="https://i.stack.imgur.com/zuaIJ.png" alt="enter image description here"></p> <p>Only one core is used, which is as per design in Node, but I think I can nearly double my requests/sec to ~300, maybe even more, if I can use Node.js clusters. I fiddled around quite a bit but I haven't been able to figure out how to put the <a href="http://nodejs.org/docs/latest/api/cluster.html" rel="nofollow noreferrer">code given here</a> for use with my app which is listed below:</p> <pre><code>var express = require( 'express' ), app = express.createServer(), redis = require( 'redis' ).createClient(); app.configure( function() { app.set( 'view options', { layout: false } ); app.set( 'view engine', 'jade' ); app.set( 'views', __dirname + '/views' ); app.use( express.bodyParser() ); } ); function log( what ) { console.log( what ); } app.get( '/', function( req, res ) { redis.lrange( 'items', 0, 50, function( err, items ) { if( err ) { log( err ); } else { res.render( 'index', { items: items } ); } }); }); app.listen( 8080 ); </code></pre> <p>I also want to emphasize that the app is I/O intensive (not CPU-intensive, which would've made something like <a href="http://github.com/xk/node-threads-a-gogo" rel="nofollow noreferrer">threads-a-gogo</a> a better choice than clusters).</p> <p>Would love some help in figuring this out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload