[99s-extend] cowboy how to ruduce the memory usage per long-hold connection

rambocoder erlang at rambocoder.com
Fri Apr 26 15:11:53 CEST 2013


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.

-rambocoder

On Fri, Apr 26, 2013 at 2:11 AM, yongboy <yongboy at gmail.com> wrote:

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


More information about the Extend mailing list