How fast can Erlang send messages?

By: on September 10, 2006

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:

-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
Stop = erlang:now(),
N / time_diff(Start, Stop).

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

%% code omitted – see previous post



  1. matthew says:

    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. tonyg says:

    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. Roberto says:

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


  4. tonyg says:

    Roberto, thank you — that is very interesting.

  5. testing says:

    per second or per minute??

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>