On our server we have a LOT of RAM for our traffic levels (16GB). The HTTP processes regularly eat up all CPU and need to be restarted without even getting close to using swap memory, so I’m looking for ways to spend RAM to ease the load on Apache (and/or help the seperate MySQL server which may be breaking Apache).
I have many WordPress installs on the HTTPD instance so APC sometimes uses as much as 900MB of ram (according to the apc.php charts). Just in case I have
apc.shm_size set to 1600MB which is more than it needs but not more than I can spare. This means there is usually lots of extra RAM available to APC but also very little turnover and fragmentation is never more than 1%.
Is this dangerous? Should I be slimming down APC to less than 1GB just on principle? Should I be expecting some turnover within APC in the name of bringing it’s overall footprint down?
Having so much memory devoted to APC means that in top/htop every single httpd process shows ~1.9GB in the VIRT memory column. Obviously this is shared memory and not used per-process, but could it be hurting our server?
NOTE: The problem with the server remains unclear but the effect is that about 60 times a day all 8 CPU’s fill up to 100% and everything stops working until Monit sees that Apache is broken and restarts it (Monin also saves the MySQL server). I’m not sure if APC is even part of the problem but I’m trying to optimize everything just in case.
Having so much allocated is usually excessive. In this instance, you may feel you need to, because of all the different files. What may be more useful is to reduce the number of files that need to be cached by merging the WordPress installs. In any event, if APC never reaches 1,000 MB used, having more than that is redundant.
How many MaxClients to set is a function of the busyness of the server, and particularly size of the resident portion of Apache and other programs. With 16GB of ram, even with say half of it allocated to Mysql (the InnoDB buffer pool – InnoDB controls member better than MyIsam, even at the cost of some more ram), a couple of hundred Apache processes is usually entirely enough (I was serving 10 million PHP hits per server per day and it averaged ~40 processes being used at a time).
Having the static images, css, JS etc served by NginX, sitting in front of (or on a seperate URL) the Apache server will also reduce the work that the heavier PHP-capable server is required to do – often very substantially. http://blogs.law.harvard.edu/djcp/2010/01/nginx-as-a-front-end-proxy-cache-for-wordpress/ has some thoughts on that, and there are other blogs and such that will walk you through installing Nginx in front of Apache, with or without WordPress being involved.
Finally, KeepAlives will mainly just kill a busy site. Turning them off is recommended now, to avoid just the sort of resource starvation you are seeing regularly. If, for example, you have set 100 MaxClients, and a KeepAlive of 30 seconds, than just 100 visitors within a 30 sec period would hold open all the Apache slots, and you can’t serve anything else.
Leave a comment
- Cron expression that runs every 5 minutes from 1:30 am – 6:00 am [duplicate]
- Understanding redundant power supplies
- Is there a way for administrators to disable users from installing Firefox extensions?
- Is there research material on NTP accuracy available?
- How to create a limited “domain admin” that does not have access to domain controllers?