two gen_udp questions

Jim Morris wolfmanjm@REDACTED
Sat Aug 8 21:59:18 CEST 2009


>
> o.k., can't there be a race condition, if multiple threads want to send data
> over the socket?

The UDP protocol does not guarantee packets are delivered in order, so
this should not be a concern, as the only side effect of several
processes sending data to the UDP socket would be them being out of
order.

However if you send all the UDP packets to a single process to send
them back and there are a lot of clients and/or packets you could
cause that process to get backed up, increasing the latency on the
packets and having the process message queue grow.
I have found it is better to have several processes send the reply
back to the same UDP socket, thereby distributing that load. The
downside is the processes have to be from the same VM so can't be
distributed over several servers (as the socket can only be shared by
the same VM).

Also note that when you do reply to a UDP packet to a client that is
behind a residential type NAT router/firewall the UDP packet generally
needs to come back from the same IP address and port to get through
the firewall/NAT device. Google STUN clients for more info.


More information about the erlang-questions mailing list