Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the minimum SO_RCVBUF value?

To minimize latency (I don't care about packet loss) I want the smallest possible receive buffer for UDP. However, when I set SO_RCVBUF to below 1000 (with setsockopt), my program never receives any packets. The datagrams I am sending have 28 bytes of data, for a total on-wire packet size of 70 bytes, so why can I not receive anything if SO_RCVBUF is < 1000? And how do I change this, to allow a smaller buffer size?

Additionally, is it possible to set the buffer in terms of number of packets, rather than bytes? Or is there some way I can manually empty it?

like image 468
Benubird Avatar asked Oct 11 '22 16:10

Benubird


1 Answers

Making the socket receive buffer smaller will not reduce latency.

Instead you need to dequeue all available packets each time. This can be accomplished with a non-blocking socket and edge-triggered epoll or kqueue - on "readable" event read until you get EWOULDBLOCK.

As to why you don't get any input with small SO_RCVBUF value, look here - http://vger.kernel.org/~davem/skb_sk.html, and here - http://lxr.linux.no/#linux+v2.6.37/include/net/sock.h#L621

Hope this helps.

like image 164
Nikolai Fetissov Avatar answered Oct 14 '22 22:10

Nikolai Fetissov