• Hi,

    Some months ago I started working in a couple of WP website projects that were already being developed, were I’m supposed to apply some customizations not achievable by plugins, etc.

    The thing is that these sites are extremelly slow. Previously they were installed on an old VPS, and when several people were using the Admin (and probably some visits too, not a lot) loading times would be around 15 seconds, or even a “timeout” error in browser.

    The traffic on the sites is around 10 visits per minute, with values around 300-600 daily visits.

    I moved the sites to a dedicated Cloud storage managed by myself (2.2Ghz 6 cores, 3Gb RAM), and loading times went down to around 3-5 seconds in the worst cases.

    But anyway, as time goes by, this has become unbearable. We don’t want our sites to go slow, they should load instantly, or at least, in 1 second max.

    Currently we use the W3Total Cache, and with the page cache enabled (cleared daily), pages load instantly, but those pages not cached take several seconds.

    The problem is that, when a FEW requests come at the same time, the CPU gets so saturated that a page that with a free CPU loads in 2 seconds, ends up taking 8 seconds.

    I’ve been doing some debugging with PHP, following the WP load code, line by line, function by function, and noticed that just the loop loading the plugins take 4 seconds.

    I even isolated the loading times by plugin. Some of them take 0.00020 seconds, some 0.020 (not fast, but “acceptable” I guess), but other ones take between 0.100 and 0.300, with a couple of the bigger ones taking 0.900 seconds. You sum up all this, and get the 4 seconds loading time. And it can go up to 8 or 11 seconds if you do more than one request.

    I’ve been developing websites with PHP for 20 years, and I’ve never seen a situation like this. I refuse to believe that a PHP just loading some code takes several seconds. Only similar things I’ve seen are scripts that import/export data, looping thousands of records from a file, inserting data into several tables, etc…

    How is it possible that some plugins make the PHP core take several seconds to process some code, loading the CPU at 100%, and making the next request even slower? What’s happening there? My problem are not rendering or downloading times. It’s the browser doing it’s “thinking” thing for several seconds before it gets any response from the server to start rendering the site.

    One of the sites has some hundreds of products (<1000) with a LOT of variations.

    I though this could be a reason for the long loading times (maybe a bloated DB), so I tried creating a CLEAN WP install, and then started adding the plugins used on the site, one by one. Of course the loading time went up slowly, to the point that a WP site, without any content, just a Home and a “Hello World” post, took 5 seconds to load. So variations had nothing, or little, to do (this is the site linked to the post).

    Even if it could be, I don’t think is server-resource related, because we also host another site I developed with just PHP, and it works without any problems. This website even connects to a remote API to search for accommodations, gets a response, and instantly renders a website with lots of information retrieved from several database tables, without any added cache, optimizations, image lazy loading, CSS minimify, JS minimify, or any other of those recommendations around to “make WP load faster”.

    These are the plugins installed, in case in triggers some alarm on someone:

    – Genesis theme + lily

    – Genesis Extender
    – W3 Total Cache
    – Sucuri Security – Auditing, Malware Scanner and Hardening
    – WooCommerce
    – Genesis Connect for WooCommerce
    – Variation Swatches for WooCommerce
    – Variation Swatches for WooCommerce – Pro
    – Smart Variations Images & Swatches for WooCommerce (Premium)
    – Premmerce Permalink Manager for WooCommerce
    – WPC AJAX Add to Cart for WooCommerce
    – WooCommerce Conditional Content
    – Advanced AJAX Product Filters for WooCommerce
    – Cantidad mínima y máxima para Woocommerce
    – Custom Shipping Methods for WooCommerce
    – FiboSearch – AJAX Search for WooCommerce
    – WooCommerce Load More Products
    – WooCommerce Servired/RedSys Spain Gateway
    – Facebook for WooCommerce
    – Kadence WooCommerce Email Designer
    – YITH WooCommerce Product Add-ons & Extra Options
    – Advanced Custom Fields
    – Max Mega Menu
    – Max Mega Menu – Pro Addon
    – ZP Shortcodes
    – Click to Chat
    – CMB2
    – Coming Soon Page, Maintenance Mode & Landing Pages by SeedProd
    – Disable Responsive Images Complete
    – Easy WP SMTP
    – Font Awesome
    – GA Google Analytics
    – GDPR Cookie Consent
    – Genesis 404
    – Google Ads & Marketing by Kliken
    – Gravity Forms
    – Limit Login Attempts Reloaded
    – Loco Translate
    – Plugin Notes Plus
    – PublishPress Capabilities
    – Really Simple SSL
    – Redirection
    – Shoppable Images Lite
    – SVG Support
    – WPS Hide Login
    – Yoast SEO

    Apart from this, I’ve got a custom PHP functions file with around 4000 lines, custom JS with 2600 lines and custom CSS with around 6000 lines.

    This site is HEAVILY modified, but I have also tested this removing these customizations, and didn’t see any noticeable speed improvements.

    If you open the site linked in the post, and then open in a new tab the Hello World post 5, or even 10 times, you will notice how long it takes to load the page. And it’s just a title and a text…

    It will also depend on how busy is the server, and that’s what I don’t understand.

    (If you want to try the actual website, just remove the “dev2” subdomain from the URL)

    This is the accommodation site I mentioned before (non-WP):
    https://deskontaliaviajes.com/alquileres-vacacionales/listado.php?whereto=costa+brava&rid=12&region=Costa+Brava

    It loads fast even if I try to “stress” it loading several accommodations at same time, while the WP is struggling to load several tabs at the same time.

    So basically, what can I do here?

    I have tried:

    – Different caches (W3TC current).
    – Disabled admin-ajax.
    – Disabled cron.
    – Reduced PHP memory to minimum value without error (256mb).
    – Removed unused action hooks.
    – Removed unused plugins.
    – Updated plugins.
    – Configured PHP to run as dedicated Apache for each site
    – Activated nginx cache.
    – … Possibly something else I already forgot.

    I don’t know what else to try. If you think I could need some server tweaking, please let me know what info I can give you to check if everything is on the recommended values.

    As a possible fix to improve speed, I’ve been thinking doing the following:

    – In the loop loading the plugins (wp-settins), add PHP code to avoid the loading of plugins that do nothing to the content (admin plugins and similar).
    – In this same loop, add a custom code, and depending on the page being loaded (home, a product detail, product list, contact…) load only certain plugins. Something like “if page is product detail, exclude plugins 3,6,1,38,13,11,15”.

    My final target is to create this website from the ground using just PHP and get rid of WP once and for all, but first they want me to try fix the speed issues 🙂

    Any help or orientation would be appreciated.

    Thanks in advance,
    Regards.

    • This topic was modified 4 years, 4 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Everything else WordPress topic

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Dion

    (@diondesigns)

    You’re using several plugins that are CPU-and-memory-pigs, so my first suggestion is to remove plugins that take the most time to load. If it solves the problem, then give some thought to finding replacements that aren’t such pigs. (I have a rule with my clients about two of the plugins on your list — if they are installed, my rates double if something goes wrong on their site. 🙂 )

    If the main issue is when plugins load, that kinda points to an issue with Zend OPcache (a PHP extension). If it’s not loaded, then make sure to load it. Then configure it to be able to cache all your PHP files. That alone may solve your issue. OPcache runs best with PHP 7.4 unless you compile PHP 8.0+ with the --disable-opcache-jit flag, or you correctly configure OPcache JIT (which is a monumental task, and it requires 512MB+ of dedicated memory on even average-sized sites).

    You might also want to consider using PHP-FPM, as it’s both faster and safer than loading PHP with mod_php. Also make sure Apache is using mpm_event and not mpm_prefork.

    Thread Starter irreo

    (@irreo)

    @diondesigns
    Thanks for the reply.

    1- I run 7.4 with PHP-FPM. Yesterday one of the things I did was to configure it to run as a dedicated service for each site. Maybe it was some placebo effect but it looked to run just a little faster, but still a no-no.
    (I tried to enable PHP 8 on the staging site but I have to rewrite lots of code, including outdated plugins, to avoid errors, so still haven’t tested the speed with it).

    2- OPcache is also enabled both on the server, and on the domain settings.

    3- Sadly the plugins that I listed are almost mandatory on this site… the day I debugged all the plugin times one by one, I though on some that could be replaced with custom programming. For instance, the Cookie notice can easily be done with simple HTML and PHP, and the plugin takes 100-200ms to load… the “404” page and the “Coming soon” too.

    But many others would require to re-create a lot of stuff…

    Anyway, care to mention which plugins are those? My big guess is WC… but there were actually 4-5 plugins that took +500ms to load on my tests.

    Thanks again,
    Regards.

    Dion

    (@diondesigns)

    Is your memory allocation in OPcache sufficient to cache all PHP scripts? The two important settings are opcache.memory_consumption and opcache.interned_strings_buffer. The opcache.max_accelerated_files setting is also important, but its default value of 10000 is usually sufficient.

    WooCommerce isn’t on the list of plugins I tell clients they shouldn’t use. I do, however, tend to charge a premium rate if it will be used…primarily because many of its addons are written with no regard to impact on server resources. So it should come as no surprise that one of the two “premium rate” plugins on your list is a WC addon. (The other…let’s just say it’s appropriately named given its heaviness.)

    Thread Starter irreo

    (@irreo)

    @diondesigns

    Hi,

    I checked the values you mentioned, but doesn’t seem to help either…

    These are the values I put on the “Additional directives” option in Plesk:

    opcache.memory_consumption=512
    opcache.max_accelerated_files=10000
    opcache.validate_timestamps=1
    opcache.revalidate_freq=60
    opcache.interned_strings_buffer=12

    I have a meeting tomorrow to evaluate possible actions, but currently I’m not sure there’s much I can do except disable some plugins and develop their functionality myself, and try the approach I mentioned of loading specific plugins depending on the content being loaded by the user.

    Thanks.

    Thread Starter irreo

    (@irreo)

    @diondesigns

    I’ve been talking with my coworker, the one that initially installed most of the plugins while building the site (before I joined the team), and while in “hardcore mode” we though on a situation where we removed all plugins that can be replaced with custom coding.

    I’ve tested the disable + removal of these plugins on the testing site, the one that took 4-5 seconds with an empty WP, and now it takes around 1-2 seconds (still “a lot”, but far more acceptable). Of course with no cache for now, I want to make sure the performance of the “default” installation is not terrible.

    Plugins affected:

    – Variation Swatches WC / Pro: We use it for linking images to the product attributes. I noticed that “Yith WC Product add-ons + extra options” allows this, so we are testing the removal of this plugin.
    – Facebook for WC: Still have to talk with the CM that uses it, but I hope we can remove it.
    – Max Mega Menu: Decided that we can add a custom HTML and get rid of this plugin and the WP menu once and for all.
    – Click to chat: Doable with custom code.
    – Coming soon page: Doable.
    – FontAwesome: Can add the script loading by ourselves.
    – Google Analytics: Add the code by ourselves.
    – Genesis 404: Custom on server.
    – Gravity forms: Get rid of the contact form and develop our own with good old school PHP with just what we need an not some plugin with 3180 features to only just use ONE of them.
    – Loco translate: Edit email templates directly instead.
    – Really simple SSL: Server redirect.
    – SVG support: Still have to check what this plugin does to “allow” SVG to be uploaded, maybe is doable without it.
    – WPS Hide Login: Same, check if doable manually, no sense on loading this plugin on every page load, even if it only takes 100ms. It’s supposed to be a “one time thing”.

    This will of course require work, and more if we finally decide to change the attributes and variations system, as it’s all custom made with own jQuery, triggering clicks and value changes on WP plugin inputs, etc… but maybe it’s worth it if we reduce the loading time.

    In any case, I’m still no happy at all about loading times… it shouldn’t take that long to load a simple page… this software is monster that eats server resources and requires tons of optimizations, caching, etc. to work…

    This is the testing site of the clean WP install now with duplicated products with variations and several addons to choose:

    https://dev2.deskontaliahome.com/sample-page/

    Even if it still takes time, is not as much as before.

    Thanks!
    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘WordPress eating CPU, extremelly slow’ is closed to new replies.