Why is gen_server:call/1 so slow (3s) when used with {global, Name}?

Sergey Samokhin prikrutil@REDACTED
Thu Jun 18 23:19:45 CEST 2009


Hello!

The first call to gen_server involving global name resolving
facilities is quite slow: it's about 3 sec. Is there something I can
do with this?

To see what I'm talking about open a brand new erl shell with -sname
set to smth meaningful and then call srv:start().

Sources of both srv and tst modules are attached to this letter. They
are also available here: http://gist.github.com/132154

srv is a globally registered gen_server which responds to 'ping' calls
by writing 'pong' to the terminal.

$ erl -sname a
Eshell V5.7.1  (abort with ^G)
(a@REDACTED)1> srv:start().
{ok,<0.53.0>}

tst is an another gen_server which calls gen_server:call({global,
srv}, ping) to ping srv.

$ erl -sname b
Eshell V5.7.1  (abort with ^G)
(b@REDACTED)1> tst:start(a@REDACTED).
# 2971.645 ms.
{ok,<0.41.0>}

Yes, 3 seconds for the first call isn't something I should care about,
but it makes init of my gen_servers much slower :(

To make sure that it isn't a kind of black magic, I've reproduced this
behaviour some times on two separated computers; but I'm not sure if
it's a bug.

I'm using Erlang R13B.

Thanks.

--
Sergey Samokhin


More information about the erlang-questions mailing list