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 low cache hit ratios of Alibaba Cloud CDN based on the causes.

Background information

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 experiences.

The cache hit ratios of Alibaba Cloud CDN are classified into byte cache hit ratios and request cache hit ratios.
  • Byte cache hit ratio = Number of bytes returned for cache hits/Number of bytes returned for all requests
    Note A lower byte 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 cache hit ratio is the major concern in actual business scenarios.
  • Request cache hit ratio = Number of cache hits/Number of all requests

View cache hit ratios

You can view cache hit ratios by using the following methods:
  • Method 1: Use the console
    The Alibaba Cloud CDN console displays byte hit ratios in the following ways:
    • Resource monitoring
      Compared 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 about 15 minutes. For more information, see Resource monitoring. Cache hit ratio
    • Real-time monitoring
      Compared 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 about 3 minutes. For more information, see Real-time Monitoring. Quality Monitoring
  • Method 2: Call API operations
    • API operations of resource monitoring
      API 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
      API 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.

Increase the cache hit ratios of Alibaba Cloud CDN

The following table describes the causes of low cache hit ratios and the solutions.
Solution Cause and use scenario Configuration
Prefetch resources during off-peak hours Causes: Before a major event or the release of an installation package, required resources are not prefetched to edge nodes. The required resources must be retrieved from the origin server. This reduces the cache hit ratio.
Use scenarios:
  • Provide support for major events

    If you want to hold a major event, you can push the static resources of the event page to CDN edge nodes. After the event starts, visitors can access the static resources, which are already cached on CDN edge nodes. This accelerates content delivery.

  • Release installation packages

    Before you release an installation or upgrade package of a product, you can push the package to CDN edge nodes. After the product is launched, visitors can download the package from CDN edge nodes. This accelerates content delivery and reduces loads on origin servers when a large number of visitors want to access your resources.

Prefetch resources
Set a proper time-to-live (TTL) value for cached resources
  • Specify a TTL value of one month or longer for static files that are infrequently updated, such as images and application packages.
  • Specify a TTL value based on your business requirements for static files that are frequently updated, such as JavaScript and CSS files.
  • Specify a TTL value of 0 seconds to disable caching for dynamic files, such as PHP, JSP, and ASP files.
Causes:
  • No cache policy is configured in Alibaba Cloud CDN, and all requests are redirected to the origin server.
  • The TTL value set in Alibaba Cloud CDN is smaller than required. Cached resources frequently expire, which reduces the cache hit ratios.

Use scenarios: Static resources are deployed on the origin server but not cached on edge nodes. Resources cached on edge nodes frequently expire.

Set a TTL value for cached resources
Accelerate content delivery Causes: If request URLs contain queryString or other variables, the URLs are considered different even if they want to access the same resource. In this case, the requests are redirected to the origin server. This reduces the cache hit ratio.

Use scenarios: Redirect URLs that carry different query strings to the same resource.

Accelerate the delivery of specified resources 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 expected.

Use scenarios: Downloads of installation packages and video streaming.

Object chunking

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 log data.

A request may be in one of the following states:
  • HIT: indicates a cache hit.
  • MISS: indicates a cache miss.
Note The cache hit status indicates the cache hit status only of L1 edge nodes. For example, if the requested resource is not found in the cache of L1 edge nodes but is found in the cache of L2 edge nodes, the cache hit status is still displayed as MISS.
Sample log entry:
26/Jun/2019:10:38:19 +0800] 192.168.53.146 - 1542 "-" "GET http://www.aliyun.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.