[erlang-questions] Sending messages to multiple processes?

Davide Marquês nesrait@REDACTED
Fri May 1 14:53:28 CEST 2009


Hi again,

>From http://www.erlang.org/doc/man/pg.html:
"At the moment, all messages are serialized by sending them through a
group master process."

>From http://www.erlang.org/doc/man/pg2.html:
"There is no special functions for sending a message to the group.
Instead, client functions should be written with the functions
get_members/1 and get_local_members/1 to find out which processes are
members of the group. Then the message can be sent to one or more
members of the group."

In pg's case the messages pass through the group master process (so
that's an additional message being sent). But using pg2 you processes
are responsible for sending the actual messages and there is no
difference from the original "list of Pids" approach.
In both cases the added benefit comes from separating the group
membership information (no longer an "implicit" list of Pids but
something updatable through a well defined interface).

Using process groups in Kevin's problem isn't a very good idea because
he doesn't really need to dynamically add/remove workers. I just
mentioned pg and pg2 because of the "sending a single message to
multiple processes" bit.

:Davide

On Fri, May 1, 2009 at 4:01 AM, G.S. <corticalcomputer@REDACTED> wrote:
>
> Is the broadcasting of msgs using pg or pg2 faster than simply having a list of pids and looping through them?
>
> 2009/4/30 Davide Marquês <nesrait@REDACTED>
>>
>> Hi Kevin,
>>
>>> Is there a neato idiom for sending a single message to multiple
>>> processes, up to say 200, or do I just need to loop it?
>>
>> No "idiom" that I'm aware of.
>> You can use the pg module to group a bunch of processes together and
>> send them messages via the group name. Info:
>> http://www.erlang.org/doc/man/pg.html
>> http://erlang.org/doc/man/pg2.html
>>
>>> I also need to know they finished processing the message.  Is this the
>>> wrong road to go down?
>>
>> That's just a matter of sending the "master process" Pid to the
>> workers/slaves when they are started and having then report back when
>> they're done.
>>
>>>
>>> Basically I'm starting 200 processes, reading in a single file, and each
>>> process is fed the same line of the file one by one until the end, but
>>> they all handle it differently, and when they have finished all the
>>> lines, they spit out a modified file, and return a value to indicate
>>> they are finished.
>>
>> For this simple case you can stick to your own master/slave processes. :)
>>
>>>
>>> Thanks for any advice,
>>> Kevin
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list