Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How to cache dynamic content in WP?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How to cache dynamic content in WP?

MerakithMerakith Member
edited January 2023 in Help

Hi,

FastCGI cache/Keycdn cache enabler precompressed gzip cache files and other methods to cache content into static files works wonder. Can easily handle in multiples of 10K requests per minute without breaking a sweat. May be more. Also the response time is under 150ms which is wonderful for this load imo

How do I cache dynamic content such as woocommerce cart? I have tried a lot of stacks but none is able to handle 100 requests per second for 1 minute on woocommerce cart page with decent response time. I understand the page is not cached. Is there any other way to increase the throughput? I am using loader.io to test and best I was able to reach average of 4.5 seconds in response time for 100 requests/second. Stacks tested include webinoly, slickstack, centminmod, openlitespeed, spinwpup and caddy. Some were tested at defaults and some were fine tuned. I am testing using 8GB ram, 4 dedicated cores, 160gb nvme disk on DigitalOcean.

I have noticed some wp plugins can generate unique cache for logged in users. I think Wordpress VIP is using varnish cache to cache some areas of dynamic content. What do you guys suggest?

Thanked by 2mustafamw3 tjn

Comments

  • @eva2000 Any help here?

  • TrKTrK Member

    Tried object caching? like redis and memcached. I never worked with woocommerce before, will setup a test site and see if it helps. Don't expect a great solution from me, all i will be doing is testing woocommerce with and without object caching.

    Thanked by 1Merakith
  • MerakithMerakith Member
    edited January 2023

    @TrK Yes. Lot of tests. I had tested with redis with phpredis, redis with predis, redis with relay, memcached and few others. A minor improvement at best.

    I did some more research and I think it's architectural limitations of WooCommerce coming in to play. It's hard to scale woocommerce without spending lot of money, time and stress.

    https://hollerwp.com/scaling-woocommerce/

    It's difficult to sustain 10 checkouts per second without a cluster and very fast single core perf cpu. That's what I am testing via loader.io They talk about these limitations in WooConf 2017. Such performance is not required for a small shop and that's where woocommerce shines. Excellent flexibility and free. I do have a cluster but I want to run something more scalable for an upcoming project where I expect such number of checkouts per second for a short period (sales). I'll be looking for alternatives.

  • duckeeyuckduckeeyuck Member
    edited January 2023

    You can't, shouldn't as well, because it makes no sense
    No reason why prices/cart data should be cache-able, the pricing/availability has to be computed every time it's requested, it's not client-sided.

    Also it makes a lot of sense that you'd get 100 requests/sec since everytime that page is loading it's probably calling other APIs and it has to wait for them :/

    Why are you even worrying about doing more than 100 rps lol?

    Thanked by 1kkrajk
  • @duckeeyuck I am not saying to cache the cart data but other areas on the page can be cached and prices for different user roles can be cached for a limited period.

    I understand but not happy with the response time on an empty cart page on a fresh installation of wp with zero content and default theme with only woo installed. 4.5 seconds average with webinoly stack.

  • Using the Simply Static plugin to convert WP to static HTML. Try to use less plugins that create dynamic content perhaps.

    Dynamic DB powered websites can't really be static, other than whatever static content they can serve. They rely on DB backend, but you can cache SQL queries, their results, in various ways.

    Other than PHP memcache or another memory or etc. cache for WP I don't think that caching dynamic content would accomplish.

    Consider building your store using a static site.

    https://www.ecwid.com/static-websites

    Check out ecommerce solutions for static sites like Jekyll, Hugo etc.

  • i think lscache is the only solution out there for woocommerce, you can also use esi to cache what you want.

    https://blog.litespeedtech.com/2017/05/24/wpw-using-lscache-with-woocommerce/

  • If you are using Litespeed, try Quic Cloud in Litespeed cache. It provides both dynamic and static cache features.

  • @Merakith said: How do I cache dynamic content such as woocommerce cart

    some plugins like litespeedcache has in-built features to cache dynamic content. Just toggle on/off to cache it.

  • MerakithMerakith Member
    edited January 2023

    I have figured it out guys. Woo is slow. No doubt about it but it's much faster if you are able to feed it with fast single core cpu.

    I was lucky enough to get a single promotional vps 1 core i9 11900K, 1gb ram from Hostcram in black friday sales. Thanks @Shakib I spin it up and gave it a go. It totally decimated my digital ocean 4 dedicated cores, 8gb ram, 1000+ gb5 single core score.

    1gb ram is easily able to handle 20 checkouts per second with under 400ms response time. https://bit.ly/3ivhmXS

    TLDR Get modern high frequency cpu if you want a fast dynamic wordpress+woo website. Don't run behind more cores.

    Thanked by 2Shakib ElonBezos
  • eva2000eva2000 Veteran
    edited January 2023

    @Merakith said:
    I have figured it out guys. Woo is slow. No doubt about it but it's much faster if you are able to feed it with fast single core cpu.

    I was lucky enough to get a single promotional vps 1 core i9 11900K, 1gb ram from Hostcram in black friday sales. Thanks @Shakib I spin it up and gave it a go. It totally decimated my digital ocean 4 dedicated cores, 8gb ram, 1000+ gb5 single core score.

    1gb ram is easily able to handle 20 checkouts per second with under 400ms response time. https://bit.ly/3ivhmXS

    TLDR Get modern high frequency cpu if you want a fast dynamic wordpress+woo website. Don't run behind more cores.

    Are both servers in same geographical location? As location impacts server response time/TTFB.

    From my Cloudflare TTFB guide on their community forums at https://community.cloudflare.com/t/improving-time-to-first-byte-ttfb-with-cloudflare/390367/1 mentioned 3 segment optimization stages, you've figured out why segment 3 optimization is important and the choice of server hardware is only a part of the formula.

    To fully optimise you need to optimize 3 segments.

    1. segment 1 - connection between visitor and CF edge server i.e. CDN cache/CDN cache control, Cache Rules, WAF, Firewall, Page Rules, Mirage, Polish webP, HTTP/2, HTTP/3, CF Workers (i.e. custom/advanced caching) etc. Cloudflare CDN level caching effectively reduces your origin server resource usage loads for CPU/Memory etc as request load is offloaded to Cloudflare CDN edge servers in an Anycast manner to the closest CF datacenter to the visitor.
    2. segment 2 - connection between CF edge server and your origin i.e. TLSv1.3 origin server support, Argo, Railgun, Full SSL/ECDSA SSL certificates origin served, pre-compressed asset served from origin, Tiered Caching and Cache Reserve eventually once out of Beta (right now TTFB ends up slower with Cache Reserve beta enabled).
    3. segment 3 - your origin server’s performance/optimisations i.e. web server, PHP, MySQL server optimisations and server hardware specs. Origin server side caching, PHP Zend Opcache caching, MySQL’s various buffer caching and various other origin server side caching can also be used.

    And yes Woocommerce is slow by nature so needs more work and resources to scale. Just look at Kinsta's PHP benchmarks for CMS/Ecommerce and other apps and compare Woocommerce vs EDD https://kinsta.com/blog/php-benchmarks/

    If you don't need Woocommerce and can make do with EDD plugin, it would be natively 3x faster for some request types for dynamic PHP served requests.

    @Merakith said: TLDR Get modern high frequency cpu if you want a fast dynamic wordpress+woo website. Don't run behind more cores.

    Not entirely true, it comes down to specific server hardware. Ideally you want more CPU cores with high frequency and properly tuned LEMP stack beyond the out of box defaults.

    Thanked by 1Merakith
  • eva2000eva2000 Veteran
    edited January 2023

    @Merakith said: I am testing using 8GB ram, 4 dedicated cores, 160gb nvme disk on DigitalOcean.

    Haven't tested DO much lately, but all my comparison benchmarks throughout the years, DO has always had the slowest VPS servers too especially when compared to Upcloud and Vultr High Frequency VPS servers. Very old benchmarks at https://community.centminmod.com/threads/13-way-vps-server-benchmark-comparison-tests-upcloud-vs-digitalocean-vs-linode-vs-vultr-vs-hetzner.17742/ i.e. sysbench MySQL max response times for DO was between 3x to 12x slower than Upcloud or Vultr High Frequency VPS servers.

    Thanked by 2Ympker Merakith
  • @Merakith said: It's difficult to sustain 10 checkouts per second without a cluster and very fast single core perf cpu. That's what I am testing via loader.io They talk about these limitations in WooConf 2017. Such performance is not required for a small shop and that's where woocommerce shines. Excellent flexibility and free. I do have a cluster but I want to run something more scalable for an upcoming project where I expect such number of checkouts per second for a short period (sales). I'll be looking for alternatives.

    There's also Cloudflare Waiting Room to allow you to queue up visitors to say your checkout based on how much concurrent user load your servers can handle https://blog.cloudflare.com/cloudflare-waiting-room/ and https://developers.cloudflare.com/waiting-room/

    Thanked by 1Merakith
  • MerakithMerakith Member
    edited January 2023

    @eva2000 said: Are both servers in same geographical location? As location impacts server response time/TTFB.

    Thanks for replying to me. Appreciate it. No. I had made tests with 3 providers.

    1) DigitalOcean server in Singapore and Netherlands.

    DO plan is dedicated cpu optimized (4 cores, 8gb ram, 150gb nvme.
    Geekbench Single core - 1000 approx

    2) Hostcram is shared 1 core plan hosted in Dallas (1 core, 1gb ram, 11gb nvme)
    Geekbench Single core - 1750 approx

    3) One provider in Australia with 6 cores, 8gb ram and nvme disks.
    Geekbench Single core - 550 approx

    I understand location impacts the response times but here we are talking about seconds (so the problem is with application) and not milliseconds. I feel loader.io can give more realistic experience.

    Multi core helps no doubt and more cores the merrier when they are fast. I had tested with various stacks including yours to ensure that there are no anomalies. I had also tested with experimental Nginx unit under the impression that it will be able to handle more php requests due to vertical integration. But the benefits does not reflect for WP sites.

    I can understand how the layers help but this test was determine load for dynamic content. So cloudflare proxy was off, ssl was enabled, no waf and /cart and /checkout was tested as they are uncached areas of the site.

    My main stack is Caddy + PHP-FPM + KeyCDN Cache Enabler (I got to aware of this plugin from your stack) and it can handle very decent amount of sites as most pages get converted into static. Problem is with the dynamic scalability and that's where faster cpu shines.

    I'll test upcloud and vulture high frequency plans and see how it goes. Most of my servers are 6 cores but 700gb5 single score. I am now looking to replace them with HF VPS to gain decent uplift in single core as well as multi core performance.

  • tjntjn Member

    @Merakith said:
    My main stack is Caddy + PHP-FPM + KeyCDN Cache Enabler (I got to aware of this plugin from your stack) and it can handle very decent amount of sites as most pages get converted into static.

    I love Caddy - haven't tried it for WordPress, don't suppose you could kindly share your Caddyfile?

    Thanked by 1Merakith
  • MerakithMerakith Member
    edited January 2023

    @tjn said:

    @Merakith said:
    My main stack is Caddy + PHP-FPM + KeyCDN Cache Enabler (I got to aware of this plugin from your stack) and it can handle very decent amount of sites as most pages get converted into static.

    I love Caddy - haven't tried it for WordPress, don't suppose you could kindly share your Caddyfile?

    I cannot share my config file as it's a catch all file with ondemand tls, cloudflare module for tls cert generation with proxy on, security headers and php-fpm over tcp. Bit deviated from general setup. But the below config file will do well for a general setup.

    With KeyCDN Cache Enabler Plugin:

    xyz.com {
        root * /var/www/html/xyz.com
        php_fastcgi unix//run/php/php8.2-fpm.sock
        file_server {
            precompressed gzip
        }
        encode zstd gzip
    
        @cache {
            not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in"
            not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)"
            not method POST
            not expression {query} != ''
        }
    
        route @cache {
            try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query}
        }
    
        @disallowed {
            path /xmlrpc.php
            path *.sql
            path /wp-content/uploads/*.php
        }
    
        rewrite @disallowed '/index.php'
    }
    

    Without Cache Plugin:

    xyz.com {
        root * /var/www/html/xyz.com
        php_fastcgi unix//run/php/php8.2-fpm.sock
        file_server
        encode zstd gzip
    
        @disallowed {
            path /xmlrpc.php
            path *.sql
            path /wp-content/uploads/*.php
        }
    
        rewrite @disallowed '/index.php'
    }
    
    Thanked by 2tjn tiendungdev
  • eva2000eva2000 Veteran
    edited January 2023

    @Merakith said: Multi core helps no doubt and more cores the merrier when they are fast. I had tested with various stacks including yours to ensure that there are no anomalies. I had also tested with experimental Nginx unit under the impression that it will be able to handle more php requests due to vertical integration. But the benefits does not reflect for WP sites.

    That probably comes partly down to Nginx tuning as well as PHP-FPM. Centmin Mod PHP-FPM supports Profile Guided Optimization where you can train PHP-FPM on specific PHP application workloads for better optimized path through specific CPUs which can lead to 10-40% better PHP-FPM performance.

    Centmin Mod PHP-FPM PGO isn't enabled by default but optionally can be enabled by end users i.e. Wordpress trained PHP-FPM PGO vs general PHP-FPM PGO vs non-PGO PHP-FPM defaults at https://community.centminmod.com/threads/php-7-3-vs-7-2-vs-7-1-vs-7-0-php-fpm-benchmarks.16090/#post-69010

    As you can see Wordpress specifically trained PGO based PHP-FPM was much faster :)

    Look at Remi Repo PHP 7.3.0 vs Centmin Mod PHP 7.3 PGO WP trained comparison - 747 vs 648 requests/s which are uncached pure PHP requests.

    example for PHP 8 GA and PHP-FPM PGO vs non-PGO https://community.centminmod.com/threads/php-8-0-0-ga-stable-release.20739/#post-87299

    Thanked by 1Merakith
  • @eva2000 Sounds interesting! I'll check it out. Are there any plans to make Centminmod compatible with Alma Linux 9?

  • eva2000eva2000 Veteran
    edited January 2023

    @Merakith said:
    @eva2000 Sounds interesting! I'll check it out. Are there any plans to make Centminmod compatible with Alma Linux 9?

    Best reply I made outlining it at https://community.centminmod.com/threads/almalinux-8-7-released.23456/#post-95570

    The gist is Centmin Mod latest beta has been developing and testing EL8 and EL9 for months now behind private installer/enablement flags, with Centmin Mod AlmaLinux/Rocky Linux 8 currently in private beta testing for some select users right now and EL9 underway for later. The focus is on EL8 first. See the forum almalinux tag to see all relevant threads.

    Any news updates will be posted on Centmin Mod community forums first for EL8/EL9 :)

    Thanked by 1Merakith
  • jsgjsg Member, Resident Benchmarker

    Due to lack of experience with CDNs (no need), almalinux (Devuan preferred) and squeezing the last bit of performance out of ones system (if it's really needed you've not planned well) I can't offer more than to modestly complement @eva2000's advice.
    I did and do run some MySQL + WP though.

    My remarks:

    • 4 cores, and slow ones at that, for both WP and MySQL + shop won't perform well.
    • Everyone talks about processor speed, but do not underestimate the significance of memory (both as in 'fast' and in 'the more the betterer')!
    • My first look would be at MySQL and optimizing its config.
    • If that shop earns more than ridiculously small money get a good and adequate VPS (or if you can afford it even a VDS) from a good provider (@terrahost or @LiteServer are good examples). Prefer (lots and fast) memory over processor speed (Epyc or E5 v4 should do fine, Ryzen or 12900K nice but not really needed) plus be sure that there is a good NVMe.
    • If you know how to do it, "manually" build both PHP and MySQL tailor-fit to your processor.
  • eva2000eva2000 Veteran
    edited January 2023

    @Merakith said: I understand but not happy with the response time on an empty cart page on a fresh installation of wp with zero content and default theme with only woo installed. 4.5 seconds average with webinoly stack.

    Oh missed that part about webinoly stack - yeah when I compared it to Centmin Mod ages back PHP max TTFB was definitely higher - summary on blog https://blog.centminmod.com/2019/07/16/131/centmin-mod-vs-easyengine-vs-webinoly-vs-vestacp-vs-oneinstack-lemp-stack-benchmarks/ and specific for PHP tests at https://community.centminmod.com/threads/php-7-x-benchmarks-centmin-mod-vs-easyengine-vs-webinoly-vs-vestacp-vs-oneinstack.14988/.

    Webinoly at HTTP/2 500 user concurrency PHP-FPM load test had max 99% percentile response time of 4.944s https://community.centminmod.com/threads/php-7-x-benchmarks-centmin-mod-vs-easyengine-vs-webinoly-vs-vestacp-vs-oneinstack.14988/#post-64309. Also 1000, 2000 and 5000 user concurrency PHP tests at https://community.centminmod.com/threads/php-7-x-benchmarks-centmin-mod-vs-easyengine-vs-webinoly-vs-vestacp-vs-oneinstack.14988/#post-64347

    So what was average response times for other stacks compared to webinoly?

    Thanked by 1Merakith
  • eva2000eva2000 Veteran
    edited January 2023

    @jsg said: If you know how to do it, "manually" build both PHP and MySQL tailor-fit to your processor.

    That can make a huge difference. It's why I developed my Centmin Mod LEMP stack to support newer GCC compilers for Nginx and PHP-FPM i.e. GCC 11 on CentOS 7 and GCC 12 on AlmaLinux 8.7+ and 9.1+. I no longer build MariaDB MySQL RPM binaries myself to opt for official MariaDB binaries. But when I built MariaDB 5.2 when it was the new kid of the block years ago, Intel optimized binaries were up to 50% faster than generic built default MariaDB 5.2 binaries provided at the time!

    Thanked by 2jsg Merakith
  • jsgjsg Member, Resident Benchmarker

    @eva2000 said:

    @jsg said: If you know how to do it, "manually" build both PHP and MySQL tailor-fit to your processor.

    That can make a huge difference. It's why I developed my Centmin Mod LEMP stack to support newer GCC compilers for Nginx and PHP-FPM i.e. GCC 11 on CentOS 7 and GCC 12 on AlmaLinux 8.7+ and 9.1+. I no longer build MariaDB MySQL RPM binaries myself to opt for official MariaDB binaries. But when I built MariaDB 5.2 when it was the new kid of the block years ago, Intel optimized binaries were up to 50% faster than generic built default MariaDB 5.2 binaries provided at the time!

    Yep, I know, I had my reasons and experience to recommend that. And btw +50% speed is by far not the best I saw, but then, my work is focused on getting algorithms (mainly crypto, as in en/decryption, hashes, etc., not as in crypto money) running fast. Doubling the speed as compared to a plain build is quite normal there and even multiple speed occurs.

    With PHP I just guessed (reasonably I think, but you'll probably know better/more experience) but with MySQL I know that a significant increase in speed can be achieved.

    Thanked by 2Merakith eva2000
  • @eva2000 said: So what was average response times for other stacks compared to webinoly?

    Webinoly was fastest at 4.5 seconds average, Centminmod at 5 seconds, Caddy+my specific php-fpm & mysql config at 6.5 seconds average, OpenLiteSpeed default being the worst at 9 seconds. Slick stack test didn't complete because I think there is some sort of rate limiter came in between. I have to check their rate limiting config. 100 requests / second on checkout page with DO 4 dedicated cores, 8gb ram and 150gb nvme, 1000 single core gb5.

    I am pretty sure the results will be different if fine tuning is done. I might have not selected the best configuration for all these options. But major objective of these test was not to find out which is the fastest stack but to get an idea of woocommerce performance.

    It made me realize that fast cpu is a very important factor when dealing with woocommerce. Ofcourse right optimizations are required for the sql queries made, etc etc. I had tried an upcoming woocommerce alternative called Northcommerce that was able to handle 100 checkouts per second easily on the DO server. It's been created from scratch for high performance. https://northplugins.com/

    But it's not production ready yet and lack features. I'll stick with woo but with faster cpu as the php throughput drastically increase as you can see in the following link. WP might be limited by SQL in some areas but raw php performance improvement is also important. https://lowendtalk.com/discussion/comment/3276550/#Comment_3276550

    Thanked by 1eva2000
  • MerakithMerakith Member
    edited January 2023

    @jsg said: Yep, I know, I had my reasons and experience to recommend that. And btw +50% speed is by far not the best I saw, but then, my work is focused on getting algorithms (mainly crypto, as in en/decryption, hashes, etc., not as in crypto money) running fast. Doubling the speed as compared to a plain build is quite normal there and even multiple speed occurs.

    That is really good to know. But I am not competent enough to maintain my own binaries with the required tweaking. It also requires time to maintain them with every new release and to compare against upstream. I'll let the authors and distro do the necessary tweaking as they find fit. I do not like to deviate from core much as it makes maintenance difficult in the long run.

    I'll stick to what I can do. Add better hardware, load balance with more servers and try to cache the queries / function at application level. But woo is a different beast and taming it is not easy. Else I'll always try to set transients for repetitively ran functions on my sites.

  • Nice article highlighting single threaded nature of WP. https://makeitwork.press/fast-cpu-fast-wordpress-performance/

  • @Merakith said: Webinoly was fastest at 4.5 seconds average, Centminmod at 5 seconds, Caddy+my specific php-fpm & mysql config at 6.5 seconds average, OpenLiteSpeed default being the worst at 9 seconds. Slick stack test didn't complete because I think there is some sort of rate limiter came in between. I have to check their rate limiting config. 100 requests / second on checkout page with DO 4 dedicated cores, 8gb ram and 150gb nvme, 1000 single core gb5.

    I am pretty sure the results will be different if fine tuning is done. I might have not selected the best configuration for all these options. But major objective of these test was not to find out which is the fastest stack but to get an idea of woocommerce performance.

    Interesting but yes the server probably was the issue there. Besides loader.io also check out k6 benchmarking tool has both a hosted service and self hosted so you have more control over your testing location/parameters too https://k6.io/. Loader.io only tests from US East Coast servers so geographical distance impacts for TTFB matter more. I went down a rabbit hold for k6 testing myself https://github.com/centminmod/k6-benchmarking LOL

    @Merakith said: I had tried an upcoming woocommerce alternative called Northcommerce that was able to handle 100 checkouts per second easily on the DO server. It's been created from scratch for high performance. https://northplugins.com/

    Interesting will keep an eye on this one too

    Thanked by 1Merakith
  • @Merakith said:
    Nice article highlighting single threaded nature of WP. https://makeitwork.press/fast-cpu-fast-wordpress-performance/

    To a certain extent yes. High CPU frequency will always help. Though we're talking PHP-FPM with PHP worker/children which combined with CPU core/thread count configured mix will also have an impact on your final PHP related response times, especially when focusing on concurrent user traffic loads. You can easily test this by ramping up load tests in terms of concurrent users and see :)

    Thanked by 1Merakith
  • ShakibShakib Member, Patron Provider
    edited January 2023

    Someone did posted some WordPress i9-11900K benchmarks here on LET that might still be relevant.

    https://lowendtalk.com/discussion/174106/hostcram-offers-5-10x-the-performance-value-compared-to-vultr-hf/

    Edit: We were in development phase back in 2021 and didn't have automated OS reinstall function. Now we got Cloud Portal with all the necessary functions including start, stop, restart, OS Rebuild, console, etc all in one place.

  • @Merakith said: I understand but not happy with the response time on an empty cart page on a fresh installation of wp with zero content and default theme with only woo installed. 4.5 seconds average with webinoly stack.

    have you got a test url?

Sign In or Register to comment.