Principle of live video broadcast-CDN

introduce

  • The full name of CDN is Content Delivery Network , which is content distribution network . Its purpose is to add a new layer of network architecture to the existing Internet to publish the content of the website to the edge of the network closest to the user, so that the user can obtain the required content nearby and improve the response speed of the user's access to the website. CDN is different from mirroring because it is smarter than mirroring, or we can use this metaphor: CDN = smarter mirroring + caching + traffic diversion. Therefore, CDN can significantly improve the efficiency of information flow in the Internet network. Technically, we will comprehensively solve the problems caused by small network bandwidth, large user visits, and uneven distribution of outlets, and improve the response speed of users' access to the website.

Prepare

  • To better understand CDN, let’s take a look at the CDN workflow. When a user visits a website that has joined the CDN service, DNS redirection technology is first used to determine the best CDN node closest to the user, and the user's request is directed to that node. When the user's request reaches the designated node, the CDN's server (the cache on the node) is responsible for providing the content requested by the user to the user. The specific process is: The user enters the domain name of the website he wants to visit in his browser, and the browser requests the local DNS to resolve the domain name. The local DNS sends the request to the website's primary DNS, and the primary DNS is determined according to a series of policies. The most appropriate CDN node at that time, and the parsed result (IP address) is sent to the user, and the user requests the content of the corresponding website from the given CDN node.

  • Since there is a performance bottleneck when users access the origin site business, CDN technology is used to cache the content of the origin site to multiple nodes. When a user initiates a request to the origin domain name, the request will be dispatched to the service node closest to the user, and the service node will respond directly and quickly, effectively reducing user access latency and improving availability.

know

1. Advantages

  • The advantages of CDN are obvious:
    (1) CDN nodes solve the problem of cross-operator and cross-regional access, and the access delay is greatly reduced; (
    2) Most requests are completed at CDN edge nodes, and CDN plays a diversion role, alleviating the source of traffic. station load.

2. CDN related technologies

The implementation of CDN relies on the support of a variety of network technologies, of which load balancing technology, dynamic content distribution and replication technology, and caching technology are the main ones. Let's take a brief look at these technologies.

2.1 Load balancing technology

Load balancing technology is not only used in CDN, but also has been widely used in many areas of the network, such as server load balancing and network traffic load balancing. As the name suggests, load balancing in the network is to distribute network traffic as evenly as possible to several servers or network nodes that can complete the same tasks, thereby avoiding overloading of some network nodes. This can not only increase network traffic, but also improve the overall performance of the network. In CDN, load balancing is divided into server load balancing and overall server load balancing (some are also called server global load balancing). Server load balancing refers to the ability to allocate tasks between servers with different performance, which not only ensures that servers with poor performance do not become the bottleneck of the system, but also ensures that the resources of servers with high performance are fully utilized. Global server load balancing allows web hosts, portals and enterprises to distribute content and services based on geographic location. Increase fault tolerance and availability by using multi-site content and services to protect against failures caused by local or regional network outages, power outages, or natural disasters. In the CDN solution, the overall server load balancing will play an important role, and its performance will directly affect the performance of the entire CDN.

2.2 Dynamic content distribution and replication technology

As we all know, the response speed of website access depends on many factors, such as whether there is a bottleneck in the network bandwidth, whether there are congestion and delays in the route during transmission, the processing power of the website server and the access distance, etc. In most cases, website response speed is closely related to the distance between visitors and the website server. If the distance between the visitor and the website is too far, the communication between them will also need to go through multiple routing, forwarding and processing, and network delays will be inevitable. An effective method is to use content distribution and replication technology to distribute and replicate most of the static web pages, images and streaming media data that account for the main body of the website to acceleration nodes in various locations. Therefore, dynamic content distribution and replication technology is also a major technology required by CDN.

2.3 Caching technology

Caching technology is no longer a new technology. Web caching services improve user response times in several ways, such as proxy caching services, transparent proxy caching services, transparent proxy caching services using redirection services, etc. Through the web caching service, WAN traffic can be minimized when users access web pages. For corporate intranet users, this means caching content locally rather than having to traverse a dedicated WAN to retrieve web pages. For Internet users, this means storing content in their ISP's cache without having to retrieve the web page over the Internet. This will undoubtedly improve the user's access speed. The core function of CDN is to improve the access speed of the network. Therefore, caching technology will be another major technology used by CDN.

