Friday, November 26, 2010

Web Server Issues

1. N/W  I/O
2. Disk I/O
3. CPU
4. Memory

A. Dig the root cause : too many processes may start thrashing,
which may seem like a Disk I/O problem, but actually is a memory

Tools : sar,systat,iostat,top,vmstat,nstat

Apache performance testing : TSUNG

Apache usually dies at 5000 concurrent connections.
It usually works in pre-fork/worker model.
Pre-fork : OS kernel does the load balancing.
Worker : Apache master process does the load balancing.

Usually every process spawns many threads.
A process has 4GB address virtual memory
shared by all its threads.
So, if there are too many, for e.g. 500, threads,
one thread may bajaao the band for everyone else.

So,it's better to have 5 processes with 100 threads each.

But in apache, creating many threads has its own problems : 
every thread has its kernel stack, process stack, which eats
up resources.

Lighttpd works on event driven model.
Accepts connections, passes the baton
to fast-cgi.exe, when it returns, lighttpd
returns to requester.

Since it is event driven, it scales better.

Work is on to make lighttpd work better on multiple cores,
so that it can spawn a different process for every core.

FrontEnd optimization : 
in .htaccess set headers(for e.g. TTL(time to live), time after which the client should fetch the image again) for static images.
caching proxy layer : varnish/squid : saves db query time, php script running time.
a separate caching layer, as opposed to php's in-built caching may help diagnose the issue better.
- proxy because caching runs at :80, server at :8080

you can also look into php opcode caching...


look at 31 yahoo tips, yahoo performance blog, mysql performance blog

If there are too many threads running, and you may be using external
libraries(code) from them, it's better to kill a thread after it has served
5000(n) requests. Since, after that it will have many memory leaks,
which will be hard to find.

No comments:

Blog Archive