A low cache hit ratio of Alibaba Cloud CDN increases the loads on origin servers and slows the retrieval of static resources. You can select a solution to improve cache hit ratios of Alibaba Cloud CDN based on the causes.
Alibaba Cloud CDN caches static resources on edge nodes to accelerate content delivery. When a client requests a resource that is cached on edge nodes, the edge nodes return the requested resource to the client. This simplifies the delivery process, accelerates content delivery, and reduces loads on the origin server. A low cache hit ratio increases loads on the origin server and degrades user experience.
- Byte hit ratio = Number of bytes returned for cache hits/Number of bytes returned for all requests Note A lower cache hit ratio indicates a higher amount of back-to-origin network traffic. A higher amount of outbound traffic from the origin server indicates a higher bandwidth value and more loads on the origin server. Therefore, back-to-origin network traffic represents the amount of loads on the origin server, and the byte hit ratio is the major concern in actual business scenarios.
- Request hit ratio = Number of cache hits/Number of all requests
View cache hit ratios
- Method 1: Use the Alibaba Cloud CDN console The Alibaba Cloud CDN console displays cache hit rate in the following manners:
- Resource monitoringCompared with real-time monitoring, resource monitoring allows you to query cache hit ratios within a longer period of time, for example, the last 30 days. Monitoring data is collected every 5 minutes, and is delayed by approximately 15 minutes. For more information, see Resource monitoring.
- Real-time monitoringCompared with resource monitoring, real-time monitoring allows you to query cache hit ratios within a shorter period of time, for example, the last hour. Monitoring data is collected every minute, and is delayed by approximately 3 minutes. For more information, see Real-time monitoring.
- Resource monitoring
- Method 2: Call API operations
- API operations of resource monitoring
Operation Description DescribeDomainHitRateData Queries the byte hit ratios of one or more accelerated domain names. You can query data collected within the last 90 days. DescribeDomainReqHitRateData Queries the request hit ratios of one or more accelerated domain names. You can query data collected within the last 90 days.
- API operations of real-time monitoring
Operation Description DescribeDomainRealTimeByteHitRateData Queries the byte hit ratios of one or more accelerated domain names. Data is collected every minute. You can query data collected within the last seven days. DescribeDomainRealTimeReqHitRateData Queries the request hit ratios of one or more accelerated domain names. Data is collected every minute. You can query data collected within the last seven days.
- API operations of resource monitoring
Increase the cache hit ratios of Alibaba Cloud CDN
|Solution||Cause and use scenario||Configuration|
|Prefetch resources during off-peak hours||Causes: Before a major event is launched or an installation package is released, required resources are not prefetched on edge nodes. The required resources must be retrieved from the origin server. This reduces the cache hit ratio. |
|Specify a proper time-to-live (TTL) value for cached resources|
Scenarios: Static resources are deployed on the origin server but not cached on edge nodes. The resources cached on edge nodes frequently expire.
|Add a cache rule|
|Ignore the parameters after the question mark (?) in URLs||Causes: If request URLs contain queryString or other variables, the URLs are considered different even if the URLs are used to access the same resource. In this case, the requests are redirected to the origin server. This reduces the cache hit ratio. |
Scenarios: Redirect URLs that contain different query strings to the same resource.
|Configure a policy to retrieve chunks of the resource file from the origin server||Causes: Downloads of installation packages or video streaming may be paused due to various reasons. In some cases, users require only a chunk of a file, but edge nodes return the entire file. The size of the content returned to the users is larger than that of the content requested by the users. In this case, the cache hit ratios are lower than the expected ratios. |
Scenarios: Downloads of installation packages or video streaming.
|Other policies to increase cache hit ratios||Alibaba Cloud CDN also provides other optimization solutions such as the 302 redirection by using the central or edge routing system, merge of back-to-origin requests, and shared cache based on various business requirements.||Alibaba Cloud after-sales engineers configure the policies in the backend.|
View log data of cache hit status
Alibaba Cloud CDN records the cache hit status of all requests. For more information about the log format, see Download logs.
- HIT: indicates a cache hit.
- MISS: indicates a cache miss.
26/Jun/2019:10:38:19 +0800] 192.168.53.146 - 1542 "-" "GET http://example.aliyundoc.com/index.html" 200 191 2830 MISS "Mozilla/5.0 (compatible; AhrefsBot/5.0; +http://example.com/robot/)" "text/html"
You can also call the DescribeCdnDomainLogs operation to query the log data of accelerated domain names.