[erlang-questions] How does gproc register global names?

31 views
Skip to first unread message

Pablo Platt

unread,
Oct 26, 2010, 9:48:29 AM10/26/10
to erlang-q...@erlang.org
Hi

I'm using gproc to register local names and properties.
I've read that gen_leader is needed to use gproc in the global scope.

How does the data get synced across all nodes?
Why isn't mnesia being used for that?
How do you solve race conditions and failures?

Thanks

Ulf Wiger

unread,
Oct 26, 2010, 11:31:24 AM10/26/10
to Pablo Platt, erlang-q...@erlang.org

It is correct that gproc uses gen_leader.
All registration reguests are passed on to the leader process,
and it broadcasts the results to the other candidates & workers.
Monitoring of registered processes is done by the local gproc
instance.

When a new leader is elected, it sends its list of registered names
to the others; if they happen to have names that the new leader
doesn't know about, they will send them to the new leader.

This is not terribly unlike how global does things, although it uses
a multicall mechanism to handle atomicity. In measurements that
I've made, the gproc method is much more efficient.

OTOH, global has facilities to handle partitioned networks. Gproc
doesn't... yet.

Using mnesia would not give better consistency, unless transactions
are used - but that would kill performance. And there are no persistency
reasons to use it either. Gproc uses ets tables, which are rigged to survive
even if the gproc process dies; the restarted gproc scans the table and
sets new monitors.

BR,
Ulf W

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com


________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questio...@erlang.org

Pablo Platt

unread,
Oct 26, 2010, 12:49:26 PM10/26/10
to Ulf Wiger, erlang-q...@erlang.org
Why doesn't mnesia have a 'light weight' transaction that works like gproc?

When a new leader is elected, how does other nodes knows which names it doesn't
know about?

I'm using gproc to register gen_server processes.
It might be useful to have gproc:cast and gproc:call that use gen_server:cast
and gen_server:call in addition to gproc:send.

Is it possible to count all registered processes without using a counter?

Is it possible to page thorough all registered processes?

Thanks


________________________________
From: Ulf Wiger <ulf....@erlang-solutions.com>
To: Pablo Platt <pablo...@yahoo.com>
Cc: erlang-q...@erlang.org
Sent: Tue, October 26, 2010 5:31:24 PM
Subject: Re: [erlang-questions] How does gproc register global names?

Ulf Wiger

unread,
Oct 26, 2010, 1:27:45 PM10/26/10
to Pablo Platt, erlang-q...@erlang.org

On 26 Oct 2010, at 18:49, Pablo Platt wrote:

> Why doesn't mnesia have a 'light weight' transaction that works like gproc?

Mnesia has a slightly different charter, ensuring consistent persistency.


> When a new leader is elected, how does other nodes knows which names it doesn't know about?

In the Mod:elected() callback, the newly elected leader can
pass data to the others, which they receive in Mod:surrender().

> I'm using gproc to register gen_server processes.
> It might be useful to have gproc:cast and gproc:call that use gen_server:cast and gen_server:call in addition to gproc:send.

True, but my idea was that OTP integrate gproc and make gen.erl
aware of gproc-registered names. :)

> Is it possible to count all registered processes without using a counter?

It would be possible if the function gproc:pattern/2 were exported, or
a function gproc:select_count/2 were added, similar to select/2 et all,
which are already there.

> Is it possible to page thorough all registered processes?

Yes, with either QLC (using gproc:table/1) or using gproc:select/3 (using
the Limit argument to fetch a give number of objects at a time.

BR,
Ulf W


>
> Thanks

Pablo Platt

unread,
Oct 26, 2010, 6:58:19 PM10/26/10
to Ulf Wiger, erlang-q...@erlang.org
> True, but my idea was that OTP integrate gproc and make gen.erl
> aware of gproc-registered names. :)

Why doesn't OTP integrate gproc?
It is already used and tested by several people.
The code and api are very good.

Can someone from the Erlang team pick up the glove?


________________________________

Sent: Tue, October 26, 2010 7:27:45 PM

Pablo Platt

unread,
Oct 26, 2010, 6:54:58 PM10/26/10
to Ulf Wiger, erlang-q...@erlang.org
Thank you for the answer.

________________________________

Sent: Tue, October 26, 2010 7:27:45 PM

Reply all
Reply to author
Forward
0 new messages