1

We have deployed our website on GCP VM, and enabled GCP CDN in front of the VM. When we browse website in most of the cases GCP CDN making requests to the Origin VM.

I am using below stack driver query to check the cache hits.

resource.type="http_load_balancer"
resource.labels.forwarding_rule_name="rule_name"
httpRequest.serverIp="gcpvmip"
httpRequest.requestUrl="request_url"
httpRequest.cacheFillBytes > 0
Tom Cruise
  • 11
  • 3
  • Have you tried following the troubleshooting steps at https://cloud.google.com/cdn/docs/support#responses-not-cached? If so, can you share the resulting response headers? – elving Jun 01 '18 at 17:34
  • We have checked everything, few times GCP CDN serving the content from its cache and few times GCP CDN hitting the Origin server – Tom Cruise Jun 02 '18 at 15:45

2 Answers2

1

Based on your latest comment, it sounds like you're expecting all requests to your site to be served from Cloud CDN's caches without contacting your origin server. However, it's normal to see cache misses when using a CDN. Each CDN operates numerous caches, not one big global cache. The fact the content for one URL has been inserted into one cache does not mean it will be present in all caches everywhere. Further, unpopular cache entries are routinely evicted from cache to make room for more popular content.

Here are some relevant excerpts from the Cloud CDN docs:

Cloud CDN uses caches in numerous locations around the world. Caching is reactive in that an object is stored in a particular cache if a request goes through that cache and if the response is cacheable. An object stored in one cache does not automatically replicate into other caches; cache-to-cache fill happens only in response to a client-initiated request.

https://cloud.google.com/cdn/docs/overview

Note that the expiration time is an upper bound on how long a cache entry remains valid. There is no guarantee that a cache entry will remain in the cache until it expires.

https://cloud.google.com/cdn/docs/caching

Note, though, that Cloud CDN operates numerous caches around the world, and old cache entries are routinely evicted to make room for new content. As a result, multiple cache fills per resource are expected as part of normal operation.

https://cloud.google.com/cdn/docs/support#low-hit-rate

If you're seeing low cache hit rates for popular content, that last link has suggestions that should help.

elving
  • 1,441
  • 8
  • 7
0

I know exactly what the problem is... GCP CDN does not have Origin Shield feature. Even worse, with GCP almost every request comes from a different one of its massive number of CDN PoPs around the world. Without Origin Shield, your app server is the origin server and it has to fill the cache of every CDN edge point.

In my experience you should use GCP CDN only for DOS protection & caching and improving the TTFB performance of HTML requests (specially to offload SSL handshake). Use another CDN for caching other assets with better Cache/Hit ratio.

Some CDN providers have Origin Shield which helps with the cache hit ratio. E.g. create cdn.yourdomain.com with a CDN provider that has Origin Shield Feature and serve all other static content from there.

I know it may sound crazy to put a CDN in front of your CDN, but trust me it works amazing and you can even save money if you go with a CDN that charges less for bandwidth. Also, GCP CDN only caches content up to 10MB.

Sed
  • 19
  • 1
  • 5
  • `GCP CDN only caches content up to 10MB. ` this is interesting. do you have any link that describe this restriction? – takehiro iyatomi Dec 11 '19 at 02:15
  • The GCP caches content up to 5TB in size; the 10MB limit only applies if the origin doesn't support byte range requests - https://cloud.google.com/cdn/docs/caching#maximum-size (nearly all modern web-servers support them) – elithrar Dec 16 '19 at 22:03