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

Dowse, Malcolm malcolm@REDACTED
Mon Jun 22 20:24:51 CEST 2009


Hi,

(It looks like my original response didn't make it to the list. It can
be found below.)

I don't know if you need to send a mail to the bugs mailing list.

Anyway, the problem looked fairly simple to solve, and so I've attached
a patch for global.erl in R13B01 which appears to fix the problem. If
OTP are happy and think it's a worthwhile change, perhaps they can
include it in a later Erlang release.

Cheers,

Malcolm

"""
Hi,

I played around with your example a bit. If you put a 'timer:sleep(1)'
just after 'global:sync()' then the problem goes away.. or at least it
does for me.

Looking at the global.erl, it seems that some sort of low-level global
lock is set on all nodes during, and shortly after, a call to
global:sync/0. If you do a global whereis query when this lock is still
set (ie. by calling a globally registered gen_server), it waits a random
interval between 0 and 4 seconds and then tries again. See the call
'random_sleep(5)' in global.erl.

The comments in the code suggests that some sort of exponential backoff
should instead be done. So it's quite possible that this is a bug.

all the best,

malcolm
"""

-----Original Message-----
From: Sergey Samokhin [mailto:prikrutil@REDACTED] 
Sent: 20 June 2009 18:27
To: Dowse, Malcolm
Cc: erlang-questions@REDACTED
Subject: Re: [erlang-questions] Why is gen_server:call/1 so slow (3s)
when used with {global, Name}?

Hi!

> I played around with your example a bit. If you put a 'timer:sleep(1)'
just
> after 'global:sync()' then the problem goes away.. or at least it does
for
> me.

Adding 'time:sleep(1)' has made init/1 so fast as I wanted it to be,
thanks!

> The comments in the code suggests that some sort of exponential
backoff
> should instead be done. So it's quite possible that this is a bug.

Should I forward this thread to erlang-bugs mailing list?

-- 
Sergey Samokhin


More information about the erlang-questions mailing list