[erlang-questions] Best way to handle multiple gen_server

Chandru <>
Thu Feb 16 09:26:02 CET 2017


On 14 February 2017 at 17:13, Alex S. <> wrote:

>
> > 14 февр. 2017 г., в 20:06, Felipe Beline <>
> написал(а):
> >
> > Hi,
> >
> > My first question is: If I have a gen_server started by a Supervisor and
> it's handling a request (but has several others waiting in the queue), then
> it dies for some reason, and the supervisor restart it. Will the requests
> in the queue be lost?
> >
> > Other question is, if I want to create a process of this specific
> gen_server for each request that I have(then it should run in "parallel"
> several instances), but after each one finishes the execution and return
> the calculated value, I want to it to terminate himself. How should be the
> properly way to implement it?
> >
> > Another doubt is, let's  say that several thousands os request is made
> at same time, and it creates one instance of the server for each one,
> should it be "ok" :)? Or  should  I create a limited amount of servers and
> then distribute the requests over then? In this case the OTP pool should
> help me ?
> >
> > Cheers, Felipe
> The requests in queue will be lost, but your clients will receive an error
> and can retry.
>

To expand on this, your clients will receive an error only if they are
using gen_server:call. If they use gen_server:cast or directly send a
message to the gen_server using the '!' operator then there is no way to
know which messages the gen_server has processed and which have been lost.

regards,
Chandru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170216/4059e1d5/attachment.html>


More information about the erlang-questions mailing list