summaryrefslogtreecommitdiffstats
path: root/archives/extend/2013-April/000124.html
diff options
context:
space:
mode:
Diffstat (limited to 'archives/extend/2013-April/000124.html')
-rw-r--r--archives/extend/2013-April/000124.html122
1 files changed, 122 insertions, 0 deletions
diff --git a/archives/extend/2013-April/000124.html b/archives/extend/2013-April/000124.html
new file mode 100644
index 00000000..08b363e5
--- /dev/null
+++ b/archives/extend/2013-April/000124.html
@@ -0,0 +1,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>