TCP 2
There are two kinds of data included in TCP segments:
- interactive data: such as Telnet, SSH;
- bulk data: such as FTP, email;
Interactive Data Flow
Each interactive keystroke normally generates a data package. So entering a key in Telnet/SSH will generate 4 segments:
- the interactive keystroke from the client
- an acknowledgment of the keystroke from the server
- the echo of the keystroke from the server
- an acknowledgment of the echo from the client
delayed acknowledgments
Normally segment 2 and 3 are combined using delayed acknowledgments. In this way TCP does not send an ACK the instant it recieves data. Instand, it delays the ACK, hoping to have data going in the same direction as the ACK, so the ACK can be set along with data. Most implement use a 200ms delay. The max delay time is 500ms in RFC.
Nagle Algorithm
Nagle algorithm says that when a TCP connection has outstanding data that has not yet been acknowledged, small segments cannot be sent until the outstanding data is acknowledged. Instead, small amount of data are collected by TCP and sent in a single segment when the acknowledgment arrives. So on a slow WAN, where it is desired to reduce the number of tinygrams, fewer segments are sent.
In some real-time application environment, Nagle algorithm needs to be turned off.
It can lead to noticeable delays to the interactive user.
The socket API uses the TCP_NODELAY
socket option to disable the Nagle algorithm.
Bulk Data Flow
With TCP's sliding-window protocol the reciever does not have to acknowledge every received packet.
The size of window offered by the receiver can usually be controlled by the receiving process.
1 2 3 | | <- MSS -> | | 1024B | 1024B | 1024B | 1024B | 1024B | ... | <-------- now window size --------> | |
The socket API allows a process to set the sizes of the send buffer and receive buffer(SO_RCVBUF
, SO_SNDBUF
).
The size of the receive buffer is the max size of the advertised window for that connection.
Slow Start
Slow Start algorithm operates by observing that the rate at which new packets should be injucted into the network is the rate at which the acknowledgments are returned by the other end.
Flow control for two ends:
- sender: congestion window(拥塞窗口), from 1 segment step 1 when ACK is received
- receiver: advertised window(通知窗口)/receiver window(接收窗口)
The sender can transmit up to the minimum of the congestion window and the advertised window.
Reference
- TCP/IP v1