3. CDN acceleration example

  • Assume that the domain name of your business origin site is www.test.com. When the domain name is connected to the CDN and the acceleration service is started, your user initiates an HTTP request. The actual processing flow is as shown in the figure:
    Insert image description here

    • When a user initiates a request for a picture resource under www.test.com, such as 1.jpg, he must first initiate a domain name resolution request to Local DNS;

    • When Local DNS resolves www.test.com, it will be found that the CNAME www.test.com.cdn.dnsv1.com has been configured, and the resolution request will be sent to Tencent DNS (GSLB). GSLB is a scheduling system independently developed by Tencent Cloud. The best node IP will be assigned to the request;

    • Local DNS obtains the resolution IP returned by Tencent DNS;

    • User test obtains the analytical IP;

    • The user initiates an access request to resource 1.jpg to the obtained IP;

    • If the node cache corresponding to the IP has 1.jpg, the data will be returned directly to the user (10), and the request ends. If the node does not cache 1.jpg, the node will initiate a request for 1.jpg to the business origin site (6, 7, 8). After obtaining the resource, it will store the resource in combination with the user-defined cache strategy (9) , and returned to the user (10), at which point the request ends.
      Insert image description here

    • With these two levels of cache (browser, CDN), it naturally involves cache update issues.

3.1 Browser cache refresh

  • Enter the URL in the address bar and press Enter or click the Go button
    . The browser obtains the data of the web page with the least number of requests. The browser will directly use the local cache for all content that has not expired, thus reducing requests to the browser. Therefore, Expires and max-age tags are only valid for this method.

  • Press F5 or the browser refresh button.
    The browser will attach the necessary cache negotiation to the request, but the browser is not allowed to use the local cache directly. It can make Last-Modified and ETag effective, but it is invalid for Expires.

  • Press Ctrl+F5 or press Ctrl and click the refresh button.
    This method is to force a refresh, which will always initiate a new request without using any cache.

3.2 CDN cache

  • After the browser's local cache expires, the browser will initiate a request to the CDN edge node. Similar to browser caching, CDN edge nodes also have a caching mechanism.

  • The offloading effect of CDN not only reduces user access delays, but also reduces the load on the origin site. But its shortcomings are also obvious: when the website is updated, if the data on the CDN node is not updated in time, even if the user uses Ctrl + F5 in the browser to invalidate the browser cache, the CDN edge node will not synchronize the latest data. Causes user access exceptions.

3.3 CDN caching strategy

  • CDN edge node caching strategies vary from service provider to service provider, but they generally follow the http standard protocol and set the CDN edge node data caching time through the Cache-control: max-age field in the http response header.

  • When the client requests data from the CDN node, the CDN node will determine whether the cached data has expired. If the cached data has not expired, the cached data will be returned directly to the client; otherwise, the CDN node will issue a return-to-origin request to the origin site. Pull the latest data from the origin site, update the local cache, and return the latest data to the client.

  • CDN service providers generally provide multiple dimensions based on file suffix and directory to specify the CDN cache time to provide users with more refined cache management.

  • CDN cache time will have a direct impact on the "return to origin rate". If the CDN cache time is short, the data on the CDN edge node will often fail, resulting in frequent returns to the origin, increasing the load on the origin site, and also increasing the access delay; if the CDN cache time is too long, data updates will occur. The problem of slow time. Developers need to add specific businesses to perform specific data cache time management.

3.4 CDN cache refresh

CDN edge nodes are transparent to developers. Compared with the forced refresh of the browser Ctrl+F5 to invalidate the browser's local cache, developers can clear the CDN edge node cache through the "refresh cache" interface provided by the CDN service provider. the goal of. In this way, developers can use the "refresh cache" function to force the data cache on the CDN node to expire after updating the data, ensuring that the client can pull the latest data when accessing.

Summarize

  • CDN = smarter mirroring + caching + traffic diversion

  • Device detection, signaling exchange, (image processing, encoding, streaming,CDN, streaming, decoding, image processing)

  • This CDN article is collected from the Internet, shared on the Internet, and is only for popular learning and understanding: CDN_Global Encyclopedia

Guess you like

Origin blog.csdn.net/MOON_YZM/article/details/127538670