Last active
December 22, 2015 16:08
-
-
Save huseyinyilmaz/6497054 to your computer and use it in GitHub Desktop.
Tested if erlang can handle to open 10 million concurent erlang processes and close them.
(It does not work in 32bit compilations because of 4GB limit.)
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
%%%------------------------------------------------------------------- | |
%%% @author Huseyin Yilmaz <huseyin@saturn.local> | |
%%% @copyright (C) 2013, Huseyin Yilmaz | |
%%% @doc | |
%%% | |
%%% @end | |
%%% Created : 9 Sep 2013 by Huseyin Yilmaz <huseyin@saturn.local> | |
%%%------------------------------------------------------------------- | |
-module(test). | |
%% API | |
-export([test/0, test_process/0, start_process/1, start_processes/3]). | |
start_process(Pid)-> | |
receive | |
die -> Pid ! died; | |
_ -> start_process(Pid) | |
end. | |
start_processes(Count,Count, Pid_list) -> Pid_list; | |
start_processes(Current, Count, Pid_list) -> | |
case Current rem 100000 of | |
0 -> io:format("~w th process created.~n",[Current]); | |
_ -> ok | |
end, | |
start_processes(Current+1, Count, [spawn(test, start_process,[self()]) | Pid_list]). | |
kill_processes(_Count, []) -> ok; | |
kill_processes(Count, [Pid|Pid_list]) -> | |
case Count rem 100000 of | |
0 -> io:format("~w th process has been killed.~n",[Count]); | |
_ -> ok | |
end, | |
Pid ! die, | |
receive | |
died -> ok | |
end, | |
kill_processes(Count - 1, Pid_list). | |
test_process()-> | |
Pid_list = start_processes(1, 10000000, []), | |
io:format("process creation completed~n", []), | |
%% io:format("Total number of processes = ~w~n", [length(processes())]), | |
kill_processes(length(Pid_list), Pid_list), | |
io:format("process killing completed~n", []). | |
test()-> | |
spawn(test, test_process, []). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment