Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of linux sliding window

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what is the use of linux sliding window". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Sliding window

We all know that TCP is a reliable protocol, and reliability often comes from the acknowledgment retransmission mechanism of TCP. On the basis of acknowledgement retransmission, the sliding window protocol is implemented. Sliding window has two main functions:

Ensure the reliability of TCP

Provide the flow control characteristics of TCP

1.1 sliding window ensures reliability

The so-called window is actually a sequence of bytes stored in the sending buffer that can be sent by the sender. Its continuous range is called a window. Sliding means that as the data is constantly sent, the window moves forward in the buffer. For example:

After TCP establishes a connection, B tells A the size of its receive window, such as 20

Then A sent 11 bytes, the position of the sending window remained unchanged, and B received the out-of-order data.

Only after A has successfully sent the data and received the confirmation that B has returned, will the sending window move forward in order, thus avoiding the repeated transmission of data after the timeout.

Note: if B does not return confirmation at the specified time, then side A will repeat the transmission.

1.2 sliding window for flow control

There are two main points to be mastered in flow control. One is the mechanism that TCP uses sliding window to realize flow control, and the other is how to consider the transmission efficiency in flow control.

1.2.1 flow control

The so-called flow control is mainly a kind of end-to-end control that the receiver transmits information to the sender so that it does not send data too fast. The main way is that the returned ACK will contain the size of its own receive window, and use the size to control the sender's data transmission.

This involves a situation, if B has told A that its buffer is full, so A stops sending data; after waiting for a period of time, B's buffer has a surplus, so send a message to A telling A that my rwnd size is 400, but unfortunately this message is lost, so A waits for B to notify | | B waits for A to send data deadlock status. In order to deal with this problem, TCP introduces a persistence timer (Persistence timer). When A receives a zero window notification from the other party, the timer is enabled, and the time is up to send a 1-byte probe message, and the other party will respond to its own receive window size at this time. If the result is still not zero, reset the persistence timer and continue to wait.

1.2.2 Transmission efficiency

An obvious problem is: a single send byte, a single acknowledgment, and a window has a spare that notifies the sender to send one byte, which undoubtedly increases the number of unnecessary messages in the network. So our principle is to send as many bytes at a time as possible, or notify the sender to send multiple bytes at a time when there is more window space. For the former, we widely use the Nagle algorithm, namely:

If the sending application process sends the sent data to the send cache of TCP byte by byte, the sender sends the first data byte first and caches the next byte first.

When the sender receives the confirmation of the first byte (also gets the network situation and the size of the receiving window of the other party), the remaining bytes of the buffer are sent out in a message of appropriate size.

When the data that arrives has reached half the size of the sending window or reaches the maximum length of the message segment, a message segment is sent immediately; for the latter, we often ask the receiver to wait for a period of time, or the receiver gets enough space to accommodate a message segment or tells the sender to send the data when the receiving cache is half free.

two。 Congestion control

The bandwidth in the computer network, the cache in the switching node, the router and so on are all network resources, and the available resources they can provide are all limited. if at some time, the demand for a certain resource in the network exceeds its available part, the performance of the network will deteriorate, just like a traffic jam, the number of cars exceeds the load of the road section, that is, congestion, analogy to the network, is congestion control.

Note: congestion control is a global process, while the flow control in the sliding window is the control of point-to-point traffic, they are essentially different.

The congestion control of TCP consists of four core algorithms: slow start, congestion avoidance, fast retransmission and fast recovery.

2.1 slow start and congestion avoidance

The sender maintains a state change called congestion window. the size of the congestion window depends on the degree of congestion of the network and is changing dynamically, while the sender's sending window may be equal to the congestion window, or it may be because the receiver's receiving cache is not enough, so the sending window will be smaller than the congestion window.

The idea of the slow start algorithm is that it is necessary to detect the degree of network congestion without sending a large amount of data at the beginning, and gradually increase the size of the congestion window from small to large.

For congestion avoidance, there is a slow start threshold ssthresh state variable in congestion control. Assuming that the congestion window size is cwind, there are the following situations:

When cwind

< ssthresh时,即执行慢开始算法,当使用当前拥塞窗口发送数据,收到多次确认以后,将cwind加倍,继续发送; 当cwind >

When ssthresh, execute congestion avoidance algorithm, cwind+1, and then continue to send data

When the network sends congestion, update ssthresh to half of the pre-congestion ssthresh value, reset cwind to 1, and continue according to the above two situations.

2.2 Fast retransmission and fast recovery

In fact, the fast retransmission algorithm requires the sender to retransmit the message segments that have not been received by the other party as soon as they receive three repeated acknowledgements in a row, without having to wait for the set retransmission timer to expire. Fast retransmission is used in conjunction with fast recovery. There are two situations:

When the sender receives three repeated acknowledgements in succession, it executes the multiplication reduction algorithm, which halves the ssthresh, but does not execute the slow start algorithm.

Another situation is that considering that if the network is congested, the sender may not receive three consecutive repeated acknowledgements, so it will think that there is no congestion in the network, so it does not execute the slow start algorithm at this time, but sets the cwind size to ssthresh and performs the congestion avoidance algorithm.

Generally speaking, TCP congestion control actually ensures the fairness between data streams, because once packet loss occurs, it immediately reduces the Backoff by half, which can leave enough space for other new data streams to ensure the fairness of the whole.

3. Disconnect and reconnect

As the name implies, it is necessary to reconnect after the network is broken. In network programming, disconnection reconnection mechanism is necessary, so how to design a disconnection reconnection mechanism?

3.1 the program sets a fixed reconnection time

There are two situations:

One is to reconnect immediately after disconnection, then reconnect after an interval of 2 seconds, then 4 seconds, 6 seconds, 8 seconds, etc.

The second is to reconnect in 2 seconds, 4 seconds, 6 seconds, 8 seconds.

3.2 Let the customer set up

After being disconnected, a pop-up window on the interface allows the customer to set the reconnection interval, which is reflected in many desktop clients and mobile app.

3.3 Monitoring network statu

We can get the network situation, if the network is disconnected, then we certainly will not reconnect, but if the network is good, we have to reconnect immediately.

This is the end of the content of "what is the use of linux sliding window". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report