[erlang-questions] conditional pub-sub in gproc

Motiejus Jakštys <>
Sun Jun 17 09:45:17 CEST 2012


On Sat, Jun 16, 2012 at 10:15:54PM -0700, Ulf Wiger wrote:
> 
> Gproc does support mnesia-based storage for gproc:get_env().
> 
> https://github.com/esl/gproc/blob/master/doc/gproc.md#get_env4
> 
> However, as a replacement for gen_leader, mnesia, unfortunately
> doesn't handle netsplits all that well either*. :)
> 
> It wouldn't be all that difficult to modify gproc to use something other
> than gen_leader, but demand for a mnesia-based gproc hasn't
> exactly been high so far...

Well, I am just about to write something like this. Use case:
* need a (global) mapping from Gid::binary() to Pid::pid(). Every time
  application wants to send something to Gid, it does a lookup.
* if a process crashes, a new one is spawned on monitoring node.
* the spawned process registers itself with the Gid.
* in case of netsplit, we have two processes with the same key. Damn.
* during netsplit, application will be querying Gid to Pid. Only one of
  the Gids will be returned. We cache somewhere, which one (more on this
  later).
* when nodes are back together, we must decide which process should live or die.
* in my case the process which Pid was returned more recently wins (at
  least for the 0.1 version). Then let the other process know that it should
  kill itself.

So.. Gproc with ways to resolve netsplit is definitely a match here.

I am not yet sure how would I keep the "most recent lookup" (probably
dirty_write the timestamp on every lookup, but I will have to think more
about it). Though gproc counters look not too half-bad here, as well.
More ideas welcome. :)

Oh, and if we (Spil Games) choose to use it in production, we would test
The Gproc With The Mnesia, thoroughly.

The whole thing I am building will be open sourced and quite useful IMO,
but it's just too early yet to announce it yet (v0.1 on the way).

Wild cheers and enthusiasm! ;-)

Regards,
Motiejus Jakštys



More information about the erlang-questions mailing list