Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Packet Size ,Window Size and Socket Buffer In TCP

Tags:

tcp

sockets

After studying the "window size" concept, what I understood is that it keeps packet before sending over wire and till acknowledgement come for earliest packet . Once this gets filled up, subsequent packet will be dropped. Somewhere I also have read that TCP is a streaming protocol, and packet is what related to IP protocol at Network layer .

What I assumed till was that I have declared a Buffer (inside code) which I fill with some data and send this Buffer using socket. I declared a buffer of 10000 bytes and send it repeatedly using socket over 10 Gbps link .

I have following assumptions and questions. Please verify and help

  1. If I want to send a packet of 64,256,512 etc. bytes, declared buffer inside code of that much space and send over socket. Each execution of send() command will send one packet of that much size .

  2. So if I want to study the packet size variation effect on throughput, what do I have to do? Do I need to vary buffer size in code?

  3. What are the socket buffer which we set using SO_SNDBUF and SO_RECVBUF? Google says it's buffer space for socket. Is it same as TCP window size or something different? Which parameter is more suitable to vary or to increase throughput?

Also there are three parameter in socket buffer: Min, Default and Max. Which one should I vary to my experiment and to get more relevance?

like image 635
Vijnana Yogi Avatar asked Mar 18 '23 00:03

Vijnana Yogi


2 Answers

If I want to send a packet of 64,256,512 etc. bytes , Declared buffer inside code of that much space and send over socket .Each execution of send() command will send one packet of that much size.

Only if you disable the Nagle algorithm and the size is less than the path MTU. You mustn't rely on this.

So if I want to Study the Packet size variation effect on throughput, What I have to do , vary buffer space in Code?

No. Vary SO_RCVBUF at the receiver. This is the single biggest determinant of throughput, as it determines the maximum receive window.

what are the socket buffer which we set using SO_SNDBUF and SO_RCVBUF

Send buffer size at the sender, and receive buffer size at the receiver. In the kernel.

It's Same as TCP Window size

See above.

or else different ? Which parameter is more suitable to vary to increase throughput ?

See above.

Also there are three parameter in Socket Buffer min Default and Max . Which one should I vary for My experiment to get more relevance

None of them. These are the system-wide parameters. Just play with SO_SNDBUF and SO_RCVBUF for the specific sockets in your application.

like image 161
user207421 Avatar answered Mar 25 '23 23:03

user207421


TCP does not directly expose a way to control the way packets are sent since it is a stream protocol. But you can make the TCP stack send packets by disabling the Nagle algorithm. That way all data that you send will be sent out immediately instead of being buffered. Data will be split into packets of MTU size which is like ~1400 bytes. Depends on the link.

To answer (2): Disable nagling and invoke send with buffers of < 1400 bytes. Use Wireshark to make sure you got what you wanted.

The buffer settings have nothing to do with any of this. I know of no valid reason to touch them.

In general this question is probably moot since you seem to want to send a lot of data. Just leave Nagling enabled and send big buffers (such as 64KB).

like image 44
usr Avatar answered Mar 25 '23 23:03

usr