[erlang-questions] pg2 vs gproc?
Eric Moritz
eric@REDACTED
Wed Jun 6 14:50:53 CEST 2012
Yes, if you register a property key, you can retrieve all the procs that
have that property set. For instance a fanout pub/sub can be accomplished
doing:
subscribe(Channel) ->
gproc:reg({p, l, {subscribers,
Channel}}).
publish(Channel, Msg) ->
gproc:send({p, l, {subscribers,
Channel}},
Msg).
If a process calls publish/2, the message will be sent to every process
that called subscribe/1.
I'm on my phone so it's a bit hard to look up the details, if you want to
get a list of pids that called subscribe, look at the code of
gproc:send/2. I think the function is called lookup_pids/1 but I may be
wrong.
The etorrent project uses gproc. That's a good read if you want to see how
to use gproc. He uses property keys for each torrent file process as well
as using await to delay initialization of gen_servers that depend on other
gen_servers.
Eric Moritz.
On Jun 6, 2012 8:27 AM, "Loïc Hoguin" <essen@REDACTED> wrote:
> On 05/26/2012 10:38 PM, Motiejus Jakštys wrote:
>
>> Hi,
>>
>
> Hello,
>
> For term() to pid() mapping I've always used gproc. For the same thing
>> my coworker always used pg2.
>>
>> I am making a comparison now. There are some features in gproc which are
>> not in pg2:
>>
>> * Await for registration
>> * Per-process properties
>> * Aggregate counters
>> * QLC
>>
>> Whereas pg2 "natively" supports mapping one key to several processes
>> (which can be easily achieved with QLC in gproc).
>>
>
> Unless I misunderstand, gproc's properties are exactly this, mapping one
> key to several processes.
>
> --
> Loïc Hoguin
> Erlang Cowboy
> Nine Nines
> ______________________________**_________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/**listinfo/erlang-questions<http://erlang.org/mailman/listinfo/erlang-questions>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120606/688b67b5/attachment.htm>
More information about the erlang-questions
mailing list