Writing in the front
This article is an interview question, and not just an interview question
What happens from entering the URL to rendering the page? Such as browser enter the browser after www.qq.com is how to put the final page rendering, this is a classic interview question, whether large companies or small companies or even the front or back end the interview percentage is very high, because involves the knowledge points and that place is more, can be found and there almost every step can be optimized
Since we brush this post, I hope you take some time to finish patiently, will not let you down, this article from the network five layer model in detail analysis and browser page rendering mechanism and other aspects to understand the URL from input to page rendering the whole process, the content is still very full
Write to write to discover a bit long, divided into three 😄
The first two articles is to help you understand the whole process, so there is no direct answer, but give you comb explain some trivial knowledge, the purpose is not the answer, but completely understand the process here, you as long as the earnest see last can proud to answer this question, give yourself a answer in my heart, Look at the last answer that I summarized through these knowledge (if your summary is more substantial/detailed, please share it in the comments section, and we will check the gaps together), first read, then think, then summarize and discuss with each other, the best effect
URL from input to page rendering this whole process can be divided into two aspects of network communication and page rendering, the general back-end program to answer this question focuses on network communication on the line, but the front-end page rendering also have to understand, in short, the more detailed the answer the higher the score
So start, this article we first look at the network communication, maybe the front-end students of the network should not have a strong cognition of the back-end students, in fact, this interview question can highlight their own is also the network, because it involves a lot of knowledge of the principle of network communication, so let’s slowly comb this
The origin of network layering
I don’t know if you know network layering, the network actually has many layers, and there are many protocols between layers, there are all kinds of packets, this stuff is dry, very boring, so many layers is too much trouble, why there are so many layers? Why not just go to the next level?
At first, the communication between computers only needed a wire to complete the communication, but the world is so big, there are so many computers, the distance is too far, and the wire is old and easy to be cut by unscrupulous people
Then came the wireless network, in which gateways and routes also need to be connected, but instead of connecting each computer in pairs, a unit of computers in an area are connected to communicate with each other
Later found out that the computer can only transmit signals, 0/1 of connections between the other computer doesn’t know what so many 0/1 means, like 010101010101111000111011010 you know what meaning is this a string, the computer also don’t know, different manufacturer of computer wired communication also is very troublesome, Define a set of rules that all computers, regardless of brand, must follow. This set of rules is known as the network protocol
Oh, I’m talking about layering networks, not protocols, moving on, continuing with our topic above, the problem is, the problem of computers sending 0/1 signals over wires that set the rules for communication, but there are all kinds of other problems in networks besides meaningless signals like 0/1
- How do two computers recognize each other?
- How can I know the address of the other party?
- How do different computer applications know they are passing data to themselves?
- How to specify the different communication data format and so on a series of problems
If all kinds of problems are written into a set of protocols to define the rules of communication between the two parties, but in case some rules have communication problems, affecting other rules, the most common is the packet, if a packet contains a variety of protocols, ah ah ah
If we layer the network, with each layer doing a specific job and then passing the data to the next layer, the complex problem of communication and network interconnection will not become simpler
Maybe you didn’t get it, but that’s okay. Keep going
TCP/IP five-tier model
If we want layers, how many layers should we divide into?
The current network layer can be divided into four layers of Internet protocol stack and seven layers of Internet protocol stack. In fact, the original network layer is the standard seven layer, which is also known as the OSI seven layer model. The reference model is a standard system developed by the International Organization for Standardization (ISO) for interconnection between computers or communication systems. It is commonly referred to as the OSI reference model or the seven-tier model
For those of you who know a little bit about networking there’s also the TCP/IP four-tier model and the TCP/IP five-tier model, where does that come from?
In fact, the so-called TCP/IP four-layer model and TCP/IP five-layer model are optimized from the OSI seven-layer, combining some layers, essentially the same, OSI seven-layer model is too detailed, has certain reference significance, but the implementation is more cumbersome, compared to TCP/IP model is more concise, It has strong practical application value
Let’s look at a picture of a model.
TCP/IP computer network is divided into four layers, general materials or tutorials are combined with OSI7 layer model and TCP/IP4 layer model, the computer network according to the 5-layer model, 5-layer model is only designed to facilitate the introduction of computer network principles, but in the actual application or TCP/IP four-layer model, I want you to understand that
Here we also use five layers to explain, easier to understand, of course, here can only let you have a specific network hierarchical structure in mind, as an interview answer to understand these enough, and then recommend you to continue to in-depth, you can see the relevant books and materials, this article can also play a role of guidance
PS: As a front-end or back-end, we are software development, so it is ok to focus on the network layer, the physical layer and the data link layer are hardware related, so these two layers will not be described too much, you can understand
The physical layer
The physical layer, as the name suggests, connects devices together by physical means (network cables, optical fibers, wireless) and transmits 0/1 electrical signals (also called bitstreams), just like the physical connections between computers
It is mainly used to transmit 0/1 signals, because 0/1 signals do not have any practical significance, so another layer is used to specify the meaning of different 0/1 combinations
Data link layer
Or the above said, 010101010101111000111011010, like a string of data computer so don’t know what meaning be
The lower physical layer cannot specify the meaning of different 0/1 combinations of signals, so a set of protocols is specified in the data link layer to group 0/1 signals and specify the meaning of different groups, so that both computers can identify this protocol, which is often referred to as the Ethernet protocol
Ethernet protocol
The Ethernet protocol specifies that a group of electrical signals constitute a packet, which is called a frame. Each frame consists of a header and data
Frame sizes typically range from 64 to 1518 bytes and larger data needs to be split into multiple frames
The header consists of 18 bytes. The header contains information about who sent the frame and to whom, so the header is mainly descriptive data such as sender/receiver etc
Data, consisting of 46-1500 bytes, is mainly what the sender wants to send to the receiver
The data of one computer is sent to another computer through the physical layer and the data link layer, how to identify each other and how to know the address of each other? The unique MAC address appears
The MAC address
Each computer into the network, we always have a network card interface, each card will have a unique address, is what is called a MAC address, it is uniquely identifies each computer in the network equipment, is a string of hexadecimal number composed of 48 bytes, each computer when manufacturers to produce identity, So we use MAC addresses to identify each other
Let’s look at another graph.
As shown in the figure above, computer A knows the MAC address of computer B, and then Computer A wants to send data to computer B. Although computer A knows the MAC address of computer B, how can A send data to B?
Computer A is not only connected to computer B, but computer A is also connected to computers C and D. Although Computer A knows the MAC address of computer B, it doesn’t know where B is going. So to solve this problem, the concept of broadcast was developed
radio
In the same subnetwork, often referred to as a LAN, computers communicate by broadcast, that is, sending packets to all computers in the same subnet. Other computers decide whether to receive the packets based on the MAC address of the recipient
Generally speaking, A will simultaneously send A packet to B/C/D, which contains the MAC address information of the receiver. When B/C/D receives A packet, it compares the MAC address in the packet with its own MAC address. If they are the same, the packet will be received; otherwise, the packet will be discarded (packet loss). This is what we call broadcasting
It’s like, you and your girlfriend get separated in the crowd, you shout her name, the person who hears her will match themselves, is their own will ignore, not their own as you are a fool ignore you
So now that we know what computers are labeled and how to communicate with each other, we still have a problem: how do we know each other’s MAC addresses? This led to the ARP protocol, through the ARP protocol to know the MAC address of the other party, this protocol is a protocol of the network layer, so we temporarily shelved, first continue to see
The network layer
Look at the role of the physical layer and data link layer, you may feel as if normal communication can be completed, so what is the network layer to do?
Actually, our network is composed of numerous sub network (LAN), radio, and only A computer in the same subnet can receive, if there is no such thing as A subnet of A computer to send A packet to A computer by means of radio B, then all the computers in the world can receive the packet, and then compared the abandoned, The result of so many computers can be imagined, so the subnet is also produced
So again, how do we tell if Mac addresses belong to the same subnet? If it is the same subnet, we send the data to each other in the form of broadcast. If it is not the same subnet, we send the data to the gateway for forwarding
How do you tell if two computers are on the same subnet, that’s what the network layer does, and to solve this problem, you have the concept of IP protocol, right
TCP/IP protocol
There are two versions of THE IP protocol, ipv4 / ipv6. The most popular version is ipv4. This address consists of a 32-bit binary number, which is generally divided into four decimal segments. It’s common for addresses to range from 0.0.0.0 to 255.255.255.255
Each computer that wants to connect to the Internet has an IP address that is divided into two parts. The front part represents the network and the back part represents the host, but the number of binary digits occupied by the network part and the host part is not fixed
If the network parts of two computers are identical, we say they belong to the same subnet (LAN). For example, 192.168.17.1 and 192.168.17.2, if the network parts of these two IP addresses are 24 bits and the host parts are 8 bits, So their network part is 192.168.17, so we say that the two computers are in the same subnet
The question then arises, given two IP addresses, who knows how many IP addresses are in the network part and how many IP addresses are in the host part?
This brings us to our other keyword subnet mask
Subnet mask
The subnet mask is a 32-bit binary number like the IP address, but the network part is set to all 1, the host part is set to all 0, that is, if the network part of the above two IP addresses is divided into 24 bits, the host part is 8 bits, then their subnet mask is
11111111.11111111.11111111.00000000, 255.255.255.0
With a subnet mask, how can YOU tell if an IP address is in the same subnet?
Clearly, know the subnet mask, as we know the network part is few, the host part is several, we just need the IP address with a subnet mask do (and) arithmetic, and then to compare their results, if you compare the results of the same, represents the same subnet, otherwise it is not the same subnet
This means that with the IP addresses and subnet masks of two computers, we can determine whether they are in the same subnet
Suppose they are on the same subnet. When computer A wants to send data to computer B, we use ARP to get the MAC address of the computer
ARP protocol
ARP sends a packet to each computer on the same subnet in the form of broadcast. The packet contains the IP address of the receiver. After receiving the packet, the receiver compares the IP address with its own, and sends its MAC address to the receiver. So computer A knows computer B’s MAC address
You may ask, after you know the MAC address, you send data in the form of broadcast, ask the MAC address is also sent in the form of broadcast, so how do other computers know whether you want to transmit data or ask for the MAC address?
In fact, in the packet asking for MAC address, there is a special MAC address in the MAC address of the other party. When other computers see this special MAC address, they know that the broadcast is asking for the MAC address
If the IP addresses of the two computers are not in the same subnet, then we send the packets to the gateway and ask the gateway to forward them for us
Transport layer
Through the coordination of the physical/data link layer and the network layer, we successfully transfer data from Computer A to computer B. However, computer B has various applications in it. How does the computer know which application the data is sent to?
At this time, the port will play, when the computer A transfer to computer B, also have to specify A port, for A specific application to receive processing, as A programmer we are more familiar with the port range: 0 to 65535, among which the first 1023 ports are occupied by the system
In other words, the function of the transport layer is to establish port-to-port communication, while the function of the network layer is to establish host-to-host communication
With IP and port, we can accurately communicate. Some of the IP we input do not specify the port number, but in fact some transport protocols have set some default ports, such as HTTP default 80, HTTPS default 443, and these port information will also be included in the packet
The two most common protocols at the transport layer are TCP and UDP
UDP protocol.
UDP is a connectionless protocol that processes data packets like TCP
A UDP packet consists of a header (8 bytes) and data (with a header less than 65535 bytes). A UDP packet consists of an IP packet. The header consists of sending and receiving ports
UDP does not provide packet grouping, assembly, and sorting. That is, after a packet is sent, it is impossible to know whether the packet arrived safely and intact
UDP Features
-
Connectionless oriented
- When UDP wants to send data, it can send data without connection. It is only a porter of data packets and does not split or splice data packets
- At the sending end, the application layer passes the data to the UDP protocol at the transport layer. UDP simply adds a UDP header to the data to identify the UDP protocol, and then passes the data to the network layer
- At the receiving end, the network layer passes the data to the transport layer, and UDP passes the IP header to the application layer without any concatenation
-
Unicast, multicast, broadcast
- UDP not only supports one-to-one transmission, but also one-to-many, many-to-many, and many-to-one transmission modes. That is, UDP provides unicast, multicast, and broadcast functions
-
For a message
- After the header is added, the UDP packets from the sender are sent to the IP layer
- UDP does not merge or split packets from the application layer, but retains the boundaries of the packets
- Therefore, the application must select a message of the appropriate size
-
Unreliability.
- Unreliability is first reflected in the lack of connection, communication does not need to establish a connection, want to send, such a situation is certainly not reliable
- Send whatever data you receive without backing it up. Send data without caring if the other party has received the data correctly
- The network environment is sometimes good and sometimes bad, but UDP does not have congestion control, will always send data at a constant speed, even if the network conditions are not good, will not adjust the sending rate, the drawback of this implementation is that in the case of poor network conditions may lead to packet loss, but the advantages are also obvious. In some real-time scenarios, such as teleconferencing, UDP is used instead of TCP
-
The header cost is small and the data packet transmission is efficient
- The UDP header contains the following data
- Two hexadecimal port numbers, sending port and receiving port
- The length of the entire data packet
- Checksum of the entire data packet (IPv4 optional field). This field is used to find errors in header information and data
- Therefore, UDP header overhead is small, only 8 bytes, compared to TCP at least 20 bytes is much less, in the transmission of data packets is very efficient
- The UDP header contains the following data
TCP protocol
When one computer wants to communicate with another, the communication between the two computers needs to be smooth and reliable in order to send and receive data correctly
-
For example, when you want to view a web page or email, you want to view the page completely and sequentially without losing anything
-
Or when you download a file, you want to get the whole file, not just a part of it
If the data is missing or out of order, it’s not what you want, so TCP is used
TCP is a connection-oriented, reliable, byte stream based transport layer communication protocol. TCP is a connection-oriented, reliable stream protocol. What is a stream? A stream is an uninterrupted data structure. Think of it like the flow of water in a drainpipe
TCP three handshakes to establish a connection, four waves to disconnect a connection is another topic, so let’s talk about it briefly
TCP three-way handshake
Three handshakes to establish links, for easy understanding, imitation of a face
-
Xiao Li (client) : Hello, are you the interviewer of XX?
-
Interviewer (server) : Uh-huh, yes. Are you Xiao Li who sent in your resume yesterday?
-
Xiao Li (client) : Yeah, yes, I am
Then, Xiao Li and the interviewer began to talk about the mountain happily
According to the above content, let’s take a look at the picture below.
The formal three handshakes to establish a connection are as follows
- First handshakeThe client sends a connection request packet to the server. The packet contains its initial data communication serial number. After the request is sent, the client enters
SYN-SENT
state - Second handshakeAfter receiving the connection request message segment, if the server agrees to connect, it will send a reply, which will also contain its own initial data communication serial number, and enter after sending
SYN-RECEIVED
state - Third handshakeAfter receiving the connection approval reply, the client sends an acknowledgement message to the server. After sending this message, the client enters the connection
ESTABLISHED
State, which the server enters upon receiving the replyESTABLISHED
The connection is successfully established
You might wonder, why does TCP require three handshakes to establish a connection, instead of two?
In fact, this function is used to prevent invalid connection request packet segments from being received by the server, resulting in errors
TCP waved four times
Wave four times to disconnect the link, then copy the phone 😄
-
Interviewer (Initiative) : Well, I have learned about your situation. Just wait for the announcement (I want to hang up)
-
Xiao Li (passive side) : uh-huh, good (this want to hang up? I haven’t talked enough.
-
Li (passive) : I hope I can work with you sometime.
-
Interviewer (Initiative) : Di… Di… Di… di
Let’s look at the real process diagram.
TCP is bidirectional. Therefore, both ends need to send FIN and ACK when the connection is disconnected
-
First wave If client A considers the data transmission complete, it needs to send A connection release request to server B
-
After receiving the connection release request for the second wave, B will tell the application layer to release the TCP connection, and then send an ACK packet and enter CLOSE_WAIT state. In this case, it indicates that the connection from A to B has been released and will no longer receive the data from A. However, because the TCP connection is bidirectional, So B can still send data to A
-
After waving for the third time, USER B will continue to send if there are still unsent data, and then send A connection release request to USER A. Then, user B enters the last-ACK state
-
After receiving the release request for the fourth TIME, A sends A confirmation reply to B. At this TIME, A enters the time-wait state, which lasts for 2MSL (maximum lifetime, which refers to the duration of the packet segment in the network, and will be discarded after timeout). If there is no resending request from B within this period, B enters the CLOSED state. After B receives the confirmation reply, it also enters the CLOSED state
Why does the client end up waiting for 2MSL
The client needs to ensure that the last ACK message is sent to the server. If the server does not receive it, it can request the client to resend it, so that the client still has time to resend it. Restart 2MSL timer
TCP/IP concurrency limit
The browser limits the number of concurrent TCP connections under the same domain name (2-10).
And in HTTP1.0 there is often a TCP/IP request for each resource download
TCP Features
-
connection-oriented
- Connection-oriented means that before sending data, connections must be established at both ends
Three-way handshake
In this way, a reliable connection can be established, laying a foundation for reliable data transmission
- Connection-oriented means that before sending data, connections must be established at both ends
-
Only unicast transmission is supported
- Each TCP transmission connection has only two endpoints for point-to-point data transmission. Multicast and broadcast transmission modes are not supported
-
Word oriented stream
- Unlike UDP, TCP transmits packets in byte stream mode without preserving packet boundaries
-
Reliable transport
- For reliable transmission, error codes are determined by the SEGMENT number and confirmation number of TCP. To ensure reliable transmission of packets, TCP assigns a serial number to each packet, and the serial number also ensures that the packets sent to the receiving entity are received in sequence
- The receiving entity then sends back an acknowledgement (ACK) of the successfully received byte, and if the sending entity does not receive an acknowledgement within a reasonable round trip delay (RTT), the corresponding data (if lost) will be retransmitted
-
Provide congestion control
- When the network is congested, TCP can reduce the rate and quantity of data injected into the network to alleviate the congestion
-
TCP provides full duplex communication
- TCP allows applications on both sides of the communication to send data at any time because there are caches at both ends of the TCP connection to temporarily store two-way communication data
- Of course, TCP can send a segment immediately, or it can cache for some time to send more segments at once (the maximum segment size depends on MSS)
UDP is different from TCP
By now, you should know a little bit about UDP and TCP, so let’s summarize by comparing them directly
contrast | UDP | TCP |
---|---|---|
Whether connection | There is no connection | connection-oriented |
reliable | Unreliable transmission, not using flow control and congestion control | Reliable transmission, using flow control and congestion control |
Connection number | Supports one-to-one, one-to-many, many-to-one and many-to-many communication | One-to-one communication only |
transport | For a message | Word oriented stream |
The first overhead | The header overhead is small, only 8 bytes | Minimum 20 bytes, maximum 60 bytes |
Applicable scenario | For real-time applications (IP phone calls, video conferencing, live streaming, etc.) | Suitable for applications that require reliable transmission, such as file transfer |
- TCP provides connection-oriented reliable services to the upper layer, while UDP provides connectionless unreliable services to the upper layer
- Although UDP is not as accurate as TCP transmission, it can also be used in many places where real-time requirements are high
- TCP can be used if the data accuracy is high and the speed is relatively slow
So I’m going to leave TCP very briefly, and then we’re going to move on to the application layer
The application layer
Application layer is the most contact with the user, the upper layer we receive the data received by the transmission layer, TCP/UDP protocol can transmit various program data packets, such as mailbox, web page, FTP and so on, so it needs different protocols to specify the format of data, after receiving rendering interpretation, application layer is composed of these protocols. Its packets are placed in UDP /TCP packet data
HTTP protocol, FTP protocol for file transfer, SMTP protocol for email sending, DNS protocol for domain name resolution, Telnet protocol for remote login and so on all belong to the application layer
There is also Socket, which is an abstract layer between the application layer and the transmission layer. It encapsulates the complex operation of TCP/IP layer into several simple interfaces for the application layer to call, so as to realize the process communication in the network
Above we have a basic understanding of the computer some communication basis, can say so far from an IP to the end of communication have been known, but we enter the domain name is not IP, so it is how to become IP communication? So that brings us to DNS in more detail
What is the DNS
Domain Name System (DNS) is a computer and network service naming System organized into a Domain hierarchy. It is used in TCP/IP networks as a distributed database that maps Domain names and IP addresses to each other. The service it provides is used to translate host names and domain names into IP addresses
In simple terms, the IP address Like a house number, when we are in the input domain name visit the web site, the data server is not meet you this domain name, it only know IP, your domain name will be through the DNS server parsed into IP value, through the house number (IP) to the data server for your web site and give you back to the browser
Why you need DNS
Most network communication is based on TCP/IP, and TCP/IP is based on IP addresses, so computers can only recognize IP addresses such as 252.94.131.12 when communicating over the network, but not domain names
We have no way to remember more than 10 IP addresses of the website (you have to say good memory that I obediently shut up 😄), generally when we visit the website, more is in the browser address bar to enter the domain name, you can see the required page, This is because a computer called DNS server automatically translates our domain name into the corresponding IP address, and then returns the corresponding web page through the IP address
Domain structure
A domain name is a method used to solve IP addresses on the Internet. A complete domain name consists of two or more parts, with periods in English between each part. To separate
Take www.qq.com. For example, and so on, is not more than a point, of course not more than a dozen, this last. By default, all urls end with a., but for the convenience of users, usually omitted, the browser will automatically add DNS resolution, com is the top-level domain name, QQ is the second level domain name, WWW is the third level domain name, if there is before the WWW, then the fourth level and so on
So the order in which we parse is going to be
. -> .com -> qq.com -> www.qq.com
Copy the code
DNS Obtaining Process
DNS is an application-layer protocol used to resolve the host name provided by a user into an IP address. The process for obtaining DNS is as follows
-
The DNS client runs on the user host, that is, our PC or mobile phone client runs the DNS client
-
The browser extracts the domain name field from the received URL, which is the host name of the visit, such as http://www.qq.com
-
The DNS client sends a query packet to the DNS server, which contains the host name field to be accessed, some cache queries and distributed DNS cluster work in the middle
-
The DNS client eventually receives a reply message containing the IP address corresponding to the host name
-
Once the browser receives an IP address from DNS, it can initiate a TCP connection to the HTTP server located at that IP address
DNS Resolution Process
If we want to visit www.qq.com, then what should we experience? Let’s look at a picture first.
Take a quick look at the picture. If you don’t understand it, look at the text
The figure above is divided into three sections
- DNS client, is the DNS client running on our host, PC or mobile phone client have
- Client to server, which can be understood simply as a router in our current network environment
- Server to server, and the last server refers to
Isp server/root DNS server/top-level DNS server/master DNS server
The DNS fetch process has many steps. If there are multiple requests in the process, it would be too time-consuming. So DNS has the concept of multiple levels of cache
-
Browser cache
- When the user accesses the browser
www.qq.com
Is displayed, the browser first searches for the IP address corresponding to the domain name in its cache - If the domain name has been accessed before and the cache has not been cleared, it exists. If the domain name does not exist, go to the next step
- When the user accesses the browser
-
System cache
- If there is no IP address corresponding to the domain name in the browser cache, the system automatically checks the user’s computer system
Hosts
Check whether the file DNS cache has an IP address corresponding to the domain name
- If there is no IP address corresponding to the domain name in the browser cache, the system automatically checks the user’s computer system
-
Router cache
- If neither the browser nor the system cache has an IP address corresponding to the domain name, check the IP address in the router cache. The preceding three steps are the DNS cache of the client
-
Internet Service Provider (ISP) DNS cache
- If the IP address corresponding to the domain name cannot be found on the customer service terminal, the system searches the DNS cache of the Internet Service provider (ISP)
- For example, if you use telecom’s network, you will find it in telecom’s DNS cache server
-
Root DNS server
- If none of the preceding information is displayed, enter the root server for query
- When the root DNS server receives the request, it looks at the region file record. If it does not, it sends the top-level domain names (
.com
) The server IP address tells the local DNS server
-
Top-level domain name server
- The top-level domain name server (TLN) receives the request and reviews the region file record. If not, the domain name server (
qq.com
The IP address of the server is told to the local DNS server
- The top-level domain name server (TLN) receives the request and reviews the region file record. If not, the domain name server (
-
Master domain name server
- The primary DNS server queries its cache after receiving the request. If it does not receive the request, the secondary DNS server (
www.qq.com
) and repeat the process until the correct record is found
- The primary DNS server queries its cache after receiving the request. If it does not receive the request, the secondary DNS server (
-
Save the result to cache
- The local DNS server saves the returned result in a cache for future use and feeds the result back to the client, which uses the IP address to establish a link with the Web server
DNS client can be obtained from the previous query cache information on answering queries, the DNS server may use its own resources to record information to answer the query cache, also on behalf of the requesting client to query or contact other DNS servers, to completely resolve the name, and then reply back to the client, this process is called recursive query
The client itself attempts to contact other DNS servers to resolve the name, and if the client does so, it uses separate and additional queries based on the server’s response. This process is called iteration, that is, interactive queries between DNS servers are iterative queries
This is the whole process of DNS. It is the first step of this interview question. The interviewer may also ask how to optimize DNS resolution
Why optimize DNS resolution
DNS resolution is the first step in the whole process of opening the website. After the user enters the domain name and hits Enter, the system invokes the DNS client and finds the DNS IP address configured or automatically assigned by the user. The DNS server completes the resolution of the digital IP server with the domain name. Typically it takes 20 to 120 milliseconds to return the IP address for a given domain name, and the browser doesn’t do anything until the DNS query is complete. Okay
Once the resolution is complete, the connection is established and maintained, that is, after a smooth access, the subsequent download speed of the web page is independent of DNS until the next resolution and access request is made
For many small websites, the DNS resolution time is close to 0.5s, and some even need about 1s to resolve the result. Users of general websites will give up visiting if the waiting time exceeds 8s, while for e-commerce websites, 4S is the limit of users’ patience, and generally optimized small websites, The DNS resolution time can be controlled within 200ms, and the DNS resolution time can be controlled within 50~100ms for websites with bandwidth of 100 mbit/s after optimization
So now you know why DNS resolution should be optimized, and how? Let’s move on
DNS resolution optimization – Make good use of cached TTL
DNS has multiple levels of cache, every time to find so many levels, it will take time, we should try to let users directly from the carrier’s DNS cache to get resolution records, so there is no need to go through the root DNS server following these processes, naturally save some time
When we purchase the domain name for domain name resolution, there is a TTL value (as shown in aliyun domain name resolution below).
It refers to the life cycle of domain name resolution (in seconds). In simple terms, it represents the cache time recorded on the DNS server when the DNS server resolves the domain name. This value is also very knowledgeable, we want to make sure that the server can be switched as quickly as possible when there is a problem
- You must know if your server has more than one or backup, if there is no backup, the server down can only generate anti, so,
TTL
The longer the better for you, becauseTTL
Short purpose is the server problems, can be switched in time, this for no backup site basic use, so at this time yourTTL
As long as possible, of course, not too long, general SettingsTTL 3600
Can be - If there are backup servers or multiple servers, switchover may occur due to server breakdown.
TTL
The shorter the time, the more timely the switch, butTTL
The shorter the time, it means that the carrier DNS cache often fails, common users, set toTTL 600
Can, if the timely switch, especially demanding site, setTTL 120
just
DNS resolution optimization – Load balancing
Configure multiple IP addresses for the same host name on the DNS server. When answering DNS queries, the DNS server returns different resolution results for each query using the IP address recorded in the DNS file, directing clients to different machines so that different clients can access different servers. In order to achieve the purpose of load balancing, can be based on the load of each machine or the machine from the geographical location of the user to start
As we use the CDN manufacturer do DNS, it is also using the DNS redirect, DNS server returns a with the IP address of the user the closest point to the user, the CDN node server is responsible for the response to the user’s request, provide the required content, CDN vendor’s DNS server the number of users access more and more, The A records of the DNS server will basically be cached by the DNS of various operators, so the service effect is the best
HTTP & HTTPS
After finishing DNS, I wanted to write a paragraph about HTTP and HTTPS, which can also be said for a long time, but later I felt it was not appropriate to write it here, so I will write it separately next time when I have the opportunity
feeling
Network communication to the end of this article, although had written hundreds of thousands of words, but can only say that tell a about integrating the content, how to say, some knowledge of network communication has mentioned, but not thorough, so need before the interview or leak can fill a vacancy, don’t delusion by reading the article or a post will think they know the network communication, TCP/IP/DNS/HTTP/HTTPS could be a long list
Of course, like most of the posts, this article has sorted out the content of network communication for everyone and described it in an easy-to-understand tone. This is also for most of the non-trained partners, and haihan also hopes to put forward any mistakes
If you want to further understand network communication, you can also this article as an introduction, in-depth look at some relevant knowledge, the third article summary also sorted out the network and browser knowledge of the mind map, where will not look up information to find the answer
In the next article, “an interview question”, enter the URL to render a comprehensive comb – page rendering, to be continued.
Oh, there are, can add a friend add group communication together, the public number [not serious front end] also welcome to pay attention to yo 😄