If the cache hit ratio of Alibaba Cloud CDN is low, the loads on origin servers increase and the retrieval of static resources slows down. You can select a solution to improve the cache hit ratios of Alibaba Cloud CDN based on the causes.
Background information
Alibaba Cloud CDN caches static resources on points of presence (POPs) to accelerate content delivery. When a client requests a resource that is cached on a POP, the POP returns 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 that are returned for cache hits/Number of bytes that are returned for all requests Note A lower cache hit ratio indicates a higher amount of origin traffic. A higher amount of outbound traffic from the origin server indicates a higher bandwidth value and more loads on the origin server. Therefore, origin traffic represents the amount of loads on the origin server, and the byte hit ratio is a 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 byte hit ratios 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, such as, 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, such as, the previous 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: Use the Alibaba Cloud CDN API
- API operations of resource monitoring
Operation Description DescribeDomainHitRateData Queries the byte hit ratios of one or more accelerated domain names. You can query data that is collected in the last 90 days. DescribeDomainReqHitRateData Queries the request hit ratios of one or more accelerated domain names. You can query data that is collected in 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 in 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 in the last seven days.
- API operations of resource monitoring
Increase the cache hit ratios of Alibaba Cloud CDN
Solution | Cause and use scenario | References |
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 POPs. The required resources must be retrieved from the origin server. This reduces the cache hit ratio. Scenarios:
| Manually refresh resources |
Specify an appropriate time-to-live (TTL) value for cached resources
| Causes:
Scenarios: Static resources are deployed on the origin server but are not cached on POPs. The resources that are cached on POPs frequently expire. | Create a cache rule for resources |
Ignore the parameters after the question mark (?) in URLs | Causes: If request URLs contain queryString or other variables, the URLs are considered different regardless of whether 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. | Ignore parameters |
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 POPs return the entire file. The size of the content that is returned to the users is greater than the size of the content that is 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. | Configure the range origin fetch feature |
Other policies for increasing cache hit ratios | Alibaba Cloud CDN also provides other optimization solutions such as 302 redirection by using the central or edge routing system, merging of back-to-origin requests, and cache sharing 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 log formats, 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.