Creating a high-performance node.js application with a cluster and node -webworker

I am not a node.js master, so I would like to have more points of view about this.

I am creating an HTTP node.js web server that should handle not only many simultaneous connections, but also lengthy work tasks. By default, node.js runs in one process, and if the part of the code that takes a long time to complete any subsequent connection must wait until the code finishes what it does in the previous connection.

For instance:

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");

So, I was thinking of starting all lengthy work tasks in separate threads using the node-webworker library :

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");

, cluster node .

, cluster (, 4 node , ), node-webworker.

- ?

+5
3

, , , - .

" node.js , , , , , ."

^ - . doSomething(); , , , , Asynchronous node.js , .

, , , :

setTimeout(function(){
    console.log("Done with 5 second item");
}, 5000);

, , , .

+3

JXcore,

$ jx mt-keep:4 mysourcefile.js

, . , , JX. 100% node.JS 0,12+ . node.js .

+1

You might want to check out Q-Oper8 as it should provide a more flexible architecture for this kind of thing. Full information:

https://github.com/robtweed/Q-Oper8

0
source

All Articles