Want to subscribe to topics you're interested in?
Become a Member

TTFB varies 56ms to 280ms for same static files hitting f5

Discussion in 'System Administration' started by Atrix, Oct 7, 2018.

  1. Atrix

    Atrix Premium Member Premium Member

    16
    4
    3
    Oct 7, 2018
    Ratings:
    +12
    Local Time:
    1:56 PM
    1.15.3
    MariaDB 10.1.36
    I'm not sure what is going on, at first the wordpress site I put up with centminmod was getting like 56ms to 137ms span of TTFB using wp super cache. I since upgraded the server even more, though I have added some additional domains.

    I use test.html with the word hello written in it and nothing else. Testing two domains on the server, site 1 which has a working wp installation will very rarely get 80ms TTFB and usually be 250ms+. site2, which has wordpress rules for the conf but no actual working wp site at the moment, will respond with 56ms almost every time and rarely get over 250ms+. I thought it might be a memory thing, but I have over 3 gigs free of memory and I verified the file is loaded in memory using vmtouch. I will leave the network debug window open and keep reloading with f5 to test.

    I'm trying to show off an extremely high page insights rank to my client and this unexplained fluctuation is screwing up my results :( Plus, one of the sites is a webcomic format site, and before the latency got higher, it felt like hitting prev/next was almost like it was local. Now you can definitely feel it's over a network. I'm just not sure what caused it to change and get longer, and why hitting f5 a lot even if I verify it's already in memory, seems to randomly make it not take so long and then the next load it's long response time again!

    I tried shifting settings but it always just ends up having no result. The only one that made any diff was to uncomment the lines for static files for html and txt extensions. This made it better. I'm still not sure why it went from speedy as it was to this. Is there wany way to tell a breakdown of ms for each stage of it serving the static file to troubleshoot better? Or maybe you already have an idea of the cause. Please help!
     
  2. eva2000

    eva2000 Administrator Staff Member

    41,296
    9,267
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,218
    Local Time:
    5:56 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Using local browser devtools networking tests can also be subject to your local pc performance variance as well. So you might want to supplement tests with a 3rd party like webpagetest.org. See my guide at WebPerf - PageSpeed - How to use webpagetest.org for page load speed testing

    Inspect the test.html headers too to see if browser caching is used which would be if you uncomment .html location context in staticfiles.conf include file.

    Are sites using HTTPS or non-HTTPS ?

    To test and inspect headers
    Code (Text):
    curl -I http://site1.com/test.html
    curl -I https://site1.com/test.html
    

    Code (Text):
    curl -I http://site2.com/test.html
    curl -I https://site2.com/test.html
    


    Tried different browsers too ?

    Did you test network dev tools with check box for disable cache or without checking disable cache ?
     
  3. Atrix

    Atrix Premium Member Premium Member

    16
    4
    3
    Oct 7, 2018
    Ratings:
    +12
    Local Time:
    1:56 PM
    1.15.3
    MariaDB 10.1.36
    The webpagetest.org site has given me D, C and A grades for TTFB. The A grade seems pretty rare though. I consistently get A for all the other tests. Google page insights also has this same issue, except their passing grade seems a higher bar to not get deductions, requiring under 200ms, webpagetest gave me an A with .46s, a lot of tests were more like .71s tho

    I have disable cache selected when I run the tests. And I accounted for network variance of my own connection by testing with ping to google to make sure it's fairly stable. I used chrome, firefox and edge as testing browsers for the speed tests, as well as iron browser (made from chromium).

    I'm using http/2 SSL only behind cloudflare, and this may be a part of the issue, as if I change my hosts file to point to the server directly to bypass cloudflare and load up the test files or the cached webpage files stored in html, it seems to work most the time getting sub 60ms. However, I have to add security exceptions for the certificates when I do it this way so I'm not sure if that could be messing with the results. Thank you for replying, any ideas? I've submitted a ticket with cloudflare now but wondering if any of the config options should be tweaked for the ssl or use with cloudflare and perhaps a slowdown is caused by that.
     
    Last edited: Oct 8, 2018
  4. eva2000

    eva2000 Administrator Staff Member

    41,296
    9,267
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,218
    Local Time:
    5:56 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    That explains it cloudflare in front will raise TTFB somewhat especially if request is not served out of cloudflare cache. With Cloudflare in front, don't focus just on TTFB but webpagetest Speedindex and perceived visual render time and first contentful and first meaningful paint and document loaded times as that is where Cloudflare can benefit at the expense of higher TTFB. Google PageSpeed Insight also focuses of first contentful paint and document loaded times as well and not TTFB.
     
    • Like Like x 1
  5. Atrix

    Atrix Premium Member Premium Member

    16
    4
    3
    Oct 7, 2018
    Ratings:
    +12
    Local Time:
    1:56 PM
    1.15.3
    MariaDB 10.1.36
    Just an update, I was able to get it to most the time respond sub 100ms by adding a page rule to cloudflare for domain.com/* to cache everything. I can only get away with this because the site already makes static files out of every page anyway the only time there's dynamic content is when a new post is added or someone comments. Hopefully don't need to upgrade the account to use an api to refresh and can set the cache time low enough but we'll see. Either way found and fixed the problem for now much thanks!
     
    • Informative Informative x 1
  6. eva2000

    eva2000 Administrator Staff Member

    41,296
    9,267
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +14,218
    Local Time:
    5:56 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Yeah that would work only because you have static pages. For dynamic you'd need Cloudflare Business plan and bypass cache on cookie to cache for guests Caching Anonymous Page Views and utilise Cloudflare Railgun for accelerating dynamic content Railgun™ | Cloudflare
     
    • Like Like x 1