The full name of CDN is Content Delivery Network. CDN is aptly called “network accelerator” because it is a network overlay optimized to speed up network access.
CDN can accelerate the speed and stability of users’ access to network resources and reduce the access pressure of source servers.
I. Introduction to CDN
Main idea: Avoid the bottlenecks and links on the Internet that may affect the speed and stability of data transmission as far as possible, so that the content transmission is faster and more stable.
Method: through the server placed throughout the network node of a layer of intelligence on the basis of the existing Internet virtual network, CDN system can in real time according to the network traffic and each node connection and load condition and to the user’s distance and comprehensive information such as response time will the user’s request to guide users closest service node, accelerate the access speed.
Objective: Users can get the content nearby, solve the situation of Internet network congestion, improve the response speed of users to visit the website.
Advantage:
- CDN node solves the problem of cross-operator and cross-region access, and the access delay is greatly reduced.
- Most of the requests are completed at the edge of the CDN, which plays a shunt role and reduces the load of the source station.
Ii. CDN basic working process
The first is the process without using CDN:
- The user enters the domain name of the web site to visit in his browser.
- The browser requests the local DNS server to resolve the domain name.
- If the resolution result of the domain name is cached on the local DNS server, the local DNS server responds to the resolution request directly.
- If the local DNS server does not cache the resolution result of the domain name, it sends a recursive resolution request to the entire DNS system and sends the resolution result to the browser.
- The browser obtains the domain name resolution result, which is the IP address of the service device corresponding to the domain name.
- The browser requests content from the server.
- The server sends the user’s request to the browser.
When the CDN is used, the DNS server translates the domain name into the CACHE server IP address of the corresponding node based on the user IP address, enabling the nearest access. Web sites using CDN services can achieve content acceleration by simply giving their domain name resolution rights to the CDN’s global load balancer (GSLB) device and injecting the content to be distributed into the CDN.
- When the user clicks on the content URL on the website page, the pastlocalThe DNS system resolves the domain name
CNAME
Indicates the CDN dedicated DNS server. - CDN DNS server will CDNGlobal load balancer
IP
The address returns to the user. - A user sends a content URL access request to the global load balancing device of the CDN.
- CDN The global LOAD balancing device selects a regional load balancing device of the region to which the user belongs based on the USER IP address and URL of the requested content and sends requests to the device.
- The LAN load balancer returns the IP address of a cache server to the global load balancer based on the following factors:
- Determine which server is closest to the user based on the user IP address.
- According to the content name carried in the URL requested by the user, determine which server has the content required by the user;
- Query the current load of each server and determine which server has service capability.
- The global load balancer returns the IP address of the server to the user.
- The user sends a request to the cache server. The cache server responds to the request and sends the content required by the user to the user terminal. If the cache server does not have the content the user wants, and the zone balancer still allocates it to the user, the server requests the content from its upper-level cache server until the source server that traces it back to the web site pulls it locally.
Iii. The role of CDN
The most common feature of a CDN is, of course, acceleration, but there are others.
1. Speed up access
CDN can enable users to obtain the content they need nearby, reduce network congestion, and improve user access response speed and hit ratio.
It also provides server-side acceleration to solve the server overload problem caused by the large number of user visits.
2. Achieve cross-carrier and cross-regional coverage of the entire network
The lack of connectivity, regional ISP geographical limitations, limited egress bandwidth and other factors all cause regional websites to be inaccessible.
CDN acceleration can cover global lines. Through cooperation with operators, IDC resources can be deployed, and CDN edge distribution storage nodes can be rationally deployed in backbone node vendors across the country, so as to make full use of bandwidth resources and balance source traffic.
3. Keep your site secure
CDN load balancing and distributed storage technology, can strengthen the reliability of the website, quite virtually to your website added a protective umbrella, to deal with the vast majority of Internet attacks. Anti-attack systems can also prevent malicious attacks on websites.
4. Remote backup
In the event of an unexpected failure of a server, the system will call on other nearby healthy server nodes to provide close to 100% reliability, which will keep your site from going down.
5. Cost savings
Can overcome the problem of uneven distribution of the website, put into use CDN acceleration can achieve the national laying of the website, you do not have to consider the purchase of servers and subsequent hosting operation and maintenance, between the server image synchronization, also do not need to manage maintenance technicians and trouble, and can reduce the cost of website construction and maintenance.
6. It allows you to focus on the business itself
CDN acceleration vendors generally provide one-stop services, not only limited to CDN, but also supporting cloud storage, big data services, video cloud services, etc., and generally provide 7×24 operation and maintenance monitoring support to ensure that the network is unblocked at any time. You can rest assured to use it. And put more energy into developing its core business.
4. CDN working principle
The basic principle of CDN is widely used in a variety of the cache, the cache server distribution to the user to access relatively concentrated area or in the network, when users visit the web site, using the global load technology to the user’s access point to the nearest work cache server, directly by the cache server response to user requests.
1. User access to CDN resources
- The user enters the domain name www.web.com to the browser. If the browser finds that there is no DNS cache in the local domain for the first time, the browser sends a request to the DNS server of the website.
- The DNS domain name resolver of the site is set to CNAME, pointing to www.web.51cdn.com, and the request is directed to the intelligent DNS load balancing system in the CDN network.
- The intelligent DNS load balancing system parses domain names and returns the IP nodes (CDN servers) with the fastest responses to users.
- The user sends a request to the IP node (CDN server).
- Since it is the first visit, the CDN server will request the original Web site and cache the content;
- Send the request result to the user.
2. Main features of CDN
- Local Cache acceleration improves the speed and stability of enterprise sites, especially those with lots of images and static pages
- The mirroring service eliminates the bottleneck caused by the interconnection between different carriers, accelerates the network across carriers, and ensures good access quality for users on different networks.
- Remote acceleration Remote access Users automatically select the Cache server based on the DNS load balancing technology and select the fastest Cache server to speed up remote access
- Bandwidth optimization The remote Mirror cache server is automatically generated for the server. When remote users access the cache server, data is read from the cache server. This reduces the bandwidth for remote access, shares network traffic, and lightens the load on the WEB server of the original site.
- Cluster anti-attack Widely distributed CDN nodes and intelligent redundancy mechanism between nodes can effectively prevent hacker intrusion and reduce the impact of various D.D.O.S attacks on websites, while ensuring better service quality.
5. Optimization of CDN network:
- Solve the “first kilometer” problem on the server side
- It mitigates or even eliminates bottlenecks between different operators
- Reduce the pressure on the export bandwidth of the provinces
- Relieves the pressure on the backbone
- Optimized the distribution of hot online content
The first kilometre is the first outlet for web traffic to the user and is the bandwidth available from the link that connects the web server to the Internet. This bandwidth determines how fast and concurrently a website can be accessed by its users. If the business is busy, the more users visit the site, the more congestion, and the site will lose users when they are most needed.
The middle kilometer represents the transmission network between nodes in the Internet.
Last kilometre The last access link in which World Wide Web traffic is transmitted to the user.
Vi. Application scenarios of CDN
1. Site/application acceleration
Dynamic files can be combined with cloud server ECS. Static resources, such as various types of images, HTML, CSS, AND JS files, can be combined with object storage OSS to store massive static resources, which can effectively speed up content loading. Easily distribute pictures, short videos and other content on the website
2. Video and audio on demand/large file download distribution acceleration
Support various file download, distribute, support online on demand to accelerate business, such as mp4, FLV video file or a single file size over 20 m on average, the main business scenario is the audio on demand, large file download (such as the installation package download), recommend object storage OSS use collocation, can speed back to the source, saving nearly two-thirds back to the source bandwidth costs.
3. Acceleration of live video (in internal test)
Video streaming service supports integrated solutions for media asset storage, slice transcoding, access authentication, and content distribution. Combined with elastic scaling service, adjust server bandwidth in time to cope with unexpected access traffic; Combined with the media transcoding service, it can enjoy high-speed and stable parallel transcoding, and the task scale can be expanded seamlessly. At present, CDN Live Accelerated service has been tested and optimized for internal users, and will be online soon
Mobile app acceleration
Mobile APP update file (APK file) distribution, mobile APP images, pages, short videos, UGC and other content optimization to accelerate distribution. Provides the httpDNS service to avoid DNS hijacking and obtain real-time and accurate DNS resolution results, shortening user access time and improving user experience.
7. CDN cache
Caching is the idea of space for time, using extra space in exchange for faster access.
- CDN cache is not used
All users access the source server directly
- CDN cache is used
The client browser first checks whether the local cache is expired. If so, it sends a request to the CDN edge node, which detects whether the cache of user requested data is expired. If the CDN data is not expired, it directly responds to the user’s request. If the CDN data is out of date, the CDN also needs to make a back to source request to the source station to pull the latest data.
Advantages of cache: the shunt function of CDN not only reduces the access delay of users, but also reduces the load of the source station.
Disadvantages: When the website is updated, if the data on the CDN node is not updated in time, even if the user invalidate the cache on the browser side by Ctrl+F5, the user’s access will be abnormal because the CDN edge node does not synchronize the latest data.
Solution to CDN cache update
- Resource URL parameter with timestamp
The parameters of the URL plus the timestamp, each time the timestamp is updated, so that the CDN edge node to synchronize the latest data from the source server.
http://www.cdn.com/static/images/test.png # no timestamp
http://www.cdn.com/static/images/test.png?_t=202012290910 # timestamped
Copy the code
- Call the refresh cache interface provided by the CDN service provider
CDN edge node is transparent to developers. Compared with the browser’s forced refresh of Ctrl+F5 to inactivate the browser’s local cache, developers can clear CDN edge node cache through the “refresh cache” interface provided by CDN service providers.
In this way, after updating data, developers can use the “refresh cache” function to force the expiration of the data cache on the CDN node to ensure that the client can pull the latest data when accessing.
Vii. Composition of CDN
1. Deployment architecture
The primary goal of CDN system design is to minimize the access response time of users. In order to achieve this goal, CDN system should try to store the contents needed by users in the nearest location. In other words, the Cache devices that provide content services to users should be deployed at the physical edge of the network, which is called the CDN edge layer. The devices responsible for global management and control in the CDN system constitute the central layer, which also stores the most content copies. If the devices at the edge layer are not matched, they request the central layer. If the devices at the central layer are still not matched, the central layer needs to report back to the source station.
There are differences among different CDN system designs. The central layer may have user service capability, or may not directly provide services but only provide content to lower-level nodes. If the SCALE of CDN is large, the devices at the edge layer will directly request content or service from the center layer, which will cause excessive pressure on the devices at the center layer. Therefore, it is necessary to consider deploying a regional layer between the edge layer and the center layer to manage and control a region and also save part of the content copy for the access of the edge layer.
Figure is a typical three-level deployment diagram of CDN system:
2. Device composition
Functional entities contained in CDN network are mainly composed of the following parts:
- Content caching device
- Content switch
- Content router
- CDN Content Management System
1. Content caching device
Content cache is a CDN node located at the user access point. It is a content provision device for end users. It can cache static Web content and streaming media content and realize the edge propagation and storage of content for users to access nearby.
2. Content switch
Content switch is located in the centralized user access point, and can balance the load of multiple content cache devices in a single point, and carry out content cache load balance and access control.
3. Content router
The content router is responsible for scheduling user requests to the appropriate device.
Content routing is usually implemented by load balancing system, which dynamically balances the load distribution of each content cache site, selects the best site for users’ request, and improves the availability of the site.
Content routers can route based on a variety of factors, including site proximity to users, content availability, network load, equipment conditions, and so on.
Load balancing system is the core of the whole CDN. The accuracy and efficiency of load balancing directly determine the efficiency and performance of the whole CDN.
Content management system
The content management system is responsible for the management of the whole CDN. It is an optional component, and its role is to carry out content management, such as content injection and release, content distribution, content audit, content service, etc.
reference
- Basic introduction of CDN concept – All-round program ape – simple book
- Brief introduction of CDN principle – Qige – Zhihu
- CDN – Baidu Encyclopedia
- Perhaps the most complete explanation of CDN in history – Zhihu, chief customer service provider of Vision Cloud
- CDN,