所以在Joe Armstrongs声称erlang进程很便宜并且vm可以处理数百万个之后.我决定在我的机器上测试它:
process_galore(N)->
io:format("process limit: ~p~n", [erlang:system_info(process_limit)]),
statistics(runtime),
statistics(wall_clock),
L = for(0, N, fun()-> spawn(fun() -> wait() end) end),
{_, Rt} = statistics(runtime),
{_, Wt} = statistics(wall_clock),
lists:foreach(fun(Pid)-> Pid ! die end, L),
io:format("Processes created: ~p~n
Run time ms: ~p~n
Wall time ms: ~p~n
Average run time: ~p microseconds!~n", [N, Rt, Wt, (Rt/N)*1000]).
wait()->
receive die ->
done
end.
for(N, N, _)->
[];
for(I, N, Fun) when I < N ->
[Fun()|for(I+1, N, Fun)].
Run Code Online (Sandbox Code Playgroud)
对于百万个流程来说,结果令人印象深刻 - 我得到6.6微米的aprox!秒平均产卵时间.但是当启动3m进程时,OS shell打印出的"Killed"与erlang运行时一样.我使用+ P 5000000标志运行erl,系统是:使用quadcore i7和8GB ram的arch linux.