[erlang-questions] Memory usage with gen_tcp

Paul Oliver <>
Thu Sep 18 17:19:13 CEST 2008


Hi all,

I have a simple echo server built on top of mochiweb_socket_server
(http://mochiweb.googlecode.com/svn/trunk/src/mochiweb_socket_server.erl):

-define(DEFAULTS, [{ip, "127.0.0.1"}, {loop, {?MODULE, loop}}, {name,
?MODULE}, {port, 8888}, {max, 100000}]).

start() ->
    start(?DEFAULTS).

start(Options) ->
    mochiweb_socket_server:start(Options).

loop(Socket) ->
    case gen_tcp:recv(Socket, 0) of
        {ok, Data} ->
            gen_tcp:send(Socket, Data),
            loop(Socket);
        {error, closed} ->
            ok
    end.

I'm load testing and have found that the memory used in the echo
server per connected client is approximately 40K.  I've tried setting
sndbuf and recbuf to 1024 respectively (hardcoded in
mochiweb_socket_server), but this doesn't seem to make a difference.
Does anybody know where I should be looking to reduce this figure?

Thanks,
Paul.



More information about the erlang-questions mailing list