Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Actually, your workload is not really I/O bound: it is CPU bound due to the cost of jade-based dynamic page generation. I cannot guess the complexity of your jade template, but even with simple templates, generating HTML pages is expensive.</p> <p>For my tests I used this template:</p> <pre><code>html(lang="en") head title Example body h1 Jade - node template engine #container ul#users each user in items li User:#{user} </code></pre> <p>I added 100 dummy strings to the items key in Redis.</p> <p>On my box, I get 475 req/s with node.js CPU at 100% (which means 50% CPU consumption on this dual core box). Let's replace:</p> <pre><code>res.render( 'index', { items: items } ); </code></pre> <p>by:</p> <pre><code>res.send( '&lt;html lang="en"&gt;&lt;head&gt;&lt;title&gt;Example&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;h1&gt;Jade - node template engine&lt;/h1&gt;&lt;div id="container"&gt;&lt;ul id="users"&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;li&gt;User:NOTHING&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;' ); </code></pre> <p>Now, the result of the benchmark is close to 2700 req/s. So the bottleneck is clearly due to the formatting of the HTML page.</p> <p>Using the cluster package in this situation is a good idea, and it is straightforward. The code can be modified as follows:</p> <pre><code>var cluster = require('cluster') if ( cluster.isMaster ) { for ( var i=0; i&lt;2; ++i ) cluster.fork(); } else { 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>Now the result of the benchmark is close to 750 req/s with 100 % CPU consumption (to be compared with the initial 475 req/s).</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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