[erlang-questions] pg2...a warning

Ulf Wiger ulf.wiger@REDACTED
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).

http://github.com/uwiger/gproc/

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

http://github.com/uwiger/gen_leader_revival/commit/e682e979ebade10b61d35f37b85e2f7b6a953af2

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):

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

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

leave(Group) ->
    gproc:unreg(key(Group)).

get_members(Group) ->
    gproc:lookup_pids(key(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.

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

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

www.erlang-solutions.com



More information about the erlang-questions mailing list