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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

It would be better if you put a working code example rather than just posting links.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.