All Products
Search
Document Center

CDN:Increase the cache hit ratios of Alibaba Cloud CDN

Last Updated:Jan 17, 2024

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.

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

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 byte 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, 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 monitoring
      Compared 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.质量监控
  • Method 2: Use the Alibaba Cloud CDN API
    • API operations of resource monitoring
      OperationDescription
      DescribeDomainHitRateDataQueries the byte hit ratios of one or more accelerated domain names. You can query data that is collected in the last 90 days.
      DescribeDomainReqHitRateDataQueries 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
      OperationDescription
      DescribeDomainRealTimeByteHitRateDataQueries 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.
      DescribeDomainRealTimeReqHitRateDataQueries 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.

Increase the cache hit ratios of Alibaba Cloud CDN

The following table describes the causes of low cache hit ratios and the solutions.
SolutionCause and use scenarioReferences
Prefetch resources during off-peak hoursCauses: 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:
  • Provide support for major events

    If you want to hold a major event, you can prefetch the static resources of the event page to POPs. After the event starts, visitors can access the static resources that are already cached on POPs. This accelerates content delivery.

  • Release installation packages

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

Manually refresh resources
Specify an appropriate 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 smaller than the required value, and cached resources frequently expire. This reduces the cache hit ratio.

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 URLsCauses: 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 serverCauses: 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 ratiosAlibaba 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.

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 is only of L1 POPs. For example, if the requested resource does not exist in the cache of L1 POPs, but exists in the cache of L2 POPs, 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.