Posted by mpaler on September 13, 2010 at 8:35pm
I'm having some performance issues with our site.
TOP on my production server is showing the following for APACHE:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
21333 www-data 19 0 345m 83m 28m R 99 4.8 0:05.07 apache2
1235 mysql 18 0 159m 44m 3876 S 1 2.5 167:32.39 mysqld Obviously, this is very bad. What's weird is that a dev box with the same setup is showing memory usage less than HALF these numbers...
Here's my questions...
- What might explain the doubling in memory usage?
- What tools/tricks could I use to uncover what is causing the bloat?
Any help is greatly appreciated.
Mike

Comments
Lot s of sites, lots of modules
The actual size is the sum of RES for all the Apache processes, minus the SHR (shared libraries, including PHP's code, Apache modules, ...etc.).
Normally, Apache's memory grows as you are loading more and more modules. If you are running several sites from different code bases (not using multisite), then things get worse and worse.
The live site could be loading certain pages that consume more memory (e.g. large data set returned from select, lots of data processed in memory arrays, ...etc.). You can enable the performance logging module and see which pages consume the most memory (comes with devel module).
One way to reduce this is to install APC (or eAccelerator if it is stable on your distro). The first access will take a lot of memory, but subsequent accesses will use less memory since it does not have to load, parse and tokenize the source.
As always, less modules is also better.
Also check the Apache modules. Some of them (specially the auth* suite) use more memory. Again less Apache modules is better.
Another way to make Apache leaner is to run it as an MPM Worker and run PHP as a FastCGI. This will make Apache very lean, as PHP is in its own process now.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
thanks Khalid. Good stuff and
thanks Khalid. Good stuff and I will try to track some of this down...
Normally, Apache's memory grows as you are loading more and more modules. If you are running several sites from different code bases (not using multisite), then things get worse and worse.I run two different drupal installations -- one for staging and one for production on the same server. I use drupals multisite functionality to maintain settings files in subversion, but they are two completely different source codes.
Would fixing this be as simple as pulling staging off the production server? Or would I need to restart apache, reboot or something like that?
Thanks,
Mike
No difference to Apache/PHP
Multisite has the advantage of having one source file for all sites that are served from the same server, and therefore only one copy is loaded.
As far as Apache/PHP is concerned, /var/www/site1/blah.php and /var/www/site2/blah.php are two different files and it will load two copies of it.
Try what I suggested: reduce the number of modules, install an accelerator, reduce apache modules.
Moving staging off to the development machine could help too. it is good practice anyway to make the live only for the live stuff. Apache would need to be restarted/reloaded after you do that to see the effect.
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.
Apache restart
No need for apache restart really if you pull staging off, but it is if you install accelerators etc..
Just move staging to another server, configure it, make dns corrections & remove virtualhost configs related to staging server. You can restart apache when you would have maintenance anyway. Sites what are not loaded/visited don't generally create load for apache.
For ubuntu /etc/init.d/apache2 reload is really fast and don't really cause downtime unless configuration is broken.
virtualhosts
I have my site which consists of only index.html page and then my subdomain consists of drupal in sub folder of that . Would it be less memory to have drupal core in my site's html folder even though it will just be serving one static page and then do as they do with multi sites and have my sub sites folder in drupal core's sites folder? Or does it not make any diff until I would add more sub sites because at moment only running one drupal install? Just thinking named virtualhosts might take up more memory?
This is a non-issue. You are
This is a non-issue. You are looking in the wrong place to improve memory usage.
--
Dave Hansen-Lange
Director of Technical Strategy, Advomatic.com
Pronouns: he/him/his
For PHP are are you running
For PHP are are you running mod_php, fastcgi, FCGID or PHP-FPM?
If you are running mod_php this will make your apache processes MUCH larger.. There are "quirks" with fastcgi and FCGID as well.. IMO the best (and newest) way to run PHP if PHP-FPM but getting this working with apache 2.2 is a pig.. Not tried it with 2.4 but in theory its easier.. On nginx its a breeze but nginx has its own set of configuration headaches..
Thanks wipeout-dude
I have changed amounts in apache prefork which has made a huge difference so far.