Vps – Apache out of memory on

500-errorapache-2.2low-memoryvps

I have a VPS with 768 MB RAM and a 1.13 GHZ processor. I run a php/mysql dating site and the performance is excellent and server load is generally very low.

Sometimes I place ads on Facebook and at peak times I can get 100-150 clicks within a few seconds – this causes the server to run out of memory :

Cannot allocate memory: couldn't create child process: /opt/suphp/sbin/suphp ….

And all users receive an error 500 page.

I am just wondering if this sounds reasonable or not – to me 100-150 does not seem to be a number that should cause apache to run out of memory.

Any advice/recommendations how to diagnose the issue highly appreciated.

Best Answer

Optimizing memory footprint is usually done by reducing (and limiting) these factors:

  • count of simultaneous Apache processes (I'd recommend switching to prefork MPM, which is kindof more controllable in memory-limited environs)
  • moving away from mod_php or php_cgi to fastcgi, mod_cfgid works fine. Reducing the count of allowed spawned php processes by FcgidMaxProcesses and removing long timeouts (see http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html )
  • server "threadiness", especially by reducing unnecessarily long timeouts ((dis)connect timeouts, keepalives, ...)

If the load is getting really heavy, you should also look into the speed of request handling (faster loading improve the total size*time of memory needed for one request)

  • optimizing your website code (improving PHP code to be faster and/or more memory efficient)
  • optimizing PHP execution (xcache can speed stuff up several times)
  • caching of whole requests also does wonders, see mod_cache

Maybe, if your web isn't any CPU-intensive at all, and you need some extreme Req/S, try some different webserver (like nginx, or lighttpd) which behave better in such situations.

Related Topic