Created
August 28, 2012 22:47
-
-
Save hnakamur/3505035 to your computer and use it in GitHub Desktop.
1M process creation in Erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module(processes). | |
-export([max/1]). | |
%% max(N) | |
%% create N processes then destroy them | |
%% See how much time this takes | |
max(N) -> | |
Max = erlang:system_info(process_limit), | |
io:format("Maximum allowed processes:~p~n", [Max]), | |
statistics(wall_clock), | |
L = for(1, N, fun() -> spawn(fun() -> wait() end) end), | |
{_, Time} = statistics(wall_clock), | |
lists:foreach(fun(Pid) -> Pid ! die end, L), io:format("Elapsed time=~p seconds~n", [Time / 1000.0]). | |
wait() -> | |
receive | |
die -> void | |
end. | |
for(N, N, F) -> [F()]; | |
for(I, N, F) -> [F()|for(I+1, N, F)]. | |
%% Results on Macbook Pro Retina 2012 | |
%% CPU: Intel Core i7 2.6 GHz | |
%% Mem: 16GB 1600 MHz DDR3 | |
%% | |
%% sh-3.2$ erl +P 2000000 | |
%% Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:8:8] [async-threads:0] [hipe] [kernel-poll:false] [dtrace] | |
%% | |
%% Eshell V5.9.1 (abort with ^G) | |
%% 1> c(processes). | |
%% {ok,processes} | |
%% 2> processes:max(50000). | |
%% Maximum allowed processes:2000000 | |
%% Elapsed time=0.135 seconds | |
%% ok | |
%% 3> processes:max(100000). | |
%% Maximum allowed processes:2000000 | |
%% Elapsed time=0.282 seconds | |
%% ok | |
%% 4> processes:max(200000). | |
%% Maximum allowed processes:2000000 | |
%% Elapsed time=0.535 seconds | |
%% ok | |
%% 5> processes:max(500000). | |
%% Maximum allowed processes:2000000 | |
%% Elapsed time=1.444 seconds | |
%% ok | |
%% 6> processes:max(1000000). | |
%% Maximum allowed processes:2000000 | |
%% Elapsed time=3.123 seconds | |
%% ok | |
%% 7> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment