Best Apache Settings
  • Hi everyone,

    Im new to managing my own server and having some troubles so far.

    I have intovps small package.

    I have webmin installed, php, mysql and centos 6.2 64bit.

    Im seeing these errors from time to time, and webmin dies and site becomes slow or unresponsive.

    [Mon Jan 30 21:34:41 2012] [error] (12)Cannot allocate memory: fork: Unable to fork new process
    [Mon Jan 30 21:34:51 2012] [error] (12)Cannot allocate memory: fork: Unable to fork new process

    I contacted intovps support and they replied "kernel memory was exceeded", i looked in "intovps hypanel" and the kernel memory increased from 10mb to 40mb in one spike. But my overall memory usage remained around 400mb. So it was just my kernel memory that spiked too high, not overall memory.

    Why does it do this? What affects kernel memory?

    I looked a tweaking apache settings, we now have this


    StartServers 10
    MinSpareServers 5
    MaxSpareServers 10
    ServerLimit 150
    MaxClients 150
    MaxRequestsPerChild 50


    What settings do you use for apache? Is mine correct?

    I have a blog and forum site, which sometimes spikes up to 600 users online for short times, when news is posted. My CPU usage is usually 0 and never goes high. Just seem to have this memory issue and finding the correct apache settings.

    Thank you for any help you can give
  • Hi Webhype,

    The Apache settings you have are correct overall.
    You can modify the MaxClients and ServerLimit to something lower, like 100, it should be enough. The kernel memory usually increases with the number of processes in a VPS and it's an extra memory that is not taken into account by the overall limit and has it's own limit.
    MaxRequestsPerChild is set ok, but can also be increased to 100 for example. What I do not see here is the keepalive setting which should be off especially when you have spikes.
    If your KeepAlive setting is on,please change it to off and see how the VPS is handling a spike in traffic. If you still have issues please send us an e-mail and ask for me. I will look over your VPS and see if there is something else that needs to be changed.

    Regards,
    Tomoiaga Cristian
  • Thank you for your suggestions. I had to change my settings yesterday after using the above settings, i saw memory keep increasing (from 300mb to 900mb) and nearly hit my limit. I now have these settings.


    StartServers 2
    MinSpareServers 5
    MaxSpareServers 5
    ServerLimit 500
    MaxClients 500
    MaxRequestsPerChild 4000


    KeepAlive is off.

    This seems to keep memory around 400mb and it does not keep on increasing as per the last settings, processes are around 25-30, CPU load is 0.03 (1 min) 0.03 (5 mins) 0.00 (15 mins).

    I'v no idea if this is better but it seems to be working lol.

    When we have traffic spike, it does "hang" a little bit for maybe 5secs+ then the page loads so im not sure if i need to increase something or lower something?
  • Do you by any chance use Apache with threads or with prefork ?
  • i believe its prefork
  • You may try to use Apache with event or worker if you are not using mod_php and also use the ulimit setting mentioned in our kb articles to reduce the memory usage when you have traffic spikes.
  • Your apache settings are terrible. They are probably the reason you are running out of memory. I suggest these settings:

    StartServers 2
    MinSpareServers 1
    MaxSpareServers 3
    ServerLimit 7
    MaxClients 7
    MaxRequestsPerChild 100

    Also turn on keepalive like this:

    keepalive on
    keepaliverequests 75
    keepalivetimeout 3

    Oh yes and apache worker ( threaded) can't be used with PHP so ignore it entirely. Stick with apache prefork.

  • Hi abdussamad,

    Thanks for your advice, when we had MaxClients set at 50, we kept seeing error or MaxClients reached. So we were forced to keep setting it higher till we saw the error go away.

    Even with sometimes high spikes in traffic do you recommend your settings?
  • If the issue is related to the number of processes, than you shoud use threads (php as fastcgi). Just remember that php settings in .htaccess won't work anymore and that you should use the ulimit setting in the apache init script. After that you should be all set. While you may try to run apache with mod_php in worker/event mode, you may notice issues as php/modules are not thread safe, that's why fastcgi is ok. Also I would try litespeed if possible, it should work out ok (same ulimit if you reach any memory limit).
  • Sorry for the late reply. Webhype you need to upgrade to a larger VPS as it looks like 512MB ram is insufficient for your needs. I suggest going for a 2GB RAM VPS.

    FYI I have maxclients set to 15 on my small VPS. No way can you run 50 apache processes in 512MB RAM!