4

I know that Node.js uses a single-thread and an event loop to process requests only processing one at a time (which is non-blocking). But i am unable to determine Event loop capacity to run 100k request per second.

Here i want to capacity planning for nodejs server to handle the 100k request per second.

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

Suresh Mahawar
  • 1,458
  • 15
  • 34

1 Answers1

4

A single instance of Node.js runs in a single thread. To take advantage of multi-core systems the user will sometimes want to launch a cluster of Node.js processes to handle the load.

More info here and here

For the reference check following code for simple implementation of cluster 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 check here.

svarog
  • 9,477
  • 4
  • 61
  • 77
Eugen Dimboiu
  • 2,733
  • 2
  • 26
  • 33
  • 1
    It would be better if you put a working code example rather than just posting links. – Shaharyar Dec 28 '16 at 10:40
  • @Eugen Dimboiu, You are right. but here i want to know that one event loop's capacity. if there is any tool to determine single event loop capacity or any other way, so that i can accordingly increase no of cpus. – Suresh Mahawar Dec 30 '16 at 05:01
  • As far as I know there is no specific tool for your need, but you can use any load testing tool to stress test your app. I think you'll need to design your app so it can scale horizontally with ease - 100k requests/second is a lot. – Eugen Dimboiu Dec 30 '16 at 12:50