In the case of "data", why is the data size equal to 1374?

This is just a question based on curiosity, but I could learn something useful.

With my Node.js server, when I received data through net.Server, I printed out the size (in bytes) of each "packet" of data.

socket.on 'data', (data) -> console.log data.length 

I noticed that most of the time it is 1374 bytes. The rest of the time it is a multiple of 1374. The highest indicator that I received from 200 data events was 17,862.

Where does this number 1374 come from? And why is the data length sometimes multiple?


My best guess is that with TCP, 1,500 bytes is the most common MTU for Ethernet, and 126 other bytes make up the TCP packet header. Node.js can sometimes compress these packages together if they get them fast enough, so sometimes they come in multiples.

+4
source share
1 answer

Part of 126 is associated with the TCP header itself, which is 20 bytes.

The data is additionally supplemented with a "header" imposed by the server library, which is used for the very reason that you described: "knock down" the data when several packets are received close enough to each other. When the packets are in quick succession, the additional information that is included is used to determine the correct order of the packets and combine the data to return.

This is a general method of reducing the amount of processing that is included in each complete data set (why start processing three times in three separate pieces of data, when they can be performed once for a larger existing set), but in cases when it comes to matching windows, it can contribute to what is called "silly window syndrome" (the window is reduced to such an extent that the data that is delivered is smaller than the header itself, which makes the transfer extremely inefficient). However, if you encounter this problem, you should probably reconsider the way you send and receive your data.

+1
source

All Articles