A low Content Delivery Network (CDN) cache hit ratio increases the workload on your origin server and reduces the access speed for static resources. You can select an optimization policy based on the cause of the low cache hit ratio to improve it.
Background information
CDN accelerates resource access by caching static resources on points of presence (POPs). When a client requests a resource that is cached on a POP, the request hits the cache. The resource is then retrieved directly from the cache and returned to the client. This prevents requests from being redirected to the origin server, which improves response speeds and reduces the bandwidth pressure on the origin server. A low CDN cache hit ratio negatively affects the user experience and increases the bandwidth pressure on the origin server.
CDN byte hit ratio:
Byte hit ratio = (Traffic served by L1 POPs – Back-to-origin traffic served by L1 POPs) / Traffic served by L1 POPs
NoteA lower byte hit ratio indicates higher back-to-origin traffic, which increases the outbound traffic, bandwidth consumption, and workload on the origin server. Therefore, back-to-origin traffic represents the workload on the origin server. In most cases, you should focus on the byte hit ratio.
Request hit ratio = Number of requests that hit the CDN cache / Total number of requests to CDN
ImportantIf range origin fetch is enabled, we recommend that you use the byte hit ratio as the metric for the hit rate.
View the cache hit ratio of CDN
Improve the cache hit ratio of CDN
The following table describes the factors that affect the CDN cache hit ratio and the methods to improve it.
Policy | Factors and scenarios | Configuration method |
Prefetch popular resources before peak hours | Factor: If you do not prefetch resources to POPs before you launch a large-scale operational activity or release a new installation package, many resources must be retrieved from the origin server. This causes a low CDN cache hit ratio. Scenarios:
| |
Configure a reasonable time-to-live (TTL):
| Factors:
Scenario: A user releases static resources on the origin server, but POPs do not cache the resources, or the resources cached on POPs expire in a short period. | |
Remove the parameters that follow the question mark (?) in a URL from the cache key | Factor: When a URL contains a queryString or other variable parameters, requests that use different URLs to access the same resource are redirected to the origin server. This causes a low CDN cache hit ratio. Scenario: You need to access the same resource using different URLs that contain different parameters. | |
Configure a range origin fetch policy for large files | Factor: A user may stop downloading an installation package or watching a video partway through. In this case, the user needs to access only a part of the resource file. However, the POP requests the entire file from the origin server. As a result, the size of the content that the POP downloads from the origin server is larger than the size of the content that is returned to the user. This causes a low cache hit ratio. Scenario: A user downloads an application installation package or watches a video. | |
Other hit rate optimization policies | In addition to the common optimization measures, Alibaba Cloud CDN provides other optimization features that can be configured for different business scenarios, such as central 302 scheduling, edge 302 scheduling, merged origin fetch, and shared cache. | These features are configured by Alibaba Cloud technical support engineers in the background. |
View logs about the cache hit status
The cache hit status of all CDN requests is recorded in the CDN request logs. For more information about the log format, see Fields in offline logs.
Description of the cache hit status field:
HIT: The cache is hit.
MISS: The cache is missed.
The hit status indicates only the status of L1 POPs. For example, if a request misses the cache on an L1 POP but hits the cache on an L2 POP, the log still records a MISS.
Log example:
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 obtain the download URLs of offline logs for an accelerated domain name.

