TCP/IP interactive data streams and block data streams

Source: Internet
Author: User

The TCP-based network protocols include telnet, ssh, FTP, and HTTP. These protocols are divided into two categories based on data throughput:

(1) interactive data types, such as telnet and SSH. In most cases, this type of protocol only performs small-traffic data exchange, such as pressing the keyboard and displaying some text. The proportion of Interactive Data Types in communication is 10%;

(2) Data is block type, such as ftp. This type of Protocol requires that TCP can carry data as much as possible, maximize the data throughput, and improve the efficiency as much as possible. The proportion of data block types in communication is 90%;

For these two cases, TCP provides two different policies for data transmission;

1. Interactive Data Stream of TCP

To improve the interaction of TCP data streams, TCP provides two policies to improve transmission efficiency and reduce network burden: (1) routing with Ack. (2) Nagle algorithm (send as much data as possible at a time ).

(1) memory with Ack

Here is a special example: remote SSH connection key echo;

C-end keys send data, S-end sends and receives data ACK, S-end sends echo data, and C-end sends echo data ack;

When the host receives the TCP datagram from the remote host, it usually does not immediately send the ACK datagram, but waits for a short period of time. If the host still has the TCP datagram sent to the remote host during this time, then, the ACK datagram "bytes" is sent out, and the original two TCP datagram data packets are integrated into one transmission. Generally, this time is 200 ms. We can see that this policy can significantly improve the utilization of TCP datagram.

(2) Nagle Algorithm

Because small groups in TCP (for example, 41byte group: 20 byte IP header, 20 byte TCP header and 1 byte data) increase the possibility of congestion in the WAN, the Nagle algorithm is optimized;

The algorithm requires that a TCP connection can have only one unconfirmed small group, and other small groups cannot be sent before the Group's confirmation arrives. On the contrary, TCP collects a small number of groups and sends them out in a group upon confirmation;

The advantage of this algorithm is that it is adaptive: The faster the confirmation arrives, the faster the data is sent;

When host a sends a TCP datagram to host B and enters the status of waiting for host B's ack datagram, the TCP output buffer can only have one TCP datagram, this datagram constantly collects the subsequent data and integrates it into a large data packet. When the ACK packet of host B arrives, the data will be sent "in one brain. This Nagle algorithm policy reduces the network burden.

When writing a plug-in program, you can disable this algorithm through tcp_nodelay. In addition, this algorithm is used to check the situation. For example, if the X Window Protocol Based on TCP still uses this algorithm when processing mouse events, the "latency" may be very high.

2. TCP block data streams

For FTP, which has high requirements on data throughput, we always want to send as much data as possible to the other host, even if it is a little "delay. TCP also provides a set of policies to support such requirements. In TCP, 16 bits indicate the size of the window, which is the core of these policies.

2. 1. Ack problems during Data Transmission

Before interpreting the sliding window, you need to check the ACK response policy. Generally, if the sender sends a TCP datagram, the receiver should send an ACK datagram. But in fact, this is not the case. The sender will continuously send data to fill the receiver's buffer zone as much as possible, and the receiver only needs to send an ACK message to respond to the data, this is the cumulative feature of ack, which greatly reduces the burden on the sender and receiver.

2. Sliding Window

A sliding window essentially describes the data of the receiver's TCP datagram buffer size. Based on this data, the sender calculates the maximum amount of data that can be sent. If the sender receives a TCP datagram whose window size is 0, the sender stops sending data and waits until the sender sends a datagram whose window size is not 0. P211 and p212 explain this point well.

For the sliding window protocol, the book also introduces three terms:

  1. Window combination: when the window is close from the left to the right, this happens when the data is sent and confirmed.
  2. Window Opening: when the right side of the window moves to the right, this phenomenon occurs after the receiver processes the data.
  3. Window contraction: this phenomenon does not often occur when the right side of the window moves to the left.

TCP uses this window to slowly move from the left of the data to the right, and send the data in the window range (but do not send all, only data in the window can be sent .). This is the meaning of the window. Figure 20-6 illustrates this. The window size can be determined through socket. 4096 is not the ideal window size, while 16384 can greatly increase the throughput.

2. 3. Data congestion

The above policy can be used for intra-lan transmission, but problems may occur in wide-area networks. The biggest problem is that there is a bottleneck during transmission (for example, it must go through a slip low-speed link) to solve this problem, the TCP sender needs to confirm the maximum data throughput of the lines connecting both parties. This is the so-called congestion window.

The principle of the congestion window is very simple. The TCP sender first sends a datagram and then waits for the response from the other party. After receiving a response, the sender doubles the size of the window and then sends two consecutive datagram packets, wait until the other party responds, and then double the window (first the exponential double of 2, to a certain extent, it will become the current growth, this is the so-called slow start), send more data packets, after a timeout error occurs, the sender learns the line bearing capacity of both parties, determines the size of the congestion window, and the sender sends data using the size of the congestion window. It is very easy to observe this phenomenon. Generally, when downloading data, the speed is slowly "Rushed up"

The above is the general process of TCP data transmission. Although not detailed, it is sufficient to describe the working principle of TCP. The focus is on the traffic control principle of TCP, sliding window, and congestion window, ack accumulation confirmation and other knowledge points.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.