Is 13.6K/connection considered a lot? Once you start doing SSL, each connection will be about 80K, IMHO the most important factor for huge ammount of COMET users is latency, which Cowboy and Erlang do great.<div><br></div>
<div>-rambocoder<br><br><div class="gmail_quote">On Fri, Apr 26, 2013 at 2:11 AM, yongboy <span dir="ltr"><<a href="mailto:yongboy@gmail.com" target="_blank">yongboy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<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>

</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>

            [{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>

-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>

        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>

        {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>

                                                                 {<<"Connection">>, <<"keep-alive">>}], Req),<br>        cowboy_req:chunk(<<"<html><body><script>var _ = function (msg) { parent.s._(msg, document); };</script>                                                                                                                                                                                                                  ">>,<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>

        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>_______________________________________________<br>
Extend mailing list<br>
<a href="mailto:Extend@lists.ninenines.eu">Extend@lists.ninenines.eu</a><br>
<a href="http://lists.ninenines.eu:81/listinfo/extend" target="_blank">http://lists.ninenines.eu:81/listinfo/extend</a><br>
<br></blockquote></div><br></div>