当前位置:网站首页>"CDN" makes your website more smooth and smooth

"CDN" makes your website more smooth and smooth

2020-12-07 10:43:25 Kites in ancient times

When you are visiting Taobao 、 When Jingdong was ready to chop his hands , Although there are a lot of pictures when you enter the page 、 A lot of content , But it loads quickly , Let you chop your hands as smooth as water . Whoosh, a good-looking picture of the goods came out , Pay in one swish . Of course, pictures are a relatively small resource , What about video sites , There are hundreds of each video M、 several G, At the same time, there are a lot of requests coming , Even if the server can resist , Can the bandwidth keep up ?

Is it relying on the abundant servers behind the big factories 、 Broadband resources and excellent optimization technology ? Yes, of course , This must be a necessary condition , Besides, it depends on what we are going to say today CDN Technology .

What is? CDN

CDN The content distribution network (Content Delivery Network) For short , It is a virtual distributed network based on bearer network , Be able to source site content ( Including all kinds of dynamic and static resources ) Intelligent cache to the global node servers . This is not only convenient for users to access the content nearby , Improve the access speed of resources , Also sharing the pressure of the source station .

CDN(Content Delivery Network) It's a content distribution network , Also known as content delivery network , The concept begins with 1996 year , It is proposed by a research group of Massachusetts Institute of technology to improve the quality of Internet service . In order to be able to IP Publish rich broadband media content on the Internet , They proposed to build a content distribution platform on the basis of the existing Internet to provide services for websites , And in 1999 A special CDN Services , by Yahoo Providing professional services . because CDN It is a network coverage layer optimized to speed up network access , So it's figuratively called “ Network accelerator ”.

CDN The core is to speed up network access , Look at the picture below , End users in different places will access the nearest CDN The server , and CDN The content on the server is on the source server cluster , Whether through active pull or passive reception , In short, the data content is consistent , And it's closest to the user , Get the lowest cost and faster .

Now some powerful companies in China will build their own CDN The Internet , To improve service performance , Of course , The cost is huge too , Think about it , Convenient access to content means setting up content node servers everywhere , Not to mention serving the world , For the whole of China , How many nodes should there be .

Fortunately, many domestic cloud service providers have CDN service , Can greatly reduce self built CDN Cost of .

Use scenarios

from CDN Meaning itself analysis , Content distribution networks , It must be the scene that needs to get the content quickly CDN. These include the following :

  1. Static resource files in the website , Such as the picture 、js Script 、 Small files such as style files ;
  2. A large file , For example, some software download stations 、 Some videos 、 Image resource download station, etc ;
  3. Online audio 、 Video website , For example, Netease cloud music 、 Tencent video, etc ;

For example, I opened the tmall mall and had a look , Many of these static files come from different domain names , There are many domains with CDN word , Obviously it all comes from CDN Node .

It's all static files , Can dynamic content be put into CDN How about it ? That's going to change the flavor ,CDN Only static content can be implemented quickly and easily , If you add dynamic content , It's a multi machine room distributed deployment . It's not that there is no compromise , Edge of computing It's such a strategy , Edge nodes can do both CDN, Also has some computing power , There can be some simple dynamic execution capabilities . This is beyond the scope of discussion .

If you've done front-end development , Maybe I used some JavaScript Development CDN, Such as qiniuyun and youpaiyun, etc .

principle

No, CDN The request path for

In the absence of CDN Under the circumstances , What is the path of a resource request .

1、 First, the user enters the domain name in the browser , For example, go to the homepage of tmall ;

2、 The user's computer queries hosts To see if there is a corresponding IP , If so, ask directly IP;

3、 If it's not cached locally , To the local DNS Initiate request , Local DNS Search for the domain name IP( It's usually A Record );

4、 If the local DNS Can't find , To the superior DNS Server request , One level, one level, one level, the top level DNS The server ;

5、 Corresponding to the domain name found IP Initiate request ;

6、 The cluster where the resource is located returns the requested resource to the client , Such as the picture 、 The style file 、 Video files, etc ;

With CDN after

When there's a CDN After access , Things get a little more complicated .

1、 The user enters the domain name in the browser , For example, go to the homepage of tmall ;

