WordPress / performance

Performance plugin from the WordPress Performance Group, which is a collection of standalone performance modules.
https://wordpress.org/plugins/performance-lab/
GNU General Public License v2.0
350 stars 94 forks source link

Recommend PHP accelerators i.e., OPCache? #452

Open LukaszJaro opened 2 years ago

LukaszJaro commented 2 years ago

Are PHP accelerators used often and beneficial to the performance of a WordPress site? If so would it be a good idea to include in the site health check?

PHP: There are various PHP accelerators available which can dramatically improve performance of your PHP files. This will apply to all PHP files, not just your WordPress installation. Search for PHP optimization for more information, f.e. APC or OPcache. The W3 Total Cache plugin, described below, offers integrated support for Memcache, APC and other Opcode caching. https://wordpress.org/support/article/optimization/#optimize-software

Some further reading https://wesleyzhang.me/do-you-need-op-cache/

mxbclang commented 2 years ago

@LukaszJaro Good question! @manuelRod Curious for your thoughts here.

manuelRod commented 2 years ago

Hello, @LukaszJaro thanks for opening this one up. As far as I can see, isn't OPCache enabled by default in modern PHP versions? +7.0? I could find the following article:

For many WordPress site owners, their server may already have the latest version of PHP installed. This means they already have OPcache automatically enabled to drastically speed up page load times for their site.

https://wp-rocket.me/blog/what-is-opcache/

Also this:

The real incentive for upgrading your PHP version is the promise of a performance boost. PHP 7.4 will deliver on that. PHP 7.4 will introduce preloading to PHP core. This is essentially done via an extension to Opcache, the software that stores precompiled script bytecode in shared memory. This helps eliminate the need for loading scripts on every request.

https://wpengine.com/blog/a-first-look-at-php-7-4/

If that's the case, maybe is a bit redundant to add a check for it, though I'm not 100% sure if that's the case.

LukaszJaro commented 2 years ago

Thank you @manuelRod, that is great information! I'm in the process of finding out from my managed hosting provider if it is enabled or some alternative being used. So far I am not seeing it listed using php info, will report back once I have more data.

LukaszJaro commented 2 years ago

Surprisingly my hosting provider(enterprise grade and running on NGINX, PHP 7.4) did not have any PHP accelerator method enabled. This is just one case so far where it was not enabled, I also have some cheaper shared hosting I can check and see what's enabled.

merkys7 commented 2 years ago

I can confirm that not all hosting providers enable PHP accelerators such as OPCache by default. Plus, users could accidentally disable it in PHP extensions settings. I think this could be a helpful feature

manuelRod commented 2 years ago

What is the hosting you are using, and which PHP version? I'm curious. Is this something they can enable on request? In that case, I'm surprised they don't do it by default.

merkys7 commented 2 years ago

I am a system engineer at Hostinger.com and I have enabled the OPCache PHP extension by default on PHP versions that supports OPCache. On my production WP site, I use 8.1 PHP with OPCache. The tests showed that with OPCache WP site could load faster. As user, you can navigate to control panel PHP selector section and enable/disable wanted PHP extensions such as OPCache,ACPU,etc. Usually, hosts enable OPCache by default.

mukeshpanchal27 commented 2 years ago

I think the latest PHP supports OPCache or APC. https://www.cloudways.com/blog/integrate-php-opcache/ has one example of how OPCache affects site performance. We should add a site health check for this type of accelerator so end users get notice of it and if it's a disabled user's request to start it from the hosting provider.

I have made an extensive framework with a lot of fields and validation methods and enums to be able to talk to my database.

Without OPcache

When using this script without OPcache, I push 9000 requests in 2.8 seconds to the Apache server. It maxes out at 90-100% CPU for 70-80 seconds until it catches up with all the requests.

Total time taken: 76085 milliseconds(76 seconds)

With OPcache enabled

With OPcache enabled, it runs at 25-30% CPU time for about 25 seconds and never passes 25% CPU use.

Total time taken: 26490 milliseconds(26 seconds)

LukaszJaro commented 2 years ago

Verified on my cheaper shared hosting that opache is not enabled in cpanel but it's easy enough to enable with a click of a button.

That's two separate hosting companies I checked that don't have it enabled by default. Judging by the above it sounds like significant performance boost is possible depending on site.

I probably read over the WordPress performance recommendations a few times over the years https://wordpress.org/support/article/optimization/#optimize-software but it never clicked about the PHP accelerators so maybe having it in site health check will encourage more people to enable it.

manuelRod commented 2 years ago

It seems then, that we need a new Site Health check :) @LukaszJaro do you want to expose this in the next perf weekly meeting? so we can get some feedback over there?

mxbclang commented 2 years ago

Thanks @LukaszJaro and @manuelRod! If we want to propose this as a new health check, can you please update the issue with the content from the new module proposal issue template? Once that's done, we can work on getting this scheduled for discussion in a future performance chat. Thank you!