[Computer Networks] Transport Layer Protocol – TCP

Time:2023-10-27

1. Congestion control

All hosts and devices throughout the network adhere to the TCP/IP protocol.

E.g. It is not unusual for 30 people in a class to take a test and only 2 or 3 fail it.
But if only 2 or 3 people pass and everyone else flunks, that’s unusual

Failing a class is different from failing a class.


[Computer Networks] Transport Layer Protocol - TCP

When host A sends a message to host B
If 1000 messages are sent and only 1 or 2 are lost, it is considered a normal packet loss and a timeout is performed to retransmit the data.


[Computer Networks] Transport Layer Protocol - TCP

1000 messages sent, 900 more lost.Host A definitely doesn’t think it’s a problem with its own sending and thinks it’s a problem with the network

The state of a potential problem with a network is referred to as anetwork congestion

When the network is in congestion, it will affect all hosts covered by the network, not only host A has a large number of packet loss, other hosts will also have a large number of packet loss


What is the sender’s sending strategy when a large number of packets are lost?
Reduce the amount of transmissions first
1. Continued buffer time for the network
2. Continued mapping of network severity for all hosts


If network congestion occurs, it is necessary to ensure that
1. Ensure that network congestion cannot worsen
2. Restore network traffic as soon as possible if network congestion improves


slow start

TCP introductionslow startmechanism, first send a small amount of data to find out the current state of network congestion, and then decide to transmit data at what speed

[Computer Networks] Transport Layer Protocol - TCP

The network is currently congested, host A sends a message to host B to ask first, and if it receives an answer, then host A sends two more messages to host B.
If another answer is received, host A sends four messages, and so on.
If an answer is received, send twice the number of messages next time.
If no answer is received, the message received from host A to host B cannot pass.The amount of data currently being sent is a good indicator of the severity of network congestion.

messages from sending 1, 2, or 4, is called theDetection of network state


The congestion window can be thought of as the sender host.Indicators for measuring the state of network health
with the help ofThe congestion window.to measure the severity of network congestion.
Network congestion may occur when sending messages that exceed the congestion window size


Sliding window final size

Sliding window = min(reception capacity of the opposite host win , congestion window of the network)
The amount of data sent to the other end at one time, depending on the acceptance capacity of the host at the other end and the minimum value of the network congestion window

So at the very beginning, the congestion window is 1, and every time an ACK response is received, the congestion window is increased by 1
Each time a packet is sent, the congestion window is compared with the window size fed back from the receiving host, and the smaller value is taken as the actual window sent.

Why is an exponential increase scheme used to design the rate of increase of the corresponding congestion window?

For example, there is a landlord who has many houses and has a tenant farmer who rents the landlord’s house.
The tenant farmer owed the landlord more than a year’s rent, and one day the landlord asked the tenant farmer for rent
The sharecroppers then began to complain, wanting to wait until they had sold their grain to pay it back
The landowner disagreed with the practice, and then came up with what seemed like a good way to give the sharecroppers
The landlord told the tenant farmers to give me one grain of rice today, two grains of rice tomorrow, and each time, according to the exponential increase, give me one month to pay back the rent.
The sharecroppers were very happy to hear this and agreed to it
But the sharecroppers had just given less than ten days when they realized they couldn’t afford it


This increase is characterized by It’s slow in the beginning and increases very fast once you pass the tipping point
the reason whySlow start is just slow in the early stages, but the tensile speed is fast.


The landowner thought, “If this keeps growing exponentially, the sharecroppers won’t be able to pay back the money, and the squeeze will be too much.
So the landowner changed a way of repayment, the first or exponential increase in repayment, but also to a certain extent with so repayment, in accordance with the linear growth of the repayment can be
E.g., after paying back 1w, you only need to increase it by a fixed 1000 each time


In order not to increase that fast, therefore the congestion window cannot be simply doubled
Introducing aThreshold for slow start
When the congestion window exceeds the entire threshold, it no longer grows exponentially, but rather linearly

[Computer Networks] Transport Layer Protocol - TCP

At first Since it is a slow start, it increases exponentially and grows rapidly when it reaches theThreshold for slow start (ssthresh)When not increasing exponentially in
Instead, it increases in a linear fashion, and when the congestion window size detects 24, it is found to cause network congestion.
The slow start threshold becomes half the original value to the new ssthresh value
At the same time, the congestion window is set to 1 and grows exponentially again, when it reaches again theNew Threshold for Slow StartWhen, again in a linear fashion, the

2. Delayed response

[Computer Networks] Transport Layer Protocol - TCP

Copy the data from the transmit buffer to the receive buffer.

As the receiver, it is possible to answer the call by answering theNotice to the other side of a larger window of headlines.This further improves the sender’s sending efficiency

The other side then updates with a larger sliding window


[Computer Networks] Transport Layer Protocol - TCP

As long as when delivering the receiver’s data to the upper layers as quickly as possible, theto have more space left in the receive buffer, i.e., theLarger window for the header

So it gives the receiver’s upper layers more time to read the
1. Let it be read as soon as possible in the meantime
2. If always reading, read more


So the introduction of thedelayed responseThe concept of waiting for a while, within the range of its timeout, before answering the
The essence of delayed response is to increase efficiency.

General delayed response There are two delay strategies
1. Quantity limit: answer every N packets
2. Time limit: answer once after the maximum delay time has elapsed

