TTFB Too hight (1.2 sec on Cloudflare)


#1

Hi

My Site is https://www.myupchar.com

I am looking at Newrelic which says, Haproxy responds in 100-150ms average. Also, my backend usually respond within 90-120 sec (using Ruby on Rails, mySQL, Memcache).

But TTFB according to WebpageTest is 1.48 seconds - I have tried multiple tools and tested various page types on site but all of them come with fairly high TTFB.

I am unable to explain except for the fact that Cloudflare may have something to do with it. Can you tell me how we can diagnose this problem and resolve it?
http://www.webpagetest.org/result/180131_AZ_ee35631fa56c392a4ab1ad96026818b6/

Any pointers will be greatly appreciated.


#2

If you give us your origin IP address, we can them compare to see if it’s CloudFlare adding time or not.
Also - if you were to use a page rule to cache the entire home page (including html), you can get the TTFB close to 20ms, and full html download under 50ms.


#3

Cloudflare isn’t going to speed up TTFB if your main page isn’t cached (I could be wrong on this). Cloudflare is actually going to add a bit of overhead to TTFB as it fetches the main page from your origin server.

What’s really going to matter is the overall load time of your site, which should be greatly improved through appropriate use of Cloudflare.


#4

My Origin IP Address is - 139.59.11.212

Issue with entire page caching is that logged in users need to be treated differently. How can we handle this using full page caching?


#5

If you read the comments below the article, it kind of nullifies the argument given. All the metrics matter and TTFB is one of them.

Also, if you look at slow network connection countries like India where most of our traffic is from, all of this adds up.


#6

rajat, the only way you can do that is to put the user ID (or token) in a url variable, then have a wildcard page rule to cache all of those.


#7

Tested from my workstation. TTFB is a bit higher from Cloudflare, but total time to retrieve is much lower.

curl -ko /dev/null --resolve www.myupchar.com:443:you.origin.ip.address \
-H ‘Cache-Control: no-cache’
-s
-w “Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n”
https://www.myupchar.com

TTFB direct to origin:
Connect: 0.260 TTFB: 1.255 Total time: 3.324
Connect: 0.265 TTFB: 1.158 Total time: 3.794
Connect: 0.261 TTFB: 1.121 Total time: 3.455

curl -ko /dev/null \
-H ‘Cache-Control: no-cache’
-s
-w “Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n”
https://www.myupchar.com

TTFB through Cloudflare:
Connect: 0.050 TTFB: 1.342 Total time: 1.873
Connect: 0.051 TTFB: 1.190 Total time: 1.726
Connect: 0.049 TTFB: 1.448 Total time: 1.741


#8

It also appears when testing from that particular colo their connection is to our CDG POP which is in France. That could be a function of the EC datacenter in the test having unique connectivity/ BGP routing or it could be a function of colos in that region available for the plan type for your domain.

http://www.webpagetest.org/result/180201_S5_28fe2c739fe37d1af2905194a775b35e/

Tools like web page test are good, but they aren’t run from endpoints where user eyeballs are so their results can be different from what users experience. You can connect to https://www.myupchar.com/cdn-cgi/trace and the colo corresponds to airport codes which how we geographically identify our POPs. If you also see a very distant POP plan type may be a factor, but TTFB for the page is a little high regardless (even direct to origin).


#9
  1. It shows a colo of LHR whereas 99% of traffic originates from India. Is that an issue? How can we address that?

  2. Also, you mentioned that TTFB, when you bypassed Cloudflare, is still 1.2 seconds. However, two reports from Newrelic indicate that LB responds in 150ms and backend servers are also fairly fast.

See images -

  1. Also, is there a possibility of getting this addressed in Business plan? We can try to use cookies for signin vs sessions that we use now. It seems that there is an option to bypass page caching if there are cookies in it.

#10

I used the same commands that you shared but my TTFB is very different (from an Indian server pinging another server in a different C Class but same hosting company, DigitalOcean)-

When I bypassed Cloudflare -
Connect: 0.002 TTFB: 0.098 Total time: 0.101
Connect: 0.002 TTFB: 0.089 Total time: 0.659
Connect: 0.002 TTFB: 0.186 Total time: 0.549

When I executed the second command and it went through TTFB -
Connect: 0.206 TTFB: 1.832 Total time: 3.633
Connect: 0.160 TTFB: 1.489 Total time: 2.190
Connect: 0.154 TTFB: 1.460 Total time: 2.697


#11

The this test was from 2 machines in the same datacenter? I would generally expect the results to be ridiculously fast (and they are). But that doesn’t mimic or correlate to what end users will see in terms of performance. The speed of light is fast, but it’s not infinite… there’s a certain level of latency which is going to be introduced through distance and each network hop that is simply unavoidable. For my two tests for example my direct test went from Austin, TX (US) to the origin server which I assume is in Bangalore since it’s DO. That’s a 19,000+ mile round trip and my colo location adds another 3000 miles to my tests through Cloudflare due to my personal network configuration. Time and hops add up.

For data hosted in Bangalore it’s probably not the ideal route for users to hit a POP in LHR, but for the plan you are currently on it may be the closest available colo for your particular network/ plan type. I suspect you would probably get better performance in the current scenario if the content were hosted on one of the DO instances in Europe.

Cloudflare sales or support(at)cloudflare(dot)come might be able to tell you if additional POPs in India are available on the Pro and/or Biz plan, sorry I don’t have the current details there. Ability for users to hit a closer POP would also likely also help improve TTFB given it appears the DC hosting the origin server is also in region. India is a key area for expansion and growth for Cloudflare… I actually keep trying to convince my boss I need to go on an extended visit to spread Cloudflare love there. :slight_smile:


#12

Cloudflare business plan does offer bypass cache on cookie. Session is a little harder if it’s not defined by a cookie… custom cache key might be an option (that’s an ENT feature only today unfortunately). Finding the right balance for caching at the edge for customized content can be a tricky business… Railgun might also help for dynamic content performance and Argo is is another possibility as well.


#13

My TTFB is also long – 2.62 seconds.

I am utterly confused by all of the TTFB talk. Is there anyone who can help offer advice? My website is paper blazer dot com.

I will love you forever and ever.

Thank you!!!


#14

Your TTFB is also extremely high when going direct to the origin. So for uncached requests/ dynamic content we have to wait on the origin as well. For pages where you can leverage cache everything that might help, but for dynamic content a less overloaded origin and/or possibly railgun might help.


#15

without CF
curl -ko /dev/null --resolve epfo.services:80:139.59.91.100 \ -H ‘Cache-Control: no-cache’ -s -w “Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n” http://epfo.services
Connect: 0.000000 TTFB: 0.000000 Total time: 0.124665
Connect: 0.000000 TTFB: 0.000000 Total time: 0.509377
Connect: 0.000000 TTFB: 0.000000 Total time: 0.124728
<DOCTYPE html
<\html>
Connect: 0.027933 TTFB: 0.292492 Total time: 0.402994

with cF

curl -ko /dev/null --resolve epfo.services:80:139.59.91.100 \ -H ‘Cache-Control: no-cache’ -s -w "Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" http://epfo.services

Connect: 0.000000 TTFB: 0.000000 Total time: 0.124693
Connect: 0.000000 TTFB: 0.000000 Total time: 0.253018
Connect: 0.000000 TTFB: 0.000000 Total time: 0.124560
!DOCTYPE html>

Connect: 0.023965 TTFB: 0.057787 Total time: 0.107832

I really confused about the above data and command whether is accurate or not

datacenter located in banglore digital ocean.

when it was at china speed is good but now it worse.

how to improve Cloudflare Indian traffic?

is it better to turn off Cloudflare performance?
or pay something to Cloudflare for Indian colocation for 30+ sites in my account.

migrating datacenter to any other location which Cloudflare pop routed for my traffic.

anyways to change the co-location of my website?
or can Cloudflare team set default colocation for my account?

how to frequently colocations changes for a website?


#16

Both of your commands directly hit the origin server. By specifying your origin IP address, you’re bypassing Cloudflare. My eyes may have missed something, but both commands are identical, correct?

My favorite tool does show that Bangalore has the slowest TTFB:
https://performance.sucuri.net/domain/epfo.services

A test from Mumbai shows your domain using Cloudflare’s Tokyo POP. I know Cloudflare has a Mumbai datacenter, so I don’t know why it’s not using that.


#17

Cloudflare limited Indian pops to paid plan. (Official said on another topic).

But I have noticed my another free plan website
Used MAA Chennai Indian location.

How frequently these collocations are change?

How much percentage of traffic routed through specific colocation?

Since my traffic is 100% from India. Any other ways to optimize it.
Maybe blocking all countries other than india, is this route colocation servers India only.

Is it better turnoff cloudflare?
How to use cloudflare only as dns proxy?so requests serves from origin data center.


#18

I know some POPs don’t serve free plans, but I haven’t seen an official list. I think it changes from time to time as costs come down. I don’t know if they limit how much of your traffic would go through a more expensive POP. I’ve not heard of such an arrangement.

Blocking countries from your website most likely won’t change this. Maybe a paid CDN company has datacenter in India. But at that point, you could just pay for Cloudflare. I’ve used KeyCDN in the past and their prices are decent, though Asia traffic costs 3x Europe/North America. They have a POP in Bangalore. Maybe the $20/month here is the best deal.

You can certainly turn off the Cloudflare proxy by setting your DNS entry to :grey:. You’ll get very fast DNS performance, with the benefit of your local datacenter.


#19

then Cloudflare shared SSL doesn’t work on my domain. so I have to install let’s encrypt