[erlang-questions] Erlang Message passing questions
Dave Smith
dizzyd@REDACTED
Tue Jun 2 19:08:31 CEST 2009
On Tue, Jun 2, 2009 at 10:43 AM, Greg Perry<Greg.Perry@REDACTED> wrote:
>
> Does this present problems from a performance perspective, ie in a high
> performance environment would it make more sense to start a collection
> of processes, have those processes "do something" and then eventually
> return with their result?
As with most high volume situations the answer is "it depends".
Personally, if I was doing something where I had a ton of (similar)
processes doing some calculation, I would plunk them all under a
supervisor and setup a monitor on each of them from the controller
process. Then they notify the controller process when they are done
running, or worst case, the controller gets a notification that they
have died and can choose what to do next. Basically this is the star
topology you were describing, with the addition of monitors for
failure detection.
As for the callback to the controller, I would suggest just using a
normal message (or if you're in OTP, gen_server:call/2, etc.).
> Also, based upon the immutability of Erlang how are iterative functions
> accomplished such as counter incrementing?
Immutability is dealt with in a general fashion by tracking state
outside of a function. I.e. you loop in a function, passing in the
most recent state each time. For example:
do_something(0) ->
all_done;
do_something(Counter) ->
do_x(),
do_something(Counter-1).
D.
More information about the erlang-questions
mailing list