4

I have a VPS running apache-php-mysql on centos and a single drupal website installed. The VPS has 256MB of RAM (could be the root cause of all my problems... maybe I just need more). Whenever I try to open my website from multiple browser tabs (about 8... not 800) all at once, apache crashes! I have this on the log:

[Wed Oct 24 11:26:31 2012] [error] [client xxx] PHP Fatal error: Out of memory (allocated 28049408) (tried to allocate 201335 bytes) in xxx on line 2139, referer: xxx

I have read many many posts here, but I think there is something fundamental that I'm missing - If I understand correctly some php script tried to allocate 200K after allocating 28MB, and fails to do so.

First question is: should this cause the apache to crash???

Next, I tried to look at 'top' command while I do my little test. Indeed I see 7 httpd processes, each reserving about 30MB - which explains why my RAM runs out.

How do I prevent apache from creating new processes until it's out of memory?

I tried configuring /etc/httpd/conf/httpd.conf like this:

<IfModule prefork.c> StartServers 1 MinSpareServers 1 MaxSpareServers 1 ServerLimit 1 MaxClients 1 MaxRequestsPerChild 100 </IfModule> 

But got the same exact result!

What am I missing?

Thanks a lot!

Update:

My PHP memory_limit is 128M (confirmed by the drupal admin pages...) The output of free -m:

 total used free shared buffers cached Mem: 256 226 29 0 0 0 -/+ buffers/cache: 226 29 Swap: 0 0 0 

What can I do to make apache consume less memory? Can't I save memory on the expense of slower responses?

2
  • You are showing only 29 MB of RAM free, which isn't much at all. Have you verified that MySQL is properly configured and not wasting precious RAM? The tuning-primer.sh (day32.com/MySQL) script is perfect for that. Have you disabled any unnecessary modules in both Apache and PHP? If you can afford it then you should definitely get your RAM increased. Commented Oct 24, 2012 at 21:11
  • Thanks! Those tips are very helpful! I'll try them and report back. I guess I can buy more RAM but I just want to understand the problem better. I'm not even sure yet more RAM will solve the problem Commented Oct 26, 2012 at 15:56

1 Answer 1

2

Depending on your version of Drupal: Drupal 6 core requires PHP's memory_limit to be at least 16MB. Drupal 7 core requires 32MB.

Based off of the error and your post you've allocated 28MB, please confirm in the php.ini file that memory_limit is set correctly. Make sure to restart Apache to apply any changes to php.ini.

Another aspect to consider is the other services that are running on your server, Apache, MySQL, etc. These also take from the total 256MB.

To get an idea on the current memory usage you can type:

free -m 

The -m flag outputs the data in MB. The -b switch displays the amount of memory in bytes; the -k switch (set by default) displays it in kilobytes.

You'll get an output like:

total used free shared buffers cached Mem: 24031 22512 1518 0 1614 8082 -/+ buffers/cache: 12815 11215 Swap: 31999 485 31514 

Depending on the available memory you can begin to narrow down the issue to either PHP or if you've outgrown/maxed out the VPS.

EDIT

@Ofri,

There's no exact science to the Apache config.. It boils down to knowing the specs of the machine and mainly trial & error. Monitoring performance of the server during the on-going trial and error periods is important so you can see the postive/negative impact.

I would stop Apache, edit the httpd.conf according with the values below and see how the server behaves:

  • MaxKeepAliveRequests 100
  • KeepAliveTimeout 15
  • MinSpareServers 5
  • MaxSpareServers 10
  • StartServers 5
  • MaxClients 150
  • MaxRequestsPerChild 300

Keep in mind Drupal is a system hog and you may ultimately end up upgrading the VPS to 512MB.

-Brendan

5
  • Thank you! I updated my question with the information you requested. What about my apache configuration? shouldn't have it prevent the many httpd processes? Commented Oct 24, 2012 at 19:03
  • @Ofri, check my edit. I posted it there for formatting purposes. Commented Oct 24, 2012 at 19:48
  • Thanks... but I still don't understand what this configuration do? It looks like whatever I do the apache just creates new processes until it is out of memory Commented Oct 24, 2012 at 20:47
  • The configuration options is specifying the initial launch behavior of Apache as well as the subsequent actions for when Apache has been running for some time. You're gonna need to do trial & error and try to find a balance. What type of page caused the error? A file upload? A resource I found to help get some beginning values was here. Ultimately, I think you need to begin exploring your options for a RAM upgrade Commented Oct 24, 2012 at 20:59
  • 1
    Thanks a lot for your time! I find it really frustrating - I don't need a fast server, or one that handles many requests concurrently I just need a server that doesn't crash because it's out of memory! There must be a way of achieving that, don't you think? Commented Oct 25, 2012 at 10:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.