On Sat, May 26, 2012 at 10:38 PM, Motiejus Jakštys
<desir...@gmail.com> wrote:
> Hi,
>
> 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).
>
> Any more differences between them?
--
Motiejus Jakštys
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 06/06/2012 05:10 AM, Motiejus Jakštys wrote:
> Bump
>
> On Sat, May 26, 2012 at 10:38 PM, Motiejus Jakštys
> <desir...@gmail.com> wrote:
>> Hi,
>>
>> 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).
>>
>> Any more differences between them?
Awesome, cannot wait to try it out. :)