Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17937

Apache vs Nginx explained

$
0
0

APACHE VS NGINX IS A FALSE DICHOTOMY

This argument is stupid, because it is comparing web-servers in a vacuum, you DO NOT do comparison that way. Here goes explanation of the my point.

THREAD PER CONNECTION VS FSM

Main concept to understand is how a web-server serves connections:

Apache uses thread-per-connection model:

Connection is initiated Thread to serve it is spawned Thread is killed only after connection is closed 

This way as we can see if we have 1000 slow connections then Apache WILL spawn 1000 threads and they will be active until all data to the clients is transferred. Overhead much.

If we have 1000 very fast connections it is mostly okay.

Nginx uses FSM approach:

Ngnix is launched, it spwans only a few threads (say, one per core) It subscribes to events using nonblocking IO Connection is initiated Ngnix receives events about it and one of the worker threads starts to serve it Threads are not spawned or killed, they just respond to incoming events 

This way, if we have say 1000 slow connections we will NOT have a huge memory and CPU (scheduling threads costs something) overhead.

What is important to understand is that due to Apache nature it loads a shared module (say php) in the worker thread and thus is faster if connection speed is huge. Nginx is NOT ABLE BY DESIGN to do this, so it uses for example php-fpm, which is SIMILAR, but NOT the same as Client <--> Nginx <--> Apache with mod_php.

BOTTOM LINE

Do NOT use stupid arguments like 'all the cool kids use nginx, cdn use nginx', which were used in the neighbor thread.

Understand how things work. Read documentation, some source code or just STRACE the fucking thing to see it for yourself. Do not repeat what others say without understanding. Religion is death.

Thanks much.

submitted by Damncommie123
[link][32 comments]

Viewing all articles
Browse latest Browse all 17937

Latest Images

Trending Articles



Latest Images