summaryrefslogtreecommitdiffstats
path: root/_build/static/archives/extend/2013-April/000124.html
blob: 08b363e5c6b062edaeaf3b5679fb79f95ad2efa7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
 <HEAD>
   <TITLE> [99s-extend] cowboy how to ruduce the memory usage per long-hold	connection
   </TITLE>
   <LINK REL="Index" HREF="index.html" >
   <LINK REL="made" HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20cowboy%20how%20to%20ruduce%20the%20memory%20usage%20per%20long-hold%0A%09connection&In-Reply-To=%3CCAN_mQBobPN0zdpqJ3WtGKJaRMNiutvurgJfncMCqM3qtUHTm1g%40mail.gmail.com%3E">
   <META NAME="robots" CONTENT="index,nofollow">
   <style type="text/css">
       pre {
           white-space: pre-wrap;       /* css-2.1, curent FF, Opera, Safari */
           }
   </style>
   <META http-equiv="Content-Type" content="text/html; charset=us-ascii">
   <LINK REL="Previous"  HREF="000123.html">
   <LINK REL="Next"  HREF="000125.html">
 </HEAD>
 <BODY BGCOLOR="#ffffff">
   <H1>[99s-extend] cowboy how to ruduce the memory usage per long-hold	connection</H1>
    <B>yongboy</B> 
    <A HREF="mailto:extend%40lists.ninenines.eu?Subject=Re%3A%20%5B99s-extend%5D%20cowboy%20how%20to%20ruduce%20the%20memory%20usage%20per%20long-hold%0A%09connection&In-Reply-To=%3CCAN_mQBobPN0zdpqJ3WtGKJaRMNiutvurgJfncMCqM3qtUHTm1g%40mail.gmail.com%3E"
       TITLE="[99s-extend] cowboy how to ruduce the memory usage per long-hold	connection">yongboy at gmail.com
       </A><BR>
    <I>Fri Apr 26 08:11:56 CEST 2013</I>
    <P><UL>
        <LI>Previous message: <A HREF="000123.html">[99s-extend] does cowboy support hot code reload/replace ?
</A></li>
        <LI>Next message: <A HREF="000125.html">[99s-extend] cowboy how to ruduce the memory usage per	long-hold connection
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#124">[ date ]</a>
              <a href="thread.html#124">[ thread ]</a>
              <a href="subject.html#124">[ subject ]</a>
              <a href="author.html#124">[ author ]</a>
         </LI>
       </UL>
    <HR>  
<!--beginarticle-->
<PRE>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) -&gt;
        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) -&gt;
        NowCount = count_server:welcome(),
        io:format(&quot;online user ~p :))~n&quot;, [NowCount]),

        output_first(Req),
        Req2 = cowboy_req:compact(Req),
        {loop, Req2, State, hibernate}.

%% POST/Short Request
info(_Any, Req, State) -&gt;
        {loop, Req, State, hibernate}.

output_first(Req) -&gt;
        {ok, Reply} = cowboy_req:chunked_reply(200, [{&lt;&lt;&quot;Content-Type&quot;&gt;&gt;,
&lt;&lt;&quot;text/html; charset=utf-8&quot;&gt;&gt;},

{&lt;&lt;&quot;Connection&quot;&gt;&gt;, &lt;&lt;&quot;keep-alive&quot;&gt;&gt;}], Req),
        cowboy_req:chunk(&lt;&lt;&quot;&lt;html&gt;&lt;body&gt;&lt;script&gt;var _ = function (msg) {
parent.s._(msg, document);
};&lt;/script&gt;
&quot;&gt;&gt;,
                                                                Reply),
        cowboy_req:chunk(gen_output(&quot;1::&quot;), Reply).

gen_output(String) -&gt;
        DescList = io_lib:format(&quot;&lt;script&gt;_('~s');&lt;/script&gt;&quot;, [String]),
        list_to_binary(DescList).

terminate(Reason, _Req, _State) -&gt;
        NowCount = count_server:bye(),
        io:format(&quot;offline user ~p :(( ~n&quot;, [NowCount]).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: &lt;<A HREF="http://lists.ninenines.eu/archives/extend/attachments/20130426/9d234e27/attachment.html">http://lists.ninenines.eu/archives/extend/attachments/20130426/9d234e27/attachment.html</A>&gt;
</PRE>

<!--endarticle-->
    <HR>
    <P><UL>
        <!--threads-->
	<LI>Previous message: <A HREF="000123.html">[99s-extend] does cowboy support hot code reload/replace ?
</A></li>
	<LI>Next message: <A HREF="000125.html">[99s-extend] cowboy how to ruduce the memory usage per	long-hold connection
</A></li>
         <LI> <B>Messages sorted by:</B> 
              <a href="date.html#124">[ date ]</a>
              <a href="thread.html#124">[ thread ]</a>
              <a href="subject.html#124">[ subject ]</a>
              <a href="author.html#124">[ author ]</a>
         </LI>
       </UL>

<hr>
<a href="https://lists.ninenines.eu/listinfo/extend">More information about the Extend
mailing list</a><br>
</body></html>