3. Sticky packages

It is not clear how the other party sends, TCP is oriented to the byte stream, sending and receiving is not directly related, how others send is not clear
To ensure that you read a complete message.
Either read one or more, but each can be separated so that application layer messages can be processed correctly

The case of reading more or less, for the next conformal text, is called theSticky packets.


E.g. Suppose you have steamed buns at your house, and a pot of buns has just come out, and you’re so hungry that you reach for them
The bun you get at this point may be half a bun, or you may get several at once
Because the buns are stuck to each other

So it’s normal to separate the buns one by one immediately after steaming them, at which point it’s just one by one to get the buns
Separating the packets can be seen as a solution to the sticky packet problem.

The essence of the sticky bun problem: clarifying the boundaries between buns

Option 1
Fixed-length header, sender based on sockets Application layer based The message sizes sent are all fixed-length (1024, 4096)
So the other side in reading data, you must read under the (1024) 4096 bytes, read not to deliver upwards

Option 2
Adding special symbols between messages
e.g. use space as separator between messages

4. TCP exceptions (interview questions)

process termination

Once the link is established, the client process and the server process use the corresponding file descriptors.
engage both client and server in communication
If one of the communicating parties’ processes simply crashes, what happens to the maintained links?

A process used to claim a lot of resources, eventually the process hangs and the memory claimed by the process is no longer there
The PCB address space etc. of a process is managed by the operating system
When the operating system creates a process, it requests resources, and when the process crashes, the operating system recovers the corresponding resources.


So when a process exits, links or files created by the process through system calls are automatically turned off by the operating system

reboot

When you open the drawing board, if you do not close the drawing board, but directly shut down the computer, then the operating system will be prompted, there are still running processes in the current system, whether to terminate the
If you click Yes, the process will be killed before shutting down the computer.
Before shutting down, the process first reclaims its own resources

So if you start more processes in the service, it’ll take a little longer to shut down.
Before shutting down the computer, it automatically performs four hand waves to break all links and kill all processes.

Network cable disconnection

Client and server are communicating normally, both are sending and receiving messages, unplug the client’s network cable
When a client opens a browser to access a page, the browser immediately recognizes that the page has changed and is not working properly.

This means that the hardware behavior of unplugging the network cable can be recognized by the local operating system.

There is a problem with the underlying network, the corresponding link is on the client, and the operating system recognizes that the network is not communicating properly, so link maintenance becomes meaningless.The OS can do this by turning the link right off

The server was unaware that the network cable had been unplugged and it came upLink Status Cognitive Inconsistency Problems
The server has a correspondingsurvival strategies.Periodically ask the client’s TCP link if it’s alive, and if there’s no answer, it’ll shut down the link

5. Fully connected queues

[Computer Networks] Transport Layer Protocol - TCP

TCP protocols, which need to be maintained at the bottom, fully-connected queues, theThe maximum length is the second argument of the listen function + 1
E.g., if the second parameter of the listen function is 1, the maximum number of successful connections is 2


If there are any more connections, the servers are in the SYN_RECV state
If the server does not process ACKs for a long period of time, the server is under a lot of pressure because two connections exist at the upper level all the time
So it will be maintained for a little while, and if it still can’t complete three handshakes, the link will be released

Fully connected: already in a successful connection state, not yet ready to be fetched by the upper layer


[Computer Networks] Transport Layer Protocol - TCP For example, suppose you’re a waiter at Haidilao, and the place is full, and when a customer comes to ask, if you say “It’s full, go eat somewhere else,” the customer will leave, but it’s very likely that in a few minutes, there will be a place inside, and the corresponding tables and chairs will be empty for a few minutes.

That’s why it was introduced to get guests to line up
At this point, if another customer comes to inquire, you can tell him that it is full, but in a few minutes there will be a place, you can wait in line under the
This allows for 100% utilization of the seat

The reason for standing in line is to make sure that you’re always utilizing 100% of your restaurant’s internal resources.

Conclusion:
Seabiscuit can’t do without outside queues

The fully-connected queue can’t do without thatWhen some clients within the server quit, freeing up the corresponding network resources, immediately fetch the connection up at the bottom level
Provide services externally without leaving the server idle


If the owner of Hai Di Lao arranges a very large number of seats outside for customers to queue up, but the customers are reluctant to queue up for a long time
For the cost of these seats, we could’ve expanded the restaurant.

The queue shouldn’t be too long.Graft the cost of maintaining the queue onto the server to give the server more throughput

Recommended Today

uniapp and applet set tabBar and show and hide tabBar

(1) Set the tabBar: uni.setTabberItem({}); wx.setTabberItem({}); indexnumberisWhich item of the tabBar, counting from the left, is indexed from 0.textstringnoButton text on tabiconPathstringnoImage PathselectedIconPathstringnoImage path when selectedpagePathstringnoPage absolute pathvisiblebooleannotab Whether to display uni.setTabBarItem({ index: 0, text: ‘text’, iconPath: ‘/path/to/iconPath’, selectedIconPath: ‘/path/to/selectedIconPath’, pagePath: ‘pages/home/home’ }) wx.setTabBarItem({ index: 0, text: ‘text’, iconPath: ‘/path/to/iconPath’, selectedIconPath: ‘/path/to/selectedIconPath’, pagePath: ‘pages/home/home’ }) […]