Hi list,<br> I am a newbie in erlang network program. I've wrote a simple stress test case in erlang for testing how many connnetions can accepted by echo server based on tcp_server.erl in one pc.<br> below is my test code:
<br><br>-module(stress_test).<br><br>-export([start/0, tests/1]).<br><br>start() -><br> tests(12345).<br><br>tests(Port) -><br> io:format("starting~n"),<br> spawn(fun() -> test(Port) end),<br> spawn(fun() -> test(Port) end),
<br> spawn(fun() -> test(Port) end),<br> spawn(fun() -> test(Port) end).<br><br>test(Port) -><br> case gen_tcp:connect("<a href="http://192.168.0.217">192.168.0.217</a>", Port, [binary,{packet, 0}]) of
<br> {ok, _} -><br> test(Port);<br> _ -><br> test(Port)<br> end.<br><br>I've create four erlang processes to connect the echo server continuously. the echo server code is like this:<br>
<br>-module(echo_server).<br>-export([start/0,stop/0]).<br><br>-define(LISTEN_PORT,12345). <br>-define(MAX_CONN, 5000). <br><br>start() -><br> process_flag(trap_exit, true),<br> tcp_server:start_raw_server(?LISTEN_PORT,
<br> fun(Socket) -> socket_handler(Socket,self()) end,<br> ?MAX_CONN, <br> 0).<br><br>socket_handler(Socket,Controller) -><br> receive<br> {tcp, Socket, Bin} ->
<br> gen_tcp:send(Socket, Bin); % echo<br> {tcp_closed, Socket} -><br> ok;<br> _ -><br> socket_handler(Socket,Controller)<br> end.<br><br>stop() -><br> tcp_server:stop(?LISTEN_PORT)
<br><br><br>and to test how many connections the server can accept, I've add only one line in funtion possibly_start_another of Joe's tcp_server.erl, like below:<br><br>possibly_start_another(false, Listen, Active, Fun, Max) ->
<br> case length(Active) of<br> N when N < Max -><br> New = start_accept(Listen, Fun),<br> io:format("current connetiones number is ~p~n",[N]), % the line I added to display connections number
<br> socket_loop(Listen, New, Active, Fun, Max);<br> _ -><br> socket_loop(Listen, false, Active, Fun, Max)<br> end<br><br>after compile these codes. It appears that only 1016 connections can be accepted by the server. What's matter with this? I really know what going wrong .. thx at first.
<br><br>Cheers,<br>Jeremy<br>