Sunday, June 23, 2013

Optimize the OS to handle large number of concurrent requests

Theoretically Node.js can handle huge number of concurrent requests without blocking the application. This means server created using Node.js can handle concurrent requests without any problem unlike thread based server applications such as Apache servers.
I had to create a server application using Node.js to handle high level of concurrent requests. During the testing for higher level of concurrency one error I got was connect EMFILE . 
This error means that the OS is not allowing your program to open more files or sockets. So to handle higher levels of requests, you need to optimize the OS. We can do this by changeing the maximum number of files that can be open. To check the current limit in Linux system type
ulimit -n
For a Linux based system, this can be done using following instructions
One method is reset the limit for your current shell. This can be done easily by typing ulimit -n 4096. 4096 is the new maximum limit
The other way is by editing /etc/security/limits.conf file. open it using your favorite editor.
sudo gedit /etc/security/limits.conf
Add following two lines before the end of file
* soft nofile 4096
* hard nofile 65535
soft limit is the current value. Hard limit is the maximum limit. The soft value cannot exceed the hard value.Then logout and re login to your system. you can check the limit by  ulimit -n