[erlang-questions] Concurrent Processes and the Programming Erlang book

Camille Troillard tuscland@REDACTED
Tue Apr 7 01:07:40 CEST 2009


The Programming Erlang book has a nice exercise at section 8.11.  I'm
sure this problem must have been solved a billion times before, so I
won't go too much into the details.

"Write a ring benchmark. Create N processes in a ring. Send a message
round the ring M times so that a total of N * M messages get sent.
Time how long this takes for different values of N and M."

Although it is written in the "Concurrent Programming" chapter, I
wondered if this problem was really concurrent after all:  the
messages are sent to a ring of N processes, but it is not stated that
shall be sent in parallel.  So I decided to write a parallel version
of this.
Attached is an erlang module that will spawn a ring of N processes and
send a total of M messages through it (that is N times N/M messages).
To use it:

rb:start(10, 10000).

Will send 1000 messages 10 times in a 10 process ring.  The result is
a tuple containing timing informations.

The results I have found are interesting in that it shows that Erlang
starts to span the processing on multiple cores starting at 30
processes.  At this point, efficiency drops in favor of
multiprocessing gaining efficiency back up to 1000 parallel processes.

Also attached is a graph showing the time spent to send one message
for a MacBook Pro (2 cores), a MacPro (4 cores) and a small Lenovo
Ideapad S10 (2 cores) under Windows, which to my great surprise
compares pretty well to the two former competitors.  The comparison
between each computer is indeed flawed for many reasons, but the shape
of the graphs is interesting.

I would be happy to know your feedback about the code, and please let
me know if there is something wrong in my interpretation.

Best Regards,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rb.erl
Type: application/octet-stream
Size: 4057 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090407/1ce97506/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Ring Bench Graph.png
Type: image/png
Size: 100422 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090407/1ce97506/attachment.png>

More information about the erlang-questions mailing list