Join the community today
Register Now

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

    534
    237
    43
    Jun 8, 2014
    Ratings:
    +431
    Local Time:
    10:46 PM
    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,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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:
    11:46 AM
  4. eva2000

    eva2000 Administrator Staff Member

    49,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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

    534
    237
    43
    Jun 8, 2014
    Ratings:
    +431
    Local Time:
    10:46 PM
    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,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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

    534
    237
    43
    Jun 8, 2014
    Ratings:
    +431
    Local Time:
    10:46 PM
    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,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 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,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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,300
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,575
    Local Time:
    12:46 PM
    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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 AM
    Mainline
    10.2
    Another question, I can safely omit all console.log right?
    Code:
    console.log(...)
    ....
    ...
    else {
        console.log(...)
    }
     
  15. rdan

    rdan Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 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

    534
    237
    43
    Jun 8, 2014
    Ratings:
    +431
    Local Time:
    10:46 PM
    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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 AM
    Mainline
    10.2
    It's hidden if the page is cacheable, when using the XF2 addon.
     
  18. deltahf

    deltahf Premium Member Premium Member

    534
    237
    43
    Jun 8, 2014
    Ratings:
    +431
    Local Time:
    10:46 PM
    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 Premium Member Premium Member

    5,330
    1,338
    113
    May 25, 2014
    Ratings:
    +2,068
    Local Time:
    10:46 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: