<tt>
<div dir="ltr"><div><div>I have tested one long-hold webapp, when 512000 user connected, the app used <br></div>6801M memory, 6801M*1024K / 512000 = 13.6K/Connection.<br><br></div><div>Does anyone give me some advice on how to reduce the memory usage per one connection, thanks very much !<br>
<br>
</div><div><br></div>Here is the code snippet:<br><br>start(_Type, _Args) -><br>������� Dispatch = cowboy_router:compile([<br>����������� {'_', [{'_', htmlfile_handler, []}]}<br>������� ]),<br>������� cowboy:start_http(my_http_listener, 100,<br>
<br>
����������� [{port, 8000}, {max_connections, infinity}],<br>����������� [{env, [{dispatch, Dispatch}]}]<br>������� ),<br>������� count_server:start(),<br>������� htmlfilesimple_sup:start_link().<br><br>......<br><br>-module(htmlfile_handler).<br>
<br>
-behaviour(cowboy_loop_handler).<br>-export([init/3, info/3, terminate/3]).<br>-define(HEARBEAT_TIMEOUT, 20*1000).<br>-record(status, {count=0}).<br><br>init(_Any, Req, State) -><br>������� NowCount = count_server:welcome(),<br>
<br>
������� io:format("online user ~p :))~n", [NowCount]),<br><br>������� output_first(Req),<br>������� Req2 = cowboy_req:compact(Req),<br>������� {loop, Req2, State, hibernate}.<br><br>%% POST/Short Request<br>info(_Any, Req, State) -><br>
<br>
������� {loop, Req, State, hibernate}.<br><br>output_first(Req) -><br>������� {ok, Reply} = cowboy_req:chunked_reply(200, [{<<"Content-Type">>, <<"text/html; charset=utf-8">>},<br>
<br>
���������������������������������������������������������������� {<<"Connection">>, <<"keep-alive">>}], Req),<br>������� cowboy_req:chunk(<<"<html><body><script>var _ = function (msg) { parent.s._(msg, document); };</script>����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ">>,<br>
<br>
��������������������������������������������������������������� Reply),<br>������� cowboy_req:chunk(gen_output("1::"), Reply).<br><br>gen_output(String) -><br>������� DescList = io_lib:format("<script>_('~s');</script>", [String]),<br>
<br>
������� list_to_binary(DescList).<br><br>terminate(Reason, _Req, _State) -><br>������� NowCount = count_server:bye(),<br>������� io:format("offline user ~p :(( ~n", [NowCount]).<br><br><br><br></div>
<br>
</tt>