[erlang-questions] performance vs msg queue length

Fred Hebert mononcqc@REDACTED
Tue Apr 20 21:09:38 CEST 2010


On Tue, Apr 20, 2010 at 2:41 PM, John Erickson <jderick@REDACTED> wrote:

> Good to know about mnesia and gen_server doing selective receives, but I am
> not using either.  BTW, I found some other evidence of this slowdown from
> an
> earlier posting.  Although the main post was about interpreter speed, I
> found these benchmark numbers quite strange for the compiled version as
> well.  With message queues of 10k, it looks like about 3x slowdown.
>
> [begin [ self() ! a || _ <- lists:seq(1,N) ],
> >        S = now(),
> >        [ receive _ -> ok end || _ <- lists:seq(1,N) ],
> >        io:format("~w~n", [timer:now_diff(now(), S) / N])
> >  end || N <- [1,10,100,1000,10000]].
> >
> > ...
> >
> > If I put it into a module, add 1e5 and 1e6 then I get:
> >
> > 1> test:test().
> > 1.0
> > 0.1
> > 0.06
> > 0.114
> > 0.1554
> > 0.36398
> > 0.358997
> >
>
>
I've ran your benchmark:

1.0
0.2
0.1
0.15
0.1913
0.31713


I've then reworked your benchmark, this time starting a new process for each
one and adding a 100k messages round:

[spawn(fun() -> [ self() ! a || _ <- lists:seq(1,N) ],
        S = now(),
        [ receive _ -> ok end || _ <- lists:seq(1,N) ],
        io:format("~w: ~w~n", [N,timer:now_diff(now(), S) / N])
  end) || N <- [1,10,100,1000,10000,100000]].

If I reorder everything it outputs:

1: 1.0
10: 0.2
100: 0.18
1000: 0.173
10000: 0.1922
100000: 0.18945

In this case, the results are much more consistent and show no trace of
degradation when adding messages. Someone who knows the innards of the VM
better than me could explain, but it looks like running your test
sequentially messes the results up.


More information about the erlang-questions mailing list