[erlang-questions] performance vs msg queue length
Tue Apr 20 21:09:38 CEST 2010
On Tue, Apr 20, 2010 at 2:41 PM, John Erickson <> 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
> 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:
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:
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