Gen_server and multiple processes
Thu Dec 19 11:02:55 CET 2002
>I would like to know if the gen_server behavior creates a separate
>process for each message
Each generic server is a process, and calls and casts to it are just
sent as messages. If you want a process to handle every incoming
message, you will have to create dynamic children (1 server for every
>In other words, if several calls to the function foo() is made, will
>there be several processes each running handle_call spawned, or will
>there be several queued calls to handle_call?
The messages will be queued.
>It seems that playing to Erlangs strengths in this situation makes the
>most sense :) Would spawning a process to handle foo and returning
>immediately might be the correct way to do this type of thing? (if
>gen_server does not do it already).
Not really. It depends on how heavy the operations are (How long will
the wait for the other messages in the queue are), how many incoming
messages you will expect (eg. will the server be a bottle neck), and if
you expect a reply or not (Should the calls be synchronous or
asynchronous), will the change of state in your server affect the
various calls, and if the order in which the requests are handled will
affect other requests.
Maybe if you describe your problem in more detail, we can lead you in
the right direction. Generalizing, and knowing little about your
problem, my first attempt would be to solve the problem with one gen
server and see if it works. If the load on it is too heavy, the step to
a server per request is not that big.
More information about the erlang-questions