Sharing a UDP socket between processes

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

Sharing a UDP socket between processes

Roger Lipscombe-2
I need to send fire-and-forget UDP messages to a particular
destination. I don't plan on receiving any incoming messages.

I need to be able to send messages from several thousand Erlang
processes. Ordinarily, I'd wrap the socket in a gen_server, but is
there really any need?

Can I simply stash the socket in an ETS table and use it directly?
What possible downsides are there to this?

Or would it be sensible to simply open/send/close a UDP socket each
time? Each process only needs to send a message at startup, and then
every 2 minutes or so. But: there will be several thousand of these
processes spawned at once.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|

Re: Sharing a UDP socket between processes

Dmitry Kolesnikov-2
Hello,


> On 22 Jun 2018, at 18.00, Roger Lipscombe <[hidden email]> wrote:
>
> I need to send fire-and-forget UDP messages to a particular
> destination. I don't plan on receiving any incoming messages.
>
> I need to be able to send messages from several thousand Erlang
> processes. Ordinarily, I'd wrap the socket in a gen_server, but is
> there really any need?

You should design system where resource ownership is explicitly managed.
gen_server is simply allows to build a fault tolerance solution.

>
> Can I simply stash the socket in an ETS table and use it directly?
> What possible downsides are there to this?

A single gen_server process is able to process over 80K messages per second before it
became a bottleneck. I would start with single process and start scanning on the needs.

Personally, I do not like usage of ETS as shared resources pool. I prefer to go with
Process pool(s) manages by supervisor(s). One process owns a resource (UDP socket) other
Child processes uses this resource. My reasoning simple here, supervisors helps you to
react on failures.

>
> Or would it be sensible to simply open/send/close a UDP socket each
> time? Each process only needs to send a message at startup, and then
> every 2 minutes or so. But: there will be several thousand of these
> processes spawned at once.

I would not recommend this option because single open / close causes resource allocation from kernel.
However, some monitoring solution uses this principle.

Best Regards,
Dmitry

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions

signature.asc (849 bytes) Download Attachment