Profiling a WordPress Website for Deployment on Shared Hosting?

I am having a problem with CPU usage on my website, and am looking for a way to detect (and fix) what is causing it. A topic not covered in this question.

Following on Hakre answer here, I now realize that what I need to do is profile my PHP calling.

Read More

Is it reasonable to put the website on my own computer, run the profiler, and use that information to improve my website?

Any other suggestions on how to do this in the best way?

Related posts

Leave a Reply

7 comments

  1. Profiling with Profiler-Plugins

    Not sure exactly what you need to accomplish with your profiling, but WP Tuner (WordPress Plugin) goes a long way to finding what is slowing down your WP install.

    It looks at each plugin and give your the memory, CPU time and SQL queries involved.

    The SQL Monitor (WordPress Plugin) analyzes SQL performance.

    Combine it with W3 Total Cache (WordPress Plugin) and you should get better performance on any platform.

    Also, look to using transient API to store fragments you do not need to generate everytime. This can really help on a slow DB.

  2. We have built a PHP profiler on top of XHProf that also uses callgrind output format. The main advantage over XDebug is hugely lower overhead and better recursive function handling, as well as XHProf-style profiling begin and end functions, enabling automated unit testing.

    You can see it at http://www.exteon.ro/en/products/php-tools/web3tracer

    You will need to compile and use it on your test box though, or ask your hosting provider to install it, but they are not likely to do that.

  3. Profiling with Xdebug

    I searched for some links so it’s easier to read into the topic. I’ve looked for doing PHP profiling with XDebug, something I would suggest to do:

    To display profiling results on the remote site, webgrind might be useful. It’s a PHP application that summarizes the profiler output.

    I’m not sure if it’s possible to provide this all in form of a wordpress plugin (at least there is none available I’m aware of and I don’t think that there is something available right now), so you might need to do some of the setup / configuration / profiling on your own.

  4. Yes, it is perfectly reasonable to set up the site in a new environment where you could actually run a performance profiler and other tools.

    As mentioned throughout the comments here, yes for the best results you’ll need an environment that looks very much like what’s running in production. And to get even better results, you’ll need to mimic the ongoing traffic, CPU/disk/network usage that’s happening on the production server, while profiling.

    In theory this can be done, but in my experience nobody really ever does that for two reasons:

    1. It’s a nightmare to configure and maintain. It’s just easier (and more accurate) to do it in production, which is why lightweight profiling tools, such as XHProf exist. Unlike Xdebug, these profilers are designed to run in production, on-demand or at a specific sample-rate. New Relic is also a good option if you can afford it.
    2. In a shared hosting environment, your site is running alongside hundreds, maybe thousands of applications similar to yours, each consuming CPU, disk IO, network and memory. While some shared hosts might tell you what your application is consuming, it would be a bit weird if they told you what the other applications are doing as well ๐Ÿ™‚

    I’ve been profiling WordPress applications for about a decade now, and here’s what you need to know: 99% of the performance problems are in the application code. Not in the server configuration, not in the disk io or amount of RAM, not in an over-saturated network. But in the application code.

    Regardless of the environment, if the application is doing:

    add_action( 'init', function() {
        wp_remote_get( 'https://some-third-party-service.org/api/version-check/' );
    } );
    

    And if that third-party service takes 1 second to respond, then every page load on your WordPress site will pay the 1 second penalty. Every. Single. Time. On Windows, on Linux, on macOS. With 1G of RAM or 32G of RAM. With an SSD disk or an old spinning magnetic disk.

    Could you have spotted the problem running a profiler on your local computer? Of course you could:

    WordPress performance profile

    Yes, naive code such as this can easily be spotted with PHP-level tools, like Query Monitor and the Debug Bar family, right there in production, even on a shared host. But if they don’t reveal the problem, then it’s perfectly fine to get a full copy of your production site, run it locally or some cheap VPS, in an environment where real profiling tools are available.

  5. If you want to see exactly what is happening in production, you need to add profiling to production.

    You have a few options to profile a PHP application (eg WordPress) in production.

    xhprof

    XHProf was originally developed by Facebook to profile (and optimize) their PHP web application (facebook.com). It was open-sourced in 2009.

    Facebook no longer maintains XHProf, and as development continued past PHP7, the XHProf code rot lead to a number of XHProf forks.

    One of the best maintained XHProf forks is maintained by Tideways; it is available in the Debian repos and therefore can be securely downloaded & installed without downloading & compiling code from the Internet if you’re using a Debian-based Linux server.

    For more information on installing tideways-xhprof and configuring WordPress to use it, see:

    excimer

    Excimer is an alternative to XHProf that’s used by Wikipedia.

    Unfortunately, I have been unable to find any guides on using Excimer with WordPress.

  6. Yes, it is perfectly reasonable to profile the website on your own computer. You will need to install the environment, including the webserver and profile the site using a profiler of choice.

    On Windows, local WordPress installation is extremely easy thanks to the Web Platform Installer. Single-click install WordPress including all prerequisites from here.