memory - Erlang change VM process initial size. Tune Erlang VM -
first have mention run on centos 7 tuned support 1 million connections. tested simple c server , client , connected 512000 clients. have connect more did not have enought ram spawn more linux client machines, since machine can open 65536 connections; 8 machines * 64000 connections each = 512000.
i made simple erlang server want connect 1 million or half million clients, using same c client. problem i'm having memory related. each gen_tcp:accept call spawn process. around 50000 open connections costs me 3.7 gb ram on server, meanwhile using c server have open 512000 connections using 1.9 gb ram. true on c server did not created process after accept handle stuff, called accept again in while loop, so... guys on web did erlang thing less memory ( ejabberd riak )
i presume flags pass erlang vm should trick. read in documentation , on web have: erl +k true +q 64200 +p 134217727 -env erl_max_ports 40960000 -env erts_max_ports 40960000 +a 16 +hms 1024 +hmbs 1024
this server code, open 1 listener monitors port 5001 calling start(1, 5001).
start(num,lport) -> case gen_tcp:listen(lport,[{reuseaddr, true},{backlog,9000000000}]) of {ok, listensock} -> start_servers(num,listensock), {ok, port} = inet:port(listensock), port; {error,reason} -> {error,reason} end. start_servers(0,_) -> ok; start_servers(num,ls) -> spawn(?module,server,[ls,0]), start_servers(num-1,ls). server(ls, nr) -> io:format("before accept ~w~n",[nr]), case gen_tcp:accept(ls) of {ok,s} -> io:format("after accept ~w~n",[nr]), spawn(ex,server,[ls,nr+1]), proc_lib:hibernate(?module, loop, [s]); other -> io:format("accept returned ~w - goodbye!~n",[other]), ok end. loop(s) -> ok = inet:setopts(s,[{active,once}]), receive {tcp,s, _data} -> answer = 1, % not implemented in example gen_tcp:send(s,answer), proc_lib:hibernate(?module, loop, [s]); {tcp_closed,s} -> io:format("socket ~w closed [~w]~n",[s,self()]), ok end.
given configuration beam consumed 2.5 gb of memory on start without module loaded.
however, if reduce maximum number of processes reasonable value, +p 60000 50 000 connections test, memory consumption drops rapidly.
with 60 000 processes limit vm used 527mb of virtual memory on start.
i've tried reproduce test, unfortunately able launch 30 000 netcat's on system before running out of memory (because of client jobs). observed increase of vm memory consumption 570mb.
so suggestion numbers come high startup memory consumption , not great number of opened connections. should pay attention stats change along increasing number of opened connections , not absolute values.
i used following configuration benchmark:
erl +k true +q 64200 +p 60000 -env erl_max_ports 40960000 -env erts_max_ports 40960000 +a 16 +hms 1024 +hmbs 1024
so i've launched clients command
for in `seq 1 50000`; nc 127.0.0.1 5001 & done
Comments
Post a Comment