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.

Read More

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).

Related posts

Leave a Reply

3 comments

  1. 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.

  2. Daniel,

    I respectfully disagree with kenkeiter, I understand using nginx as a reverse proxy out in front of Apache. Harvard Law has had great success with this method and they have a great article on how they do this, with a link to their WordPress plugin which helps interface with nginx:

    http://blogs.law.harvard.edu/djcp/2010/01/nginx-as-a-front-end-proxy-cache-for-wordpress/

    What they discovered at Harvard Law was that, with nginx basically caching all requests in the front-end, it doesn’t actually improve performance to use any other caching-type plugins in the backend, and is not worth the additional complexity. If you’re serious about using nginx in this way, I recommend you take a look at that article about their experience and try to pare down the dynamic processes, including the WP-side caching.

    Some basic sleuthing like looking carefully at your Apache access and error logs to see what kinds of queries are actually having to be done dynamically and trying to reduce such cases may also be a good start.

  3. Well, first of all, you’re using Apache and Nginx — kind of redundant. You should be using Nginx/FastCGI w/PHP. The tutorial at this site should help out. Otherwise, my best guess is that some recent change to your code is causing some bug in PHP to not release memory properly. There’s not reason that an Apache process should consume that much memory.

    http://interfacelab.com/nginx-php-fpm-apc-awesome/

    Good luck!

    @kenkeiter