This is the 18th day of my participation in the August Challenge

One, foreword

First to understand the CDN: Ali Cloud CDN

Content Delivery Network (CDN) : it is a distributed Network composed of edge node server farms all over the world, which is established and overlaid on the bearer Network. It can share the pressure of the source site, avoid network congestion, accelerate the distribution of website content in different regions and scenarios, and improve the speed of resource access.

CDN vendors, their CDN servers all over the country. For small and medium-sized enterprises, it is impossible to make too many servers around the country, so you can completely push the static pages, JS, CSS and pictures in the second kill activities to the SERVER of CDN manufacturers.

CDNAcceleration principle:

Assume that your accelerated domain name is www.a.com. After you access the CDN and start the accelerated service, when the end user initiates an HTTP request in Beijing, the processing flow is as follows:

  1. When a terminal user sends a request to the specified resource at www.a.com, the terminal user sends a domain name resolution request to the LDNS (local DNS).

  2. LDNS checks whether the IP address of www.a.com is recorded in the cache. If yes, it is returned directly to the end user. If no, consult the authorized DNS.

  3. When the authorized DNS resolves www.a.com, the IP address of domain name CNAME www.a.cdn.com is returned.

  4. The domain name resolution request is sent to the cloud vendor’s DNS scheduling system and the optimal node IP address is assigned to the request.

  5. LDNS Obtains the resolved IP address returned by the DNS.

  6. The user obtained the resolved IP address.

  7. The user initiates an access request to the obtained IP address.

    • If theIPIf the node corresponding to the address has cached the resource, the data is directly returned to the user, as shown in steps 7 and 8. At this point, the request ends.
    • If theIPIf the node corresponding to the address does not cache the resource, the node sends a request for the resource to the source site. After obtaining the resources, cache the resources to a user-defined cache policyCDNNode and return to the user, such as the Beijing node in the figure, at which point the request ends. For details about how to configure a cache policy, see Configuring the Cache Expiration Time.

Summary: Popular CDN, that is, the nearest machine to the user’s location, the user’s APP and page load directly through the CDN.





Second, based onCDNSeckill active static page caching scheme

Seckill active static pages are generally divided into two parts:

  1. The data embeddingHTMLLater staticHTMLpage
  2. HTMLPage referencedjs,cssAnd pictures

These resources can be pushed directly to the CDN.

Popular CDN: the nearest machine to the user’s location, the user’s APP and page load directly through the CDN.

Here’s an example:

  • Seconds kill active pagenginxThere are three, so if there are a million users visiting the active page at the same time, then a million requests will be sent to this pagenginxOn the server.
  • At this point, we bought a cloud vendorCDNService, suppose there are 100 servers.
  • A million users and each of them is going to be looking for something close to themCDNServer, then eachCDNThe server only accepted 10,000 requests in a certain time frame.

So the benefits of this are:

  1. Using the ones scattered all over the countryCDNServers can easily withstand high concurrency requests by dispersing the pressure on our own servers
  2. If the company’s computer room is in Beijing, requests from users in Yunnan, Guizhou or other remote areas are sent to the computer room in Beijing, and the speed will be slow.

However, if the active pages of Secakill are scattered in various provinces, that is, there are some CDN servers in Yunnan, Guizhou or other remote provinces. After the page is pushed, users in various places will directly access the CDN server nearest to them. This will load much faster.

Source back operation: That is, resources in the CDN become invalid and you need to pull the latest resources from the original server.

HTML, JS, CSS, and images can all be placed on nginx, and if the source comes in, it will simply pull the local read back.

CDNInvalidation and hit problems in static data caching schemes

If you change the page by accident, you need to letCDNFast invalidation cache, and then push the page back:

  1. You can configure cache policies, such as expiration time.
  2. The source server must also store a copy of the data

As for the hit problem, you have to choose which ones to pushCDNNodes:

  1. If it is too scattered, then the cost is very high, and the failure of the cost is very high, but also may lead to a very low hit rate, so it is best to push to the distance from their users the largest area, and ensureCDNNetwork well with the company’s servers.

There are 1000 CDN servers with our page cache. At this time, a large part of CDN servers may not be visited by too many people, but a small part of CDN servers may bear more pressure because they are close to most of your users.

  1. And it’s cachedCDNOn the second level cache server, the cache server has a large capacity, centralized, cache hit ratio will be relatively high, and the number is not large, cache invalidation speed is fast

The number of CDN servers is not too much, try to choose in the distance from most of your users relatively close to the place; If you want to invalidate the cache, and there are not many CDN servers, the invalidation will be faster and cheaper; But the distance from the user is relatively concentrated, the overall cache hit ratio is also high