Want more timely Centmin Mod News Updates?
Become a Member

Benchmarks Optimizing and tuning WordPress and XenForo with NewRelic

Discussion in 'Dedicated server hosting' started by deltahf, Oct 8, 2021.

  1. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    Ah, nice, I can't recall the exact reason, but I didn't think I could use optimise-images.sh for XF files. I think because it doesn't affect the file's metadata? Also, the plugin processes new uploads automatically which is important for me.

    Oh wow, that's a great feature. :D

     
  2. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    Yeah wasn't sure myself, that our mutual friend did make it work - but yeah auto processing on new uploads is definitely a benefit of using that plugin :)

    Yeah it could be a dummy version to only work on past 24hrs of images created.
     
  3. Eddie

    Eddie New Member

    9
    0
    1
    Oct 4, 2018
    Ratings:
    +0
    Local Time:
    1:42 AM
  4. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    Probably, eventually it would but no plans or timeline right now as it isn't a priority. Especially since from a lot of tests, there's a 50/50 chance that AVIF images end up larger than webP versions.
     
  5. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    Just had a look at my CloudFlare Worker stats and thought this was interesting. My custom CF Worker which caches WordPress pages went live on January 12, 2022. We can see Workers are serving around 4-6GB more cached bandwidth per day, and nearly (if not all) of that is the HTML of the articles being served from the edge POPs. Screen Shot 2022-01-30 at 12.09.59 AM.png
     
  6. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    Yup looks as expected if you're doing full HTML page caching at Cloudflare CDN level :D
     
  7. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    My site had a huge traffic event today and just blasted to a record number of active users in Google Analytics!

    Screen Shot 2022-02-02 at 5.47.07 PM 2.png

    The previous record of 1,200 would have been higher, but my server at the time had a complete meltdown and lost me a crazy amount of traffic. This time, thanks to Centminmod and all these optimizations, I was ready. :D

    My server never even blinked during the traffic spike as Cloudflare handled almost the entire load, especially thanks to my custom Worker. You can see what happened behind the scenes in these charts. The event occurred around 5:30pm.

    Cloudflare Cache Performance:

    Screen Shot 2022-02-03 at 1.48.53 AM.png

    Server Load:

    Screen Shot 2022-02-03 at 1.49.47 AM.png

    WordPress APM charts:

    Screen Shot 2022-02-03 at 1.50.09 AM.png

    XenForo APM charts:

    Screen Shot 2022-02-03 at 1.50.21 AM.png
     
  8. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    Congrats mate - as it should be with all the optimizations in place and Cloudflare Worker based guest full page HTML caching in action :D

    With Cloudflare guest full page HTML caching in place, you'd have a lot of room to move :)
     
  9. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    Hi!

    Thanks for your code.
    I modify it a bit for XF2 usage only.

    Something to note:
    xf_user = XenForo cookie when "Stay logged in" is check
    xf_lscxf_logged_in = from this addon, unique cookie for logged in users
    x-litespeed-cache-control = from this addon, added http response header for pages that should not be cached

    Please check my modification, 0% coder here :D

    https://add.pics/images/2022/06/06/imageecdab9f5177f5c09.png

    upload_2022-6-7_0-24-22.png

    But comparing from the code I use here:
    https://community.centminmod.com/threads/what-cf-worker-usage-model-to-use.22846/#post-93301

    You didn't declare or use: cf: { cacheTtl
    Why is that?

    Thanks!
     
    Last edited: Jun 7, 2022
  10. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    FYI, there's 2 methods of doing Cloudflare Worker caching

    1. using CF Worker's Cache API example at https://developers.cloudflare.com/workers/examples/cache-api/ or

    2. using fetch method caching at https://developers.cloudflare.com/workers/examples/cache-using-fetch/

    You're using the latter while @deltahf is using Cache API. The fetch method allows for finer grain control over caching and additional CF parameters you may want to enable or disable.
     
  11. eva2000

    eva2000 Administrator Staff Member

    49,741
    11,439
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,774
    Local Time:
    2:42 AM
    Nginx 1.21.x
    MariaDB 10.x
    Be sure you checked for XF2 overlay handling and guest posting situations Compatibility for CSRF protection & Cloudflare full HTML page caching.
     
  12. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    How to cache 301 request also, modify the code to this?
    HTML:
    if (response.status != 200) || (response.status != 301) {
          return response
    }
     
  13. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    Another question, the example codes has mostly ; or semi colon closing, but yours don't have.
    Is that fine with Javascript?
     
  14. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    Another question, I can safely omit all console.log right?
    Code:
    console.log(...)
    ....
    ...
    else {
        console.log(...)
    }
     
  15. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    I tried your Code @deltahf with only xf_cookie and noCacheHeader changes, and I can't make it work :(

    HTML:
    const has_target_cookies = Boolean(
          cookies.includes('xf_user') || cookies.includes('xf_lscxf_logged_in')
    );
    
    const noCacheHeader = response.headers.get('x-litespeed-cache-control')
        if (!noCacheHeader) {
    
    This worker needs special page rule?
    What else I'm missing?
     
    Last edited: Jun 7, 2022
  16. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    Sorry @rdan, didn't mean to leave you hanging, just now cleaning out my Inbox and realized you replied here!

    Yes that should work.
    Yes, semi-colons are optional in JavaScript. I don't like using them.

    Semicolons in JavaScript

    Yes, I just find it helpful for debugging with Wrangler. :)

    There is no harm in leaving it in. Console logs don't actually go anywhere unless you are actively viewing wrangler logs, as far as I know.

    My guess is that the x-litespeed-cache-control header always contains a string of some sort (one of these values), which evaluates to true in a Boolean context. So, when you're negating it, it is always false, so your code designed to do the caching is never actually getting reached.

    Try checking for specific values in the header before you evaluate it inside that conditional.
     
  17. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    It's hidden if the page is cacheable, when using the XF2 addon.
     
  18. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    Hidden, as in the header does not exist?

    So just to clarify, you only want the page to be cached by the worker if the header is not present? Because it looks to me like that's what the code will be doing now.

    Clearly something isn't working the way that we expect it to, so the next step is to question your assumptions. I'd recommend starting with some console.log() statements in order to verify the values of the important variables here. For example, check to see the value of the x-litespeed-cache-control really is empty when you expect it to be, or check to see if the code really is entering into that conditional there when you want it to.
     
  19. rdan

    rdan Well-Known Member

    5,368
    1,348
    113
    May 25, 2014
    Ratings:
    +2,110
    Local Time:
    12:42 AM
    Mainline
    10.2
    Yes, for cacheable pages.

    Correct.

    When I tested it few days ago... I think it's not working when XenForo 2 because of this response header:
     
  20. deltahf

    deltahf Premium Member Premium Member

    543
    244
    43
    Jun 8, 2014
    Ratings:
    +443
    Local Time:
    11:42 AM
    Have not updated this thread in a while but I've also not made too many significant performance optimizations recently. However, after updating to PHP 8.1 and rebooting the server, I did noticed a significant drop in performance according to NewRelic. It's time to dig in and find out what's going on.

    Both WordPress and XenForo are affected, but WordPress has been hit the worst. I am now seeing uncached WordPress TTFB times of 500+ms. The increase in transaction times is visible after the upgrades were performed in the early morning hours of December 11.

    Screen Shot 2022-12-13 at 4.58.57 AM.png

    Screen Shot 2022-12-13 at 4.59.12 AM.png

    As we can see from the graph, all of the increased response time is caused by PHP. After updating from 8.0 to 8.1 and verifying that everything was working correctly, I decided to update the rest of the software on the server as well, including the kernel, and reboot.

    Code (Text):
    $ yum update --disableplugin=priorities --setopt=deltarpm=0 --enablerepo=remi
    
    ...
    
    ========================================================================================================================================
     Package                                Arch                 Version                                 Repository                    Size
    ========================================================================================================================================
    Installing:
     kernel                                 x86_64               3.10.0-1160.80.1.el7                    updates                       52 M
     kernel-devel                           x86_64               3.10.0-1160.80.1.el7                    updates                       18 M
    Updating:
     MariaDB-client                         x86_64               10.4.27-1.el7.centos                    mariadb                       12 M
     MariaDB-common                         x86_64               10.4.27-1.el7.centos                    mariadb                       81 k
     MariaDB-compat                         x86_64               10.4.27-1.el7.centos                    mariadb                      2.2 M
     MariaDB-devel                          x86_64               10.4.27-1.el7.centos                    mariadb                      7.7 M
     MariaDB-server                         x86_64               10.4.27-1.el7.centos                    mariadb                       26 M
     MariaDB-shared                         x86_64               10.4.27-1.el7.centos                    mariadb                      113 k
     bind-export-libs                       x86_64               32:9.11.4-26.P2.el7_9.10                updates                      1.1 M
     bind-libs                              x86_64               32:9.11.4-26.P2.el7_9.10                updates                      158 k
     bind-libs-lite                         x86_64               32:9.11.4-26.P2.el7_9.10                updates                      1.1 M
     bind-license                           noarch               32:9.11.4-26.P2.el7_9.10                updates                       91 k
     bind-utils                             x86_64               32:9.11.4-26.P2.el7_9.10                updates                      261 k
     ca-certificates                        noarch               2022.2.54-74.el7_9                      updates                      911 k
     copy-jdk-configs                       noarch               3.3-11.el7_9                            updates                       22 k
     dkms                                   noarch               3.0.8-1.el7                             epel                          84 k
     elasticsearch                          x86_64               7.17.8-1                                elasticsearch                300 M
     expat                                  x86_64               2.1.0-15.el7_9                          updates                       83 k
     expat-devel                            x86_64               2.1.0-15.el7_9                          updates                       58 k
     galera-4                               x86_64               26.4.13-1.el7.centos                    mariadb                       10 M
     java-11-openjdk                        x86_64               1:11.0.17.0.8-2.el7_9                   updates                      238 k
     java-11-openjdk-headless               x86_64               1:11.0.17.0.8-2.el7_9                   updates                       39 M
     kernel-headers                         x86_64               3.10.0-1160.80.1.el7                    updates                      9.1 M
     kernel-tools                           x86_64               3.10.0-1160.80.1.el7                    updates                      8.2 M
     kernel-tools-libs                      x86_64               3.10.0-1160.80.1.el7                    updates                      8.1 M
     kpartx                                 x86_64               0.4.9-136.el7_9                         updates                       81 k
     krb5-devel                             x86_64               1.15.1-55.el7_9                         updates                      273 k
     krb5-libs                              x86_64               1.15.1-55.el7_9                         updates                      810 k
     libkadm5                               x86_64               1.15.1-55.el7_9                         updates                      180 k
     microcode_ctl                          x86_64               2:2.1-73.15.el7_9                       updates                      4.5 M
     newrelic-daemon                        x86_64               10.3.0.315-1                            newrelic                     4.6 M
     newrelic-infra                         x86_64               1.35.0-1.el7                            newrelic-infra                41 M
     newrelic-php5                          x86_64               10.3.0.315-1                            newrelic                      11 M
     newrelic-php5-common                   noarch               10.3.0.315-1                            newrelic                      40 k
     nri-mysql                              x86_64               1.8.2-1                                 newrelic-infra               1.8 M
     nri-nginx                              x86_64               3.2.5-1                                 newrelic-infra               2.1 M
     nspr                                   x86_64               4.34.0-3.1.el7_9                        updates                      128 k
     nss                                    x86_64               3.79.0-4.el7_9                          updates                      895 k
     nss-softokn                            x86_64               3.79.0-4.el7_9                          updates                      379 k
     nss-softokn-freebl                     x86_64               3.79.0-4.el7_9                          updates                      337 k
     nss-sysinit                            x86_64               3.79.0-4.el7_9                          updates                       66 k
     nss-tools                              x86_64               3.79.0-4.el7_9                          updates                      555 k
     nss-util                               x86_64               3.79.0-1.el7_9                          updates                       80 k
     python-perf                            x86_64               3.10.0-1160.80.1.el7                    updates                      8.2 M
     redis                                  x86_64               7.0.5-2.el7.remi                        remi                         1.5 M
     remi-release                           noarch               7.9-4.el7.remi                          remi                          23 k
     rsync                                  x86_64               3.1.2-11.el7_9                          updates                      408 k
     systemd                                x86_64               219-78.el7_9.7                          updates                      5.1 M
     systemd-devel                          x86_64               219-78.el7_9.7                          updates                      216 k
     systemd-libs                           x86_64               219-78.el7_9.7                          updates                      419 k
     systemd-sysv                           x86_64               219-78.el7_9.7                          updates                       97 k
     tuned                                  noarch               2.11.0-12.el7_9                         updates                      270 k
     tzdata                                 noarch               2022f-1.el7                             updates                      491 k
     tzdata-java                            noarch               2022f-1.el7                             updates                      185 k
    Removing:
     kernel                                 x86_64               3.10.0-1160.45.1.el7                    @updates                      64 M
     kernel-devel                           x86_64               3.10.0-1160.45.1.el7                    @updates                      38 M
    


    I have checked the PHP error logs to be sure that none of my software is filing complaints because it is now running on 8.1 but nothing is unusual. I have also checked to be sure that my server's CPU is still running at its higher clock speeds after the reboot, and it is.

    At this point my first assumption is that the upgrade process has possibly overwritten some of my PHP configuration/optimization settings, but at first glance I don't see anything out of place, and PGO is still showing as activated. This will require further investigation.

    Code (Text):
    $ php -v
    PHP 8.1.13 (cli) (built: Dec 11 2022 08:40:44) PGO (NTS)
    Copyright (c) The PHP Group
    Zend Engine v4.1.13, Copyright (c) Zend Technologies
        with Zend OPcache v8.1.13, Copyright (c), by Zend Technologies