How to increase pipeline throughput in nodejs?

I know that Node.js uses a single-threaded and event loop to process requests that process only one at a time (which does not block). But I can not determine the throughput of the pipeline to run 100 thousand requests per second.

Here I want capacity planning for a nodejs server to handle a request of 100k per second .

Please let me know how I can determine the capacity of an event loop to increase capacity.

+4
source share
1 answer

One instance of Node.js runs in a single thread . To use multi-core systems, the user sometimes needs to start a cluster from Node.js processes to handle the load.

More here and here

For reference, check out the following code for a simple cluster implementation in Node.js

              var cluster = require('cluster');  
              var express = require('express');  
              var numCPUs = require('os').cpus().length;

              if (cluster.isMaster) {  
                  for (var i = 0; i < numCPUs; i++) {
                      // Create a worker
                      cluster.fork();
                  }
              } else {
                  // Workers share the TCP connection in this server
                  var app = express();

                  app.get('/', function (req, res) {
                      res.send('Hello World!');
                  });

                  // All workers use this port
                  app.listen(8080);
              }

Cluster is an extensible multi-core server manager for Node.js for more source checking here .

+4
source

Source: https://habr.com/ru/post/1665100/


All Articles