[erlang-questions] pg2...a warning

Ulf Wiger <>
Fri Apr 30 00:21:18 CEST 2010

Evans, Matthew wrote:
> Thanks Ulf,
> Steve told mea bout your gproc work, It looks interesting.
> I actually ran into another pg2 strangeness today on another application.
> [...]

I have now shelved my idea of emulating pg2 on top of gproc.
It seems as if most people are attracted to the basic idea of pg2
much more than the exact semantics and the implementation.

I pushed a new version of gproc that works well in a distributed
setting. I will qualify that statement by saying that there is not
yet any test suite for the global registration part (we use QuickCheck
for the local part, and that still works).


It requires my own version of the hanssv+serge/gen_leader.erl,
as I found a bug in how gen_leader handled DOWN messages.


It would be great to have some more people take it for a spin
and report any bugs.

A simple process group implementation on top of gproc could look
like this (warning: mailing-list-quality code, not compiled):

-export([join/1, leave/1, get_members/1]).

join(Group) ->
    Key = key(Group),
    try gproc:reg(Key)  % fails if already registered
       error:badarg ->
          gproc:get_value(Key)  % fails if not already registered

leave(Group) ->

get_members(Group) ->

key(Group) ->
    {p,g,{?MODULE,Group}}. % a global property named {?MODULE,Group}

One problem with the above is that there is no check to see if
you misspelled the group name and ended up alone in a newly
created group. If your application uses hard-coded group names,
this is fairly easily addressed. Otherwise, some persistent table
of valid group names could be used to check against.

As stated before, gen_leader is a bit clumsy in environments where
nodes are dynamically added and removed. Changing the participants
of a gen_leader cluster is fairly difficult. The gen_leader_revival
project tries to merge a number of existing modifications to
gen_leader to make it more flexible.

Ulf W
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd



Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.


More information about the erlang-questions mailing list