2、 The user's computer is local DNS Server request , Search for domain name IP Address ; 3、 Local DNS If there is a record of this domain name in the server , Then it directly responds to the user's parsing request , Otherwise, local DNS Towards the root DNS Query domain name authorization server ; 4、 root DNS Authorize the domain name DNS Record back to local DNS; 5、 Local DNS Authorized by domain name DNS After recording , Continue to authorize the domain name DNS Search for domain name IP Address ; 6、 Domain name Authorization DNS After querying the domain name record ( It's usually CNAME), Return to local DNS; 7、 Local DNS After getting the domain name record , To intelligence DNS Search for domain name IP Address ; 8、 intelligence DNS According to certain algorithms and Strategies ( For example, static topology , Capacity, etc ), Will be the most suitable CDN node IP Address returned to Local DNS; 9、 Local DNS Will get the domain name IP Address , Return to user terminal ; 10、 The user gets the domain name IP After the address , Access to the site server ; 11、CDN The node server answers the request , Return content to client ,CDN The server saves locally at the same time , For next use .

The following flow chart shows the whole request process .

The general process is what it looks like , In the real world , intelligence DNS It may be more complicated . Because of the... Of a region CDN It's probably not just a machine or a cluster , It's a small, distributed deployment .

For example, it's a big one all over the country CDN The Internet , That intelligence DNS It's actually an intelligent load balancer , It will be based on a series of indicators , For example, geographical location 、 Line, etc. return a IP Address , This address may not be a CDN Server's IP, It's a small range of smart load balancer addresses , This load balancer may coordinate a certain province of CDN node , When directed to this load balancer , According to a series of indicators , Will return the most appropriate CDN Node IP To the client .

CDN Core components

intelligence DNS

Intelligent scheduling DNS yes CDN Key systems in service , When users access join CDN When serving the website , Domain name resolution requests will eventually be made by “ Intelligent scheduling DNS” Responsible for handling . It uses a set of pre-defined strategies , Provide the node address closest to the user at that time to the user , So that users can get fast service . At the same time, it needs to be connected with CDN Nodes keep communicating , Track the health status of each node 、 Capacity and other information , Make sure that the user's request is allocated to the nearest available node .

Cache function service

Load Balancer

CDN Nodes usually exist in the form of clusters or regional clusters , The load balancer can dispatch requests to the most appropriate CDN Server . The load balancer may be hardware F5, It could be LVS、HA、Nginx In the form of software .

Content cache server

CND What's provided is content acceleration , Of course, there has to be a place to store the content . If it's a small static file, it's OK , If it's a big video file, etc , There are certain requirements for large capacity storage and high-speed reading .

Content management services

The initial content is stored in the source server , Then we have to find a way to store the content in different places CDN Node . In what way , The easiest way to do this is when the client accesses some of the CDN after , Found that there was no content needed , Go to the source server and pull it .

There are two modes of content transfer , A push mode , A pull mode . Push mode is the source server like each CDN Nodes actively push , This way is more flexible , But the implementation is more complex , Suppose you have an administrative console , The administrator selects some files that need to be pushed , Then choose the one you want to push CDN node , Click the push button , Push the file forward actively .

indicators

General indicators

To measure CDN There are several indicators of service performance :

  • Time delay : A packet sent from a user's computer to a web server , And then immediately from the web server back to the user's computer round-trip time . The lower the delay , The better the performance .
  • Download speed : Refers to the transmission speed of data downloaded from the network or network server . The faster you download , The better the performance .
  • Opening speed : Refers to the speed at which users can open a website . The faster it opens , The better the performance .
  • Packet loss rate : It refers to the ratio of the number of packets lost in the network transmission to the sent data group .
  • Return to source rate : The back to source ratio is divided into two types: the proportion of back to source requests and the proportion of back to source traffic .
    • The number of back to source requests is more than : The edge node has no cache for 、 Cache expiration ( Caching ) And uncacheable requests as a percentage of total request records . The lower the performance, the better .
    • Back to source flow ratio : Back to source traffic is the traffic generated by the size of the back to source request file and the traffic generated by the request itself . So the back to source flow ratio is = Back to source traffic /( Back to source traffic + The traffic that the user requests to access ), The lower the ratio , The better the performance .
  • cache hit rate : When an end user accesses an accelerator node , The proportion of the number of times that the node has cached the data to be accessed to the total number of accesses . The higher the cache hit rate , The better the performance .

benefits

1、 Local Cache Speed up , Improved enterprise site ( Especially contains a lot of pictures and static page site ) Access speed of , And greatly improve the stability of the above nature site ; 2、 Image services eliminate the impact of the bottleneck of interconnection between different operators , Realize the network acceleration across carriers , Ensure that users in different networks can get good access quality ; 3、 Remote access users according to DNS Load balancing technology , Intelligent automatic selection Cache The server , Choose the fastest Cache The server , Speed up remote access ; 4、 Bandwidth optimization : Automatically generate remote server Mirror( Mirror image )cache The server , Remote user access from cache Read data on the server , Reduce the bandwidth of remote access 、 Share network traffic 、 Reduce the original site WEB Server load and other functions ; 5、 Cluster anti attack : Widely distributed CDN Node plus intelligent redundancy mechanism between nodes , Can effectively prevent hacking and reduce all kinds of DDos The impact of the attack on the site , At the same time to ensure a better quality of service .

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

版权声明
本文为[Kites in ancient times]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012071039223937.html