[erlang-questions] stress test with tcp_server
周敏
erlanging@REDACTED
Sun Jun 24 15:00:17 CEST 2007
Hi list,
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.
below is my test code:
-module(stress_test).
-export([start/0, tests/1]).
start() ->
tests(12345).
tests(Port) ->
io:format("starting~n"),
spawn(fun() -> test(Port) end),
spawn(fun() -> test(Port) end),
spawn(fun() -> test(Port) end),
spawn(fun() -> test(Port) end).
test(Port) ->
case gen_tcp:connect("192.168.0.217", Port, [binary,{packet, 0}]) of
{ok, _} ->
test(Port);
_ ->
test(Port)
end.
I've create four erlang processes to connect the echo server continuously.
the echo server code is like this:
-module(echo_server).
-export([start/0,stop/0]).
-define(LISTEN_PORT,12345).
-define(MAX_CONN, 5000).
start() ->
process_flag(trap_exit, true),
tcp_server:start_raw_server(?LISTEN_PORT,
fun(Socket) -> socket_handler(Socket,self()) end,
?MAX_CONN,
0).
socket_handler(Socket,Controller) ->
receive
{tcp, Socket, Bin} ->
gen_tcp:send(Socket, Bin); % echo
{tcp_closed, Socket} ->
ok;
_ ->
socket_handler(Socket,Controller)
end.
stop() ->
tcp_server:stop(?LISTEN_PORT)
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:
possibly_start_another(false, Listen, Active, Fun, Max) ->
case length(Active) of
N when N < Max ->
New = start_accept(Listen, Fun),
io:format("current connetiones number is ~p~n",[N]), % the line I
added to display connections number
socket_loop(Listen, New, Active, Fun, Max);
_ ->
socket_loop(Listen, false, Active, Fun, Max)
end
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.
Cheers,
Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070624/b8f4cf97/attachment.htm>
More information about the erlang-questions
mailing list