Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use Cluster to get around the single threaded reliability issue. <a href="http://nodejs.org/api/cluster.html" rel="nofollow">Cluster</a> is one of the built in libraries and you can configure it to launch one or (n) number of worker instances. Typically you launch an instance for every CPU core in the server. The main process monitors events from the worker processes (I am not sure process is 100% the correct term) and can catch terminations, log them, and than restart the workers. Ideally you will also want to have multiple web servers regionally located and a load balancer that can monitor your web servers, detect when they are overloaded or not responding and take appropriate actions such as launching new instances and killing dead ones </p> <p>Typical code to use cluster looks like this (based on example in the cluster documentation):</p> <pre><code>var cluster = require('cluster'); var http = require('http'); var numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. for (var i = 0; i &lt; numCPUs; i++) { cluster.fork(); } cluster.on('exit', function(worker, code, signal) { console.log('worker ' + worker.process.pid + ' died'); // restart this instance cluster.fork(); }); } else { // create an error handler for uncaught exceptions so we can log them process.on('uncaughtException', function(err) { var date = new Date (); var message = date.toString () + ":UNCAUGHT EXCEPTION\n" + err.stack + "\n"; console.log (message); process.exit(1); // we will get restarted by the cluster process }); // Workers can share any TCP connection // In this case its a HTTP server http.createServer(function(req, res) { res.writeHead(200); res.end("hello world\n"); }).listen(8000); } </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. 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