To KeepAlive or not to KeepAlive, that is the question
I'm using Apache on a Ubuntu 10.04 LTS VPS with 512mb of memory. My website gets a fair amount of hits. Some requests involve multiple files too – the PHP file, and related image, CSS, and/or Javascript files. I'm trying to maximize performance so I can get the most bang for my buck, and delay upgrading to a larger Linode.
In a situation like this, what do you guys do (enable or disable KeepAlive?), and what do you recommend?
5 Replies
In the end, it really depends on your situation. You really should look at your traffic and adjust for that.
Also, have you tried caching? That's usually the first thing to do and generally gives the greatest return.
First, if you are running mod_php, then every worker carries memory overhead of having it loaded, whether the request is for a static file, or not.
Second, whether a request is for a static file or a dynamic page, the worker that processed the request is occupied until all the data is sent to the client.
These two issues are combined and aggravated when using keep-alives.
I think the simplest solution: Continue using apache, it works, its well understood, but let it spend its time and memory on servicing requests, rather than feeding data back out to clients. The way you do this is to put nginx on port 80 on your public IP, apache on localhost, and then set nginx to reverse proxy to apache and enable buffering of results.
You can try and set nginx up to handle requests for static files, and only proxy dynamic requests to apache, but I don't think its worth it.
@eas:
First, if you are running mod_php, then every worker carries memory overhead of having it loaded, whether the request is for a static file, or not.
Second, whether a request is for a static file or a dynamic page, the worker that processed the request is occupied until all the data is sent to the client.
These two issues are combined and aggravated when using keep-alives.
I think the simplest solution: Continue using apache
… but switch from mpmprefork + modphp to mpmworker + modfastcgi (NOT fcgid!) and have for example a hundred worker threads and PHPFCGICHILDREN=25. This way you have only one webserver to worry about.