[erlang-questions] OTP process startup vs spawn overhead

Ulf Wiger ulf.wiger@REDACTED
Thu Jul 28 12:37:36 CEST 2011


Are you running that expression from the shell?

If so, one big difference between the two will be how much is interpreted vs compiled code. Specifically, that the fun in the second test is interpreted, whereas the receive loop in the gen_server is compiled.

BR,
Ulf W

On 28 Jul 2011, at 12:00, Heinrich Venter wrote:

> In an attempt to prove that spinning up OTP processes as workers does
> not incur that much overhead I have done the following with results
> that are confusing me a bit.
> 
> [ timer:tc(fun() -> [ Pid ! ok || {ok, Pid} <-
> [test_gen:start_link()|| _ <- lists:seq(1,10000)] ] end) || _ <-
> lists:seq(1,10)].
> 
> [ timer:tc(fun() -> [ Pid ! ok || Pid <- [spawn_link(fun() -> receive
> _ -> ok end end) || _ <- lists:seq(1,10000)] ] end) || _ <-
> lists:seq(1,10)].
> 
> 
> First start 10,000 gen_server with a very simple handle_info that
> shuts down the process when it receives anything.  Do this 10 times
> measuring the times for each just to get a bit of smoothing.
> Then do the same with spawn_link.  The idea is that we can compare the
> times and see how much overhead we have for OTP.
> 
> The problem is that the spawn_link version takes 4 times LONGER to
> execute!  The issue has to be with the way I do the spawn.
> Can any one please shed some light on this?
> 
> -]-[einrich
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com






More information about the erlang-questions mailing list