[erlang-questions] gen_udp:send blocks?

Valentin Micic v@REDACTED
Fri Sep 7 15:23:22 CEST 2018


On 07 Sep 2018, at 3:00 PM, Roger Lipscombe wrote:

> On 7 September 2018 at 12:37, Valentin Micic <v@REDACTED> wrote:
>> On 07 Sep 2018, at 12:11 PM, Roger Lipscombe wrote:
>>> My question is more about understanding the semantics of gen_udp:send:
>>> why is it blocking? If the buffer was full, I'd expect it to discard
>>> the message and return immediately.
>> 
>> UDP should behave the way you expected. May I ask if the caller of gen_udp:send is the owner (e.g. creator) of the socket?
> 
> Yes it is. I call gen_udp:open in Module:init/1, and gen_udp:send in
> Module:handle_cast/2.
> 
> Oh. Here's a thought: we use a hostname as the destination in
> gen_udp:send. Could that be causing blocking?

Well, if the name resolution is slow (e.g. you use some remote DNS server), this may cause some delay, but, as far as I know, local OS resolver would cache the name once it has been resolved.
HOWEVER, if that delay caused gen_server message process queue to build up due to constant incoming traffic, than all bets are off --  when this number grows above hundred, this may cause the whole run-time to underperform, which puts more pressure one the gen_server's process message queue and so on. This could explain the behavior you observed.
There's an easy way to check this -- just check the process message queue length for your gen_server (or any other process to that end), and you'll know :-)

V/







More information about the erlang-questions mailing list