Author |
|
enderandrew
Joined: 24 Jun 2012 Posts: 5 Location: USA, Omaha, NE
|
Posted: Sun 24 Jun '12 7:53 Post subject: Memory consumption |
|
|
I've got a test Wordpress install on a VPS for a new site I'm developing. The site isn't getting hardly any traffic yet other than myself putting in some content (through Wordpress) and Google crawling the site. Yet, at least once a day I fully run out of memory on a 2 GB VPS.
Apache has 10 processes running, each eating up about 400MB of memory, consuming all physical and virtual memory to the point that I can't even kill the process and reboot. I'm not seeing excess traffic.
Is there a good way to determine from Apache or PHP logs perhaps what is eating up my memory? |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3092 Location: Hilversum, NL, EU
|
Posted: Sun 24 Jun '12 15:26 Post subject: Re: Memory consumption |
|
|
enderandrew wrote: | Apache has 10 processes running, each eating up about 400MB of memory, consuming all physical and virtual memory to the point that I can't even kill the process and reboot. I'm not seeing excess traffic. |
Running Windows ? |
|
Back to top |
|
enderandrew
Joined: 24 Jun 2012 Posts: 5 Location: USA, Omaha, NE
|
Posted: Sun 24 Jun '12 17:55 Post subject: Re: Memory consumption |
|
|
Steffen wrote: | enderandrew wrote: | Apache has 10 processes running, each eating up about 400MB of memory, consuming all physical and virtual memory to the point that I can't even kill the process and reboot. I'm not seeing excess traffic. |
Running Windows ? |
Linux, Debian specifically. Most of the time I have 1 GB of physical memory used and 1 GB free, but occasionally all the Apache processes spike from 400MB per process to 500MB per process and I run out of physical memory.
Then I can't even run commands through the SSH session and I have to remotely reboot the server.
I assume it is a bad Wordpress plugin and PHP going nuts, but it never happens while doing one particular task in Wordpress and I'm not seeing anything as far as PHP errors. I'm not sure how to track this down. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 25 Jun '12 16:09 Post subject: |
|
|
Which MPM are you running and how are the settings? |
|
Back to top |
|
enderandrew
Joined: 24 Jun 2012 Posts: 5 Location: USA, Omaha, NE
|
Posted: Tue 26 Jun '12 0:34 Post subject: |
|
|
James Blond wrote: | Which MPM are you running and how are the settings? |
apache2-mpm-prefork with stock settings from Debian. My site config has a lot of rewrite rules in it for Wordpress, caching and security. I've moved those to 000-default.conf and out of .htaccess to help with performance. My 000-default.conf is here:
http://pastebin.com/yaZb4Q8d
And my enabled Apache modules are:
alias auth_basic authz_host authz_user cache cgi deflate dir env expires filter headers include info mime negotiation php5 reqtimeout rewrite setenvif speling ssl status
I suspect it might be a bad Wordpress plugin and PHP causing all the problems. I'm tempted to crank down my PHP settings just in case.
The worst case is what is happening where Apache eats so much memory the entire system is unresponsive and does nothing. Can I write a basic script that checks memory consumption and restarts the apache2 service if need be? |
|
Back to top |
|
enderandrew
Joined: 24 Jun 2012 Posts: 5 Location: USA, Omaha, NE
|
Posted: Tue 26 Jun '12 2:05 Post subject: |
|
|
I also want to add that I have several rewrite rules in my 000-default.conf that are likely redundant to an extent. They come from two different Wordpress security plugins, and a guide found here:
http://perishablepress.com/6g-beta/
I'd really like to consolidate them. I know that .htaccess is parsed with every HTTP request and I wonder if that is what is affecting performance. I thought that site config is only parsed when Apache starts, but I assume consolidating these rules can only help.
Could someone assist me with that?
Edit: I've made a few trims of my own, and have a slightly shorter list of rules:
http://pastebin.com/rtK8KW5X |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 26 Jun '12 10:21 Post subject: |
|
|
enderandrew wrote: |
I'd really like to consolidate them. I know that .htaccess is parsed with every HTTP request and I wonder if that is what is affecting performance. I thought that site config is only parsed when Apache starts, but I assume consolidating these rules can only help.
Could someone assist me with that?
|
Sure that .htaccess decrease your performance on a site with high traffic. I have a PHP tool on my site to convert .htaccess files into code for httpd.conf
Than it will be parsed only once and you can disable AllowOverride. http://mariobrandt.de/archives/php/disable-allowoverride-htaccess-to-httpd-conf-225/
Also prefork is not the fastest mpm. For me it helped to use worker mpm and php over mod fcgid http://mariobrandt.de/archives/php/changed-to-worker-mpm-156/ |
|
Back to top |
|
enderandrew
Joined: 24 Jun 2012 Posts: 5 Location: USA, Omaha, NE
|
Posted: Tue 26 Jun '12 15:08 Post subject: |
|
|
I had already moved all the rules to my site .conf file and out of .htaccess and then denied Overrides.
I've now also moved to worker and php-cgi which is supposed to use less memory, but idle my webserver is actually using more memory. Though it should spike less with traffic presumably.
I still need to try to isolate what caused the memory to spike occasionally. I'm not sure how to do that. In my /var/log/apache2/error.log I can see PHP fatal errors when it ran out of memory, but nothing consistent when it happened or what line preceded it. |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 26 Jun '12 23:23 Post subject: |
|
|
I had that issue with some memoryleaking php extensions (windows and linux). That is why I use only php over mod fcgid. Than apache does not crash. In /var/log/apache2/error.log shouldn't be any PHP error when using php over fcgid. Maybe you use fcgid and the module at the same time. |
|
Back to top |
|