socket module rcvbuf and sndbuf

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

socket module rcvbuf and sndbuf

Ben Browitt
Hi,

I'm writing a simple wrapper around the socket nif to test the performance compared to gen_udp.
My questions are specific to UDP sockets.

How do the socket rcvbuf and the otp rcvbuf relate to each other?
The 'rcvbuf' with level = socket is the size of the OS level receive buffer.
The 'rcvbuf' with level = otp is the size of the buffer "we" read into when we read data (with recv/recvfrom/recvmsg).
If UDP MTU is 1500 bytes, what happens if the socket rcvbuf=MTU or rcvbuf=MTU*N?
Should the otp rcvbuf be equal to the socket rcvbuf or larger? What's the difference?
What happen if the wrapper module doesn't read messages fast enough from the socket nif?

Does sndbuf have any effect on UDP sockets?
Should the wrapper module queue packets if the sndbuf is full and resend when possible or should it just drop packets?

What's the difference between recv, recvfrom, recvmsg and similarly send, sendmsg, sendto?

Is it relatively safe to use the socket module in production?
What should I be careful about when implementing the udp wrapper module?

Thanks




Reply | Threaded
Open this post in threaded view
|

Re: socket module rcvbuf and sndbuf

Micael Karlberg-5
On 2019-11-06 14:54, Ben Browitt wrote:

> Hi,
>
> I'm writing a simple wrapper around the socket nif to test the performance compared to gen_udp.
> My questions are specific to UDP sockets.
>
> How do the socket rcvbuf and the otp rcvbuf relate to each other?
> The 'rcvbuf' with level = socket is the size of the OS level receive buffer.
> The 'rcvbuf' with level = otp is the size of the buffer "we" read into when we read data (with
> recv/recvfrom/recvmsg).
> If UDP MTU is 1500 bytes, what happens if the socket rcvbuf=MTU or rcvbuf=MTU*N?

The buffer should be large enough to hold the largest message you expect to receive.

> Should the otp rcvbuf be equal to the socket rcvbuf or larger? What's the difference?

The size of the socket:rcvbuf varies a bit with the platforms.
On my Linux box its 212992. Enough to hold several UDP messages.
There is no need to set the otp rcvbuf equal to or larger then
the socket:rcvbuf, since you only read one message at a time.
(Unless you connect and use recv, which I have not tested).

> What happen if the wrapper module doesn't read messages fast enough from the socket nif?

The OS buffers will (eventually) become full (and incoming messages will
be lost, I assume).

>
> Does sndbuf have any effect on UDP sockets?

Sure, but on linux its quite large (212992 on my Linux box).
If you write faster then the kernel can write, it will fill up.

> Should the wrapper module queue packets if the sndbuf is full and resend when possible or should it
> just drop packets?

Queue'ing will only lead to other problems. Much simpler to just
return the error code and leave it to the sender.

>
> What's the difference between recv, recvfrom, recvmsg and similarly send, sendmsg, sendto?

* recv is used to receive bytes.
* recvfrom and recvmsg is used to receive messages
* recvmsg is used when you need more control or need the
   control-related messages or miscellaneous ancillary data
   it can provide.
* recv is used by TCP (and connected UDP)
* recvfrom is used by UDP
* recvmsg is used by both TCP and UDP

>
> Is it relatively safe to use the socket module in production?

I think we have said that we intend for 'socket' to be
"officially official" with OTP 23. Until then we consider
it "experimental". The point of that is that we should be
able to change things if we need to.

But:
        *) we still do not support Windows.
        *) SCTP is untested.

Both of these may force us to alter the API.

> What should I be careful about when implementing the udp wrapper module?
>
> Thanks
>

/BMK