DNS Resolving domain names

What is the DNS

When we visit a website, we enter a domain name. On the real network, hosts communicate with each other through IP addresses. The FUNCTION of the DNS server is to resolve the domain name string into the corresponding IP address

Which DNS servers are available

If every input of a domain name needs to go to a DNS server resolution, the world is so high traffic, it is certainly unable to bear, so the DNS server will be tiered, different types of DNS servers are responsible for resolving different domain names

  • Local DNS cache: The PC caches resolved domain names and IP addresses to the local PC, allowing Windows to passipconfig /displaydnsTo view
  • Local DNS Server
    • If the computer has set up its OWN DNS then the local DNS server is going to be at this address
    • If the DNS server is automatically assigned according to router DHCP, the local DNS server is the DNS address of the router
    • The router sends the request to the DNS of the upper isp
  • Root DNS: The root server is used to manage the home directory of the Internet. It contains the IP address of the top-level DNS server
    • Com Indicates the IP address of the top-level domain server
    • Cn Indicates the IP address of the top-level domain server
    • Net TOP-LEVEL domain name server IP address
    • other
  • Top-level domain name server: the IP address of the server in which the authoritative domain name is contained
  • Authoritative DNS server: returns the destination HOST IP address corresponding to the domain name

DNS Resolution Process

When we enter the www.abc.com domain name

  1. Check whether the IP address corresponding to the domain name exists in the local cache. If yes, return the IP address directly
  2. If the local DNS server does not exist, search for the DNS server. If the local DNS server does exist, return the DNS server
  3. If the local DNS server does not exist, the recursive search starts
  4. First, the root DNS server is searched and.com is accessed. Then it returns the IP address of the local.com DNS server
  5. Then the local server continues to request the.com top-level domain name server. The top-level domain name server finds the DNS server IP address corresponding to www.abc.com and returns it to the client
  6. The local DNS server of www.abc.com resolves the domain name, and the DNS server returns the host IP address

In step 6, the DNS server returns multiple host IP addresses after resolution. In this case, clients can perform simple load balancing through random or polling access

The above process is a process that does not configure a CDN for a domain name

CDN accelerates static resource access

What is the CDN

CDN is an intelligent virtual network built on the basis of the existing network. It relies on the edge servers deployed in various places, through the load balancing, content distribution, scheduling and other functional modules of the central platform, so that users can obtain the required content nearby, reduce network congestion, and improve user access response speed and hit ratio. The key technologies of CDN mainly include content storage and distribution

Memory storage

For example, we have a picture website application deployed in Chengdu. At the beginning, the application was only used to promote local people in Chengdu. Back went out of business development, all parts of the country people are visited, in the xinjiang urumqi users find pictures of loading speed becomes very slow (picture because the data need by cable transmission to urumqi is too far away from chengdu, and there may be a network congestion, etc.) then think of a way, we deployed a cache server in urumqi, As long as subsequent users in Urumqi have accessed a certain image, it will be cached on the server in Urumqi, and subsequent access can be faster

Distributed technology

In urumqi, such as access to cache server without the corresponding image cache, this time can go to visit the northwest data center to get the data, data center of northwest didn’t go to the source data was obtained, so that we can as far as possible to reduce access to source data center to reduce pressure source data center at the same time, speed up the user’s access to experience

  • Edge node: the data access center closest to the user, such as Chengdu
  • Region node: If the corresponding cache is not found in the edge node, you can go to the region node, such as the southwest region
  • Central node: If the region node data is still not hit, it needs to go back to the source (access the source data center node)

After layer by layer data center node data access, the data will be sequentially cached in the corresponding data center node, the subsequent user access can be adjacent access

What can a CDN cache

Web pages, pictures, files and other data that do not change often can be cached in the CDN

How does CDN update data

Search data may not exist, may be expired, how to update the CDN cache

  • Pull mode
  • Push model

If the hotspot data is not in the cache of the nearest CDN, it is pulled up. If the source data is returned, the source data center may be under too much pressure.

In this case, the active push mode can be adopted to actively push hotspot data to edge nodes.

Problems with CDN

  • Anti-theft chain problem
    • The request is accompanied by a refer identifying the source
    • Time stamp to prevent theft
  • Data expiration problem
    • When the server data is updated, static resource access may be inconsistent if the CDN data is not updated
    • Resources are set expiration time, when the expiration time will be pulled back to the source of the latest content
    • Refresh CDN cache actively, force the cache to fail all back to the source to pull the latest data

CDN resolution process

  1. After a CDN is configured, the domain name abc.cdn.com of CNAME is returned instead of the IP address
  2. Parses abc.cdn.com to obtain the corresponding IP address and requests the CDN DNS server. In this case, the global load balancing domain name is returned
  3. After parses abc.cdn.gslb.com to obtain the corresponding IP address, the global load balancer requests the global load balancer to select the most appropriate IP address of the nearest or polymorphic server to the client according to the USER’S IP address, carrier, content carried in the URL, and the load of each CDN server
  4. The client can initiate calls through simple random or polling operations

Establishing an HTTP connection

HTTP uses TCP to transmit data. A TCP connection must be established before data transmission

In HTTP communication, three handshakes were required to establish a connection and four waves were required to disconnect a connection. In HTTP/1.0, each time data was sent, a connection was required to be established and a connection was required to be disconnected after the response was completed. Long connections have been in place since HTTP/1.1, unless one end disconnects actively, which greatly improves communication efficiency.

Load balancing on the server

Generally, servers such as Nginx are used for load balancing. HTTP requests from clients will establish long connections with Nginx and start data transmission to Nginx. Nginx will maintain long connections to different servers and forward data to real back-end servers

Of course, NGINx can also initiate requests in short connection mode, but using long connection can reduce 3 handshakes and 4 waves greatly improve communication efficiency and reduce network congestion

Problems with long connections

The connection will be released when the connection is released. Then, when the connection is released, the server will first send a FIN packet to the client. If the client has not received the FIN packet and initiates an HTTP request, The request then responds to a NoHttpResponseException

Solution:

  • Client retry mechanism (specifying maximum number of retries)
  • Periodically clear idle links in advance, enable scheduled tasks on the client, and disconnect the client from the server before timeout

reference

  • The illustration of HTTP
  • Diagram of TCP/IP protocol
  • Geek time, funny talk about network protocols