[erlang-questions] OTP process startup vs spawn overhead

Heinrich Venter hfventer@REDACTED
Thu Jul 28 12:00:20 CEST 2011


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



More information about the erlang-questions mailing list