Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js maxing out at 1000 concurrent connections

We're benchmarking node performance using a simple Hello World node server on AWS (EC2).

No matter what size instance we use Node always appears to max out at 1000 concurrent connections (this is NOT 1000 per second, but 1000 it can handle at 1 time). Shortly after that the CPU spikes and node basically freezes.

Node v0.10.5

var http = require('http'); var server = http.createServer(function (req, res) {     res.writeHead(200, {'Content-Type': 'text/plain'});     res.end('loaderio-dec86f35bc8ba1b9b604db6c328864c1'); }); server.maxHeadersCount = 0; server.listen(4000); 

Node should be able to handle more than this correct? Any thoughts would be greatly appreciated.

Also the file descriptors (soft, hard, system) are set to 65096)

like image 674
jadent Avatar asked Jun 10 '13 22:06

jadent


People also ask

How many concurrent connections can Nodejs handle?

To address these issues, Node. JS uses a single thread with an event-loop. In this way, Node can handle 1000s of concurrent connections without any of the traditional detriments associated with threads. There is essentially no memory overhead per-connection, and there is no context switching.

How many Websocket connections can Nodejs handle?

The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil).

CAN node js handle high traffic?

In this article, we will consider some practices that you should adopt to scale your Node. js servers. Your servers will then be able to handle high traffic workloads without a degraded user experience.

How many clients can Nodejs handle?

Answer to your question. This is what I got on a very busy system with very little free RAM available so your mileage may vary. But it served 10,000 connections at the same time so the answer to your question is: it can handle a lot of requests, at least 10,000.


2 Answers

Use the posix module to raise the limit on the number of file descriptors your process can use.

Install posix

npm install posix 

Then in your code that runs when you launch your app...

var posix = require('posix');  // raise maximum number of open file descriptors to 10k, // hard limit is left unchanged posix.setrlimit('nofile', { soft: 10000 }); 
like image 129
Daniel Avatar answered Sep 27 '22 17:09

Daniel


You've reached the default limit of file descriptors a process can use (1024). You can check the limit on the command line by running "ulimit -n". To change the limit, you need to edit /etc/security/limits.conf. Add the follow block:

* soft nofile 65535 * hard nofile 65535 root soft nofile 65535 root hard nofile 65535 

"*" applies to all users except root. Limits for root must be added separately. There are soft and hard limit. Users are allowed to change their own limits up to the soft limit but not exceeding the hard limit.

Once the file has been edited, log out and back in again. Verify the change by running ulimit -n. Restart your Node process and you should be good to go.

There's also a system-wide file descriptor limit that can be increased with the following command:

sysctl -w fs.file-max=65535 
like image 22
BadCanyon Avatar answered Sep 27 '22 15:09

BadCanyon