More hair, less code
This article has been included in my GitHub, welcome everyone to participate in star and issues.
https://github.com/midou-tech/articles
Nagging a few words
A few days ago, I asked everyone in the group about the state of spring recruitment recently.
If you are still enrolled in spring recruitment, whether it is social recruitment or school recruitment. Uncle Long would like to say a few words, this year’s overall economic situation is very bad, maybe some people do not realize how bad, but I believe many people feel. Many companies are living beyond their means, laying off workers and cutting costs, and many are changing their expansion plans to staying alive.
Everyone who is looking for a job, do not expect too much of the market, do not feel that my professional seniors are not BAT into the market, now the supply and demand relationship has changed, the demand is becoming less and less, but the supply has been increasing, looking for a job you should also adjust their expectations. Of course, people with good ability will not go to BAT, but it is very important to have good ability, but it is impossible for everyone to have good ability, so you should have the right expectation in mind and constantly polish their ability.
Prepare job-hopping you must also think clearly in jump, before every year is gold, silver and four job-hopping season. This year, I heard several seniors preparing for job-hopping said that many companies are symbolic aspects and do not offer at all.
By the way, what is symbolic aspect? The company is external, and the company will recruit at any time. If you see a company’s external website is not hiring, it basically means that the company is cold. Unless there is a real collapse, companies will usually post job openings on their website, but are they actually hiring?
So there is a lot of face is, however, the face is also very good, is not to send offer. If so, it’s not you, it’s the market. If a company really wants you, cherish it.
All right, uncle Long, that’s it. Let’s do the dry stuff. Today’s focus is on TCP reliability, including some key interview questions.
The body of the
After data structures, computer networks are the most frequently asked questions in job interviews. Uncle Long attached great importance to this knowledge, so he was praised by many interviewers during the school recruitment, which was also an indispensable factor for uncle Long to get more than 20 offers.
Before the computer network architecture computer network five layer structure analysis, TCP sticky packet problem how to solve, flow control & congestion control (STAMP I can see the article oh).
Today talk about the reliability of TCP, the network inside the important knowledge points are basically finished, if there is what do not understand the background to get long uncle wechat, silent Mimi hint under the long uncle.
Reliability is easy to understand. It’s reliability. What is reliable? We often hear teachers say that certain students are reliable, students will say who is reliable, in the society, leaders will also like those reliable subordinates, bosses like reliable employees. Reliable is responsible for things can be completed as scheduled, quality assurance.
The function of TCP is to deliver data. Therefore, the reliability of TCP ensures that data is delivered to the peer end in sequence, on time, and without data loss.
Uncle Long must make one thing clear, reliable does not equal security, TCP does everything possible to ensure data reliability, but nothing to ensure data security. Security means that your data cannot be seen or stolen by others. Data on TCP is transmitted in plaintext.
How does TCP ensure reliability
TCP is a reliable transmission protocol. How to ensure reliability? TCP is guaranteed by the following mechanisms
1. Byte numbering mechanism
The numbering mechanism is easy to understand, which is to number each byte of the data part of the TCP data segment.
Why do we need numbers?
Easy to say, just to be clearer receive and send. TCP data is sequentially received and assembled before being delivered to the upper layer.
In daily life also often encounter such circumstance, you go to the bank still must not take a number at the door, take a number to deal with first, make sure to deal with things not disorderly already, also need not everybody stands long queue, call to number is you.
2. Confirmation mechanism of data segment
This is the confirmation and response mechanism that we often hear, asking and answering, ensuring that the other party has received the question, and repeating the question if it has not been received.
TCP acknowledgement is that each data segment is sent with an acknowledgement number from the receiving end. The received acknowledgement number indicates that all the data before this number is received.
Confirm that there are several important questions inside the response mechanism, which is also a high frequency interview problem, Long Uncle must nag a few words.
- TCP can send multiple data segments consecutively at one time
TCP can send multiple data segments consecutively, depending on the size of the window returned by the other party. As long as the window size can be accommodated, Negale algorithm can be turned off to send multiple data segments continuously.
- Only continuously received data segments are acknowledged
Suppose you send data segments 101, 201, 301, 401, 501, 601, and the receiver receives 101, 201, and 501. In this case, the receiver will only return an acknowledgement of 201, but not an acknowledgement of 501, because 301 and 401 have not been received. Confirmation of 501 will be returned only after 301 and 401 have been received (without a timeout).
- Data with discontinuous serial numbers is cached first
In the example above, the recipient receives 101, 201, and 501, but the 501 cannot be acknowledged because of discontinuous data. However, the 501 is cached locally, and the 501 is immediately returned to the recipient after receiving 301 and 401.
TCP timeout retransmission mechanism
The preceding two methods are used to prevent and reduce errors. The timeout retransmission mechanism ensures that TCP data is lost during transmission. Therefore, timeout retransmission mechanism is an important mechanism to ensure reliability.
Each TCP segment sent starts a Retransmission Timer (RTT). If no acknowledgement is received within the timer time, a retransmission is initiated to resend the data segment.
There is also a point that TCP does not immediately remove a data segment from the buffer after sending it, but does not discard it from the send queue until an acknowledgement is received.
The timeout retransmission principle looks simple, and the retransmission procedure is simple, but it’s as simple as that. One difficulty is that the timing of the timeout retransmission timer is a complex issue.
On the surface, it looks simple. Isn’t it the time it takes to send a message to the receiver *2?
It’s not that simple
A round trip through the middle of the network section is not fixed, network congestion degree is uncertain.
Just like when you’re driving a car, navigation can’t just give you one route, and it will give you a different route each time because of the congestion on the road.
TCP guarantees reliability, so TCP requires high performance communication regardless of network environment and must maintain this feature regardless of changes in network congestion.
TCP currently uses an adaptive algorithm to calculate RTT value.
Given an initial RTT value, the initial RTT value is 6s. Each subsequent acknowledgement will be calculated to calculate the round-trip time and RTT fluctuation, that is, the RTT deviation. Finally, the RTT+RTT deviation is the new RTT value.
= (1 – alpha)+ alpha.
RFC 6298 recommends a α value of 1/8, i.e. 0.125.
Data will not be retransmitted indefinitely and repeatedly. If no acknowledgement is returned after a certain number of retransmissions, the system determines that the network or the peer host is abnormal and forcibly closes the connection. Notify the application of abnormal communication and forcibly terminate.
I am Long Shu, an uncle who shares Internet technology and mind journey. Thank you for reading. Your little thumbs-up will be a great incentive for me to continue teaching people how to fish.