avatarJen-Hsuan Hsieh (Sean)

Summary

The article discusses Cloudflare's caching mechanisms and their impact on network latency, detailing how to verify if Cloudflare has cached static resources and the benefits and potential drawbacks of using Cloudflare's services.

Abstract

The article "APM & Logging Services Part.3 — The cache of Cloudflare" delves into the role of Cloudflare as a reverse proxy in a Content Delivery Network (CDN) and how its Anycast routing and distributed data centers minimize network latency. It explains the caching process, where stored resources from one request are reused for subsequent requests, reducing the load on origin servers. The author guides readers through checking the cache status using response headers and the curl command on UNIX-like platforms. The article also outlines the types of resources Cloudflare caches by default and discusses the latency that can occur at different stages of a client's request, from DNS lookup to SSL handshake, and how Cloudflare's caching can mitigate these delays. Tools like Pingdom are recommended for evaluating latency improvements. While acknowledging Cloudflare's benefits, the author also mentions potential side effects, such as the need to change name servers and the possibility of increased latency if Cloudflare has not yet cached content. The article concludes with an invitation for feedback and provides links to related topics and references for further reading.

Opinions

  • The author, Sean, emphasizes the importance of understanding Cloudflare's caching mechanisms for optimizing website performance.
  • Cloudflare's default caching behavior is seen as beneficial for static content but insufficient for dynamic content and HTML files.
  • The use of Cloudflare is presented as generally advantageous for reducing network latency, but the author notes that it can introduce latency if content is not yet cached, especially over greater distances.
  • The article suggests that Cloudflare's caching can significantly improve the "send, wait, and receive" phases of a client's request by serving content closer to the user.
  • The author provides a balanced view by discussing both the advantages of Cloudflare's services and the considerations that need to be taken into account, such as the necessity to change name servers.
  • Sean encourages readers to engage with the content by providing feedback and offers additional resources for those interested in learning more about Cloudflare, APM & Logging Services, IT & Network, Database, Software testing, Debugging, and DevOps practices.

APM & Logging Services Part.3 — The cache of Cloudflare

Copy right@A layman

As I have ever introduced it in the previous article, Cloudflare is one kind of the reverse proxy of CDN (Content Delivery Network).

The physical data server location relates to the network latency. With the AnyCast and distributed data center around the world, the requests will pass to the data server which is close to the client.

There are several hops from the client and the data server. However, we don’t have to go back to the server after caching the static resources on the CDN.

We will talk about the network latency and cache in this topic.

Source: https://www.cloudflare.com/zh-tw/

Cache from Cloudflare

Caching is the process of storing resources from one request and reusing those resources for subsequent requests. The original servers don’t have to handle the requests.

1.Make sure that Cloudflare has already cached the static resources

The first thing to do is getting the header of the response. You can retrieve the response headers by using curl on UNIX-like platform.

curl -svo /dev/null explore.garmin.cn/css/main.css

We can get useful information there.

Copy right@A layman

CF-Cache-Status We can look for the CF-Cache-Status to realizing the cache status. You can refer to the following table to look at the data types that Cloudflare will cache by the default setting.

Source: https://support.cloudflare.com/hc/en-us/articles/200168266-What-do-the-various-Cloudflare-cache-responses-HIT-Expired-etc-mean-

Server Cloudflare won’t cache some resource types by default. In this case, it will not show CF-Cache-Status in the header. You can refer to the following list.

Notice that Cloudflare won’t cache the dynamic content and the HTML files by the default setting.

Source: https://support.cloudflare.com/hc/en-us/articles/200172516-Which-file-extensions-does-CloudFlare-cache-for-static-content-

2. Where does the latency occur?

As we mentioned before, the physical data server location relates to the network latency.

To answer this question, we can review the client side process by checking the timeline from Pingdom.

Copy right@A layman
  1. DNS In this phase, the user’s browser must perform domain lookup when the web page references content from another domain. It will increase more delays if the website uses domain sharding.
  2. SSL In this phase, the client waits for the SSL handshake with the server.
  3. Connect
  4. Send In this phase, the client sends requests to the server.
  5. Wait (TTFB) In this phase, the client waits for the first byte (Time To the First Byte) from the server. It includes operation such as the database operation and insufficient server resources.
  6. Receive In this phase, the client waits for all data from the server.

The latency for send, wait, and receive will increase with the distance between the server and the client.

3.How to evaluate the latency improvement from Cloudflare?

Use Pingdom to test the same site twice. It will cache the static resources on the second time.

Copy right@A layman

The left part doesn’t cached contents yet (Revalidated). The right part cached (Hit).

The cache can improve the network latency for send, wait, and receive phases because because the requests don’t need to go back to the server after the caching.

3. Will Cloudflare cause any Side effects or disadvantages?

As we know, Cloudflare is one kind of reverse proxy which acts as an intermediary server between the client and the server.

It still have some disadvantages:

  • First, you have to change the name server to point directly to Cloudfare.
  • Second, Reverse proxy will increase the latency of send, wait, and receive with distance increasing if Cloudflare doesn’t cache yet.

Summary

Thanks for your patient. I am Sean. I work as a software engineer.

This article is my note. Please feel free to give me advice if any mistakes. I am looking forward to your feedback.

Please feel free to clap if this article can help you. Thank you.

You can also subscribe my page on Facebook.

Related topics

APM & Logging Services:

IT & Network:

Database:

Software testing:

Debugging:

DevOps:

References

  1. What do the various Cloudflare cache responses (HIT, Expired, etc.) mean?
  2. Which file extensions does Cloudflare cache for static content?
  3. Kinsta CDN vs Cloudflare CDN — Which One Should You Use?
  4. 某交易網站經常出現 Error 520 ? Cloudflare和Ray ID是甚麼 ?
  5. Error 520: Web server is returning an unknown error
  6. What is Domain Sharding?
  7. How to Analyze and Improve Page Load Performance
  8. Maximum concurrent connections to the same domain for browsers
  9. How to Properly Run a Website Speed Test (You’re Doing it Wrong)
  10. Network Latency — Comparing the Impact on Your WordPress Site
  11. WordPress CDN — Why You Should Be Using One in 2019
  12. How can I tell if Cloudflare is caching my site or a specific file?
Web Development
Cloudflare
Cdn
Debugging
DevOps
Recommended from ReadMedium