About web application that handles thousands users
Imagine we are going to write an web app which concurrent users scales to thousands, how do we do?
1. Buy powerful server: more RAM, use SSD with RAID… Yeah it’s first thought to consider. But we can improve existing server capable by software tuning.
2. This is known as “C10K problem”. First we need to lift some Linux’s server params about networking and file open. It’s on the kernel, need tweaking and restart.
# Reference https://gist.github.com/jedi4ever/903751
fs.file-max = 999999
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
2. Why Nginx existed while there is Apache?
Because Nginx is event-driven server. Each request is handled as an event. On opposite, Apache spawned a new process / thread on each request, and occupies lot more memory and resources. That’s why Nginx is suitable for serving static contents much better than Apache. Using Nginx-like server may boost performance.
4. An important point is on traditional web application: app run, process requested and shutdown. App also has to start up, wait for synchronous I/O tasks, …
To handle more users, an alternative model is: App act as a server with event-driven processing model. NodeJS is successful story based on this approach.
For PHP, we can use ReactPHP.
For Python, we can use Tornado.
(I don’t know any solution with Ruby, RoR).
5. This picture is not complete, but I hope it helps to outline a plan to built faster and better web application solution.