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.

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

The cache hit ratios of Alibaba Cloud CDN are classified into byte hit ratios and request hit ratios.
  • 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

You can view cache hit ratios by using one of the following methods:
  • Method 1: Use the Alibaba Cloud CDN console
    The Alibaba Cloud CDN console displays cache hit ratios in the following manners:
    • 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 approximately 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 approximately 3 minutes. For more information, see Real-time monitoring. Quality 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.

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 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.
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 the edge nodes. After the event starts, visitors can access the static resources, which are already cached on the 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 the edge nodes. After the product is launched, visitors can download the package from the 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
Specify a proper time-to-live (TTL) value for cached resources
  • Specify a TTL of one month or longer for static files that are infrequently updated, such as images and application packages.
  • Specify a TTL based on your business requirements for static files that are frequently updated, such as JavaScript and CSS files.
  • Specify a TTL 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 that is specified in Alibaba Cloud CDN is less than the required value. Cached resources frequently expire. This reduces the cache hit ratios.

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.

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

Object chunking
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. To configure one of the policies, submit a ticket.

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.

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 does not exist in the cache of L1 edge nodes but exists 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://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.