[erlang-questions] gproc and synchronous start of registred processes
Max Lapshin
max.lapshin@REDACTED
Mon Oct 31 13:32:21 CET 2011
Browser makes two requests: A, B.
Request A comes to http server and looks if there is
gproc:lookup_local_name(my_proc), it is undefined.
Request B comes to http server and looks if there is
gproc:lookup_local_name(my_proc), it is undefined.
Request A starts new process my_proc:start_link (lets call it
pid(0,100,0) ) and waits while its init returns
Request B starts new process my_proc:start_link (lets call it
pid(0,101,0) ) and waits while its init returns
pid(0,100,0): calls gproc:add_local_name(my_proc) and let process A
return with success
pid(0,101,0): calls gproc:add_local_name(my_proc) and fails with gproc error.
Request A returns with success
Request B returns with failure, but nothing bad has really happened on server.
Now lets speak more concrete. 5000 of flash clients are waiting for
live event beginning and all of them are rechecking if stream has
started.
While there is no stream, nothing bad is happening, because they are
making not more than 5000 of success requests per several seconds, it
is ok.
But when stream appears, only one will return with success, all other
will log 4999 failures into error log. Funny, really?
I've solved it with the following code:
Check for registered name outside of registrator process:
https://github.com/maxlapshin/game2/blob/master/src/game_tracker.erl#L44
and if no name found, ask registrator process for doing it:
https://github.com/maxlapshin/game2/blob/master/src/game_tracker.erl#L89
Question is: maybe I've missed something and there is something like:
gproc:add_local_name(my_proc, fun() ->
my_proc:start_link(..)
end),
which will do it synchronously?
More information about the erlang-questions
mailing list