[erlang-questions] Best way to handle multiple gen_server
Tue Feb 14 18:13:14 CET 2017
> 14 февр. 2017 г., в 20:06, Felipe Beline <> написал(а):
> 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.
As far as spawning short-lived tasks, I suggest looking into proc_lib and its start/init_ack capabilities. It unfortunately conceals a little bit of debugging info right now but that’ll be fixed in OTP 20.
I wouldn’t recommend `pool` module personally. Handling several thousand requests simultaneously should be no problem, but that of course depends on the nature of handling. I’d say if you cannot cache any data between requests, there’s no real point in pooling.
More information about the erlang-questions