technology from back to front

How fast can Erlang send messages?

My previous post examined Erlang’s speed of process setup and teardown. Here I’m looking at how quickly messages can be sent and received within a single Erlang node. Roughly speaking, I’m seeing 3.4 million deliveries per second one-way, and 1.4 million roundtrips per second (2.8 million deliveries per second) in a ping-pong setup in the same environment as previously – a 2.8GHz Pentium 4 with 1MB cache.

Here’s the code I’m using – time_diff and dotimes aren’t shown, because they’re the same as the code in the previous post:

-module(ipctest).
-export([oneway/0, consumer/0, pingpong/0]).

oneway() ->
N = 10000000,
Pid = spawn(ipctest, consumer, []),
Start = erlang:now(),
dotimes(N – 1, fun () -> Pid ! message end),
Pid ! {done, self()},
receive ok -> ok end,
Stop = erlang:now(),
N / time_diff(Start, Stop).

pingpong() ->
N = 10000000,
Pid = spawn(ipctest, consumer, []),
Start = erlang:now(),
Message = {ping, self()},
dotimes(N, fun () ->
Pid ! Message,
receive pong -> ok end
end),
Stop = erlang:now(),
N / time_diff(Start, Stop).

consumer() ->
receive
message -> consumer();
{done, Pid} -> Pid ! ok;
{ping, Pid} ->
Pid ! pong,
consumer()
end.

%% code omitted – see previous post

by
tonyg
on
10/09/06
  1. funs are more expensive to invoke than normal module methods. Can you try this without using dotimes – make the fun a normal recursive method?

  2. Removing dotimes for oneway produced a speed boost of about 10% – but doing the same for pingpong scarcely affected the speed at all. If anything, it ran slightly slower. It’s possible that the extra arguments to the helper procedure (Count, Pid, Message) for the non-dotimes pingpong costs more than the overhead of using a fun for the dotimes pingpong. The fun can close over (Pid, Message) once, avoiding the need to pass the parameters around.

  3. different benchmark approach than yours, but would like to hear your opinion on this, if you feel so:

    http://www.ostinelli.net/boost-message-passing-between-erlang-nodes/

    r.

  4. Roberto, thank you — that is very interesting.

  5. testing
    on 19/09/09 at 8:57 am

    per second or per minute??

  6. [...] ?????? Roughly speaking, I’m seeing 3.4 million deliveries per second one-way, and 1.4 million [...]

 
 


4 × = twenty four

2000-14 LShift Ltd, 1st Floor, Hoxton Point, 6 Rufus Street, London, N1 6PE, UK+44 (0)20 7729 7060   Contact us