Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding an high performance node.js application with cluster and node-webworker
    primarykey
    data
    text
    <p>I'm not a node.js master, so I'd like to have more points of view about this.</p> <p>I'm creating an HTTP node.js web server that must handle not only lots of concurrent connections but also long running jobs. By default node.js runs on one process, and if there's a piece of code that takes a long time to execute any subsequent connection must wait until the code ends what it's doing on the previous connection.</p> <p>For example:</p> <pre><code>var http = require('http'); http.createServer(function (req, res) { doSomething(); // This takes a long time to execute // Return a response }).listen(1337, "127.0.0.1"); </code></pre> <p>So I was thinking to run all the long running jobs in separate threads using the <a href="https://github.com/pgriess/node-webworker">node-webworker</a> library:</p> <pre><code>var http = require('http'); var sys = require('sys'); var Worker = require('webworker'); http.createServer(function (req, res) { var w = new Worker('doSomething.js'); // This takes a long time to execute // Return a response }).listen(1337, "127.0.0.1"); </code></pre> <p>And to make the whole thing more performant, I thought to also use <a href="http://learnboost.github.com/cluster/">cluster</a> to create a new node process for each CPU core.</p> <p>In this way I expect to balance the client connections through different processes with <code>cluster</code> (let's say 4 node processes if I run it on a quad-core), and then execute the long running job on separate threads with <code>node-webworker</code>.</p> <p>Is there something wrong with this configuration?</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. 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