[erlang-questions] UDP buffers and packet loss

Raimo Niskanen raimo+erlang-questions@REDACTED
Mon Nov 21 10:30:07 CET 2016


On Mon, Nov 21, 2016 at 10:49:12AM +0200, pablo platt wrote:
> @Raimo, I'll try increasing read_packets.
> How does increasing read_packets work compared to increasing recbuf?
> Both have the same effect only read_packets keep unhanded packets as Erlang
> messages while recbuf keep them as raw data?

I would not say they have the same effect.

The kernel puts packets in your receive buffer and when it overflows it
drops packets.  The reason that it overflows is either that the packets are
too large or that your application does not read them fast enough, or both.

Your application has to manage both a continous flow of packets and a
certain amount of load spikes, where load spikes can be either due to a
temporarily high packet rate or due to large packets.

A large receive buffer size helps you to handle large packets or
temporarily high packet rates at the expense of memory for the socket.

There are also kernel parameters for system UDP buffers that can be
increased so the kernel does not drop packets even before sorting
them to the right socket.

A large read_packets helps you handle a high packet rate at the expense of
executing erlang code slower.  So if you set read_packets to high you will
not drop packets, but the erlang node will choke under the packet rate,
maybe by running out of memory for the unprocessed packets.


> 
> Do you have a suggestion how to check the effect of increasing it?
> How do I know if UDP packets where dropped on the network or on the buffer
> because my Erlang process didn't process them fast enough?

I am sorry I do not know exactly how to read proper statistics for this...

If you increase read_packets and see smaller packet loss it that is fine.
But if you increase it more and do not see smaller packet loss then it is
high enough for this load case.  If you can chooke the node with UDP
packets then you have increased it too much. :-)

> 
> @Andreas
> How did you compare gen_socket with gen_udp?
> Before going the nif way, I want to be sure that it improves my throughput.
> Why a nif can handle more UDP packets than gen_udp? I thought that the
> Erlang code should be the bottleneck in both cases.
> 
> 
> On Mon, Nov 21, 2016 at 10:29 AM, Andreas Schultz <aschultz@REDACTED> wrote:
> 
> > On 11/19/2016 08:51 PM, Max Lapshin wrote:
> >
> >> ah, it is receive?
> >>
> >> We had to write special port driver to receive 500 mbit/s of UDP video
> >> multicast
> >>
> >
> > With [1] I'm able to forward (receive and send) 500mbit/s on a single
> > core. The
> > interface itself is a port driver combined with a nif and works only on
> > Linux
> > (and maybe OSX), but the actual forwarding code is pure Erlang [2].
> >
> > Andreas
> >
> > [1]: https://github.com/travelping/gen_socket
> > [2]: https://github.com/travelping/gtp_u_edp/blob/master/src/gtp_
> > u_edp_forwarder.erl
> >

> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list