What’s the ideal way to profile WordPress memory usage?

We’re running a WordPress multisite instance on two Rackspace Cloud servers, one web and one database, with 30 or so sites currently. I’ve put Nginx in front for static assets and Apache handles all dynamic requests. I’ve also configured Memcached for the database and APC op code caching for PHP. W3 Total Cache is enabled by default across all of the sites we have.

It’s wicked fast with one issue: Apache processes regularly weigh in between 80 and 120 MB. The web server has 2 GB of memory, meaning I get 15 or so processes until things go on the fritz. The processes obviously shouldn’t be that large but I’m perplexed as to why they are.

What’s a good strategy for identifying what’s going on?

Thanks in advance!

Update 10/2/10: For those wondering, the resolution of the memory issue problem was disabling PHP xdebug (was inadvertently enabled on configuration and caused random memory usage spikes).

3 s
3

The apache process memory amount you talk about (80 to 120 MB per process) can be split into two reasons.

  1. Apache
  2. WordPress

Apache

You can optimize apache by only loading the number of modules you need and other optimization tweaks that will reduce the memory. If you have not optimized that yet, give it some tweaks.

WordPress

WordPress just consumes a lot of memory and is not very optimized at all. I would start with replacing the database class with something more properly implemented. That should gain more speed and reduce the memory usage a lot. Next to that I have not that much to suggest. Not using Worpdress is not considered helpful I guess.

Strategies

To find out what’s going on, you need to track how much memory a wordpress request is taking up. There is a get peak usage function (memory_get_peak_usage()) you could use to monitor worpdress memory usage. If it comes close to the 80 – 120 MB you wrote about, you know that wordpress is creating your headaches. You might want to log the time-stamp, peak memory, execution time and requested URI.

Using Nginx to serve cached wordpress pages will most certainly help you because it will prevent wordpress from getting loaded – even for those “inbound” caches like the one you use. They are conceptually broken because they are a wordpress plugin, so at least a part of wordpress needs to be loaded even for cached results.

Leave a Comment