<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>mochiweb &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/mochiweb/</link>
	<description>Feed of posts on WordPress.com tagged "mochiweb"</description>
	<pubDate>Fri, 25 Dec 2009 07:40:57 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Nginx vs Yaws vs MochiWeb : Web Server Performance Deathmatch, Part 2 [Update x 2]]]></title>
<link>http://maheshvnit.wordpress.com/2009/11/05/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2-update-x-2/</link>
<pubDate>Thu, 05 Nov 2009 07:01:56 +0000</pubDate>
<dc:creator>maheshvnit</dc:creator>
<guid>http://maheshvnit.wordpress.com/2009/11/05/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2-update-x-2/</guid>
<description><![CDATA[Update 1: Retest data (using different machine and Erlang kernel polling) added near bottom of post.]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><em>Update 1: Retest data (using different machine and Erlang kernel polling) added near bottom of post.</em></p>
<p><em><strong>Update 2</strong>: More details and testing on the weird MochiWeb kernel polling results, bottom of post.</em></p>
<p>Almost a year ago I did some <a href="http://www.joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/" target="_blank">Apache and Nginx performance testing</a>. Apparently I have the bug again and have done some performance testing on <a href="http://www.nginx.net/" target="_blank">Nginx</a>, <a href="http://yaws.hyber.org/" target="_blank">Yaws</a> and <a href="http://code.google.com/p/mochiweb/" target="_blank">MochiWeb</a>. The latter two being Erlang based. Again deathmatch may be an overstatement but this is my attempt at gleaning some interesting performance data from some high performance web servers. Also, I attempted to improve the graphs this time around since they were a bit hard to read the last time.</p>
<p><strong>The Setup:</strong></p>
<p>I was not able to use the same server and setup as the last time, so comparing between this and my last deathmatch probably isn’t very accurate. For this test I used a Intel Dual Core 2.2GHz, 4GB RAM machine running Ubuntu 8.10 (64bit) and for the test server. Erlang (R12B-3), Yaws (1.77) and Nginx (0.6.32) are installed from the standard repository and mochiweb from subversion (rev 88). All are using the <strong>default configurations</strong> outside of adjusting listening port numbers. The test is again against a basic robots.txt file. The tests were done using a consumer grade 100mb switch and all tests originated from an old laptop I had laying around. I think that about covers the test bed, if you have any questions let me know.</p>
<p>For the tests I used autobench (httperf under the hood) with the following command, each test ran ten minutes apart. The order of the tests were done in was MochiWeb then Yaws and lastly Nginx.</p>
<blockquote><p>autobench –single_host –host1 HOST –port1 PORT –uri1 /robots.txt –low_rate 10 –high_rate 200 –rate_step 10 –num_call 10 –num_conn 5000 –timeout 5 –file SERVER-results-`date +%F-%H:%M:%S`.ts</p>
<p><a href="http://www.noupe.com/php/php-security-tips.html#more-15885" target="_blank">Read the rest of this entry »</a></p>
<p>&#160;</p>
<p><a href="http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/" target="_blank">http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/</a></p>
<p>&#160;</p>
</blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Edgynet Demo Released]]></title>
<link>http://blog.edgynet.com/2009/09/26/edgynet-demo-released/</link>
<pubDate>Sat, 26 Sep 2009 17:14:48 +0000</pubDate>
<dc:creator>edgynet</dc:creator>
<guid>http://blog.edgynet.com/2009/09/26/edgynet-demo-released/</guid>
<description><![CDATA[We are very pleased to announce the release of a demo version of the Edgynet network simulator. It i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div class="edgynet-post">
<p>We are very pleased to announce the release of a demo version of the Edgynet network simulator. It is available online right now, all that&#8217;s required is a web browser. See:</p>
<blockquote><p><a href="http://www.edgynet.com/demo">http://www.edgynet.com/demo</a></p></blockquote>
<p>To use the simulator in its current form, you will need to have some understanding of how to set up networking on a Linux machine from the command line (using either &#8216;<code>ifconfig</code>&#8216; and &#8216;<code>route</code>&#8216;, or iproute2 commands). In the future we hope to simulate other types of network devices, but at the moment the interface to each virtual-device is based on Linux.</p>
<div class="warning-box" style="background-color:#ced6d8;border:solid 1px black;margin:20px;padding:10px 20px;">
<h3 class="warning-topic" style="font-size:105%;font-weight:bold;color:black;">Tiny bit of bad news:</h3>
<p>If you are connecting to the service from outside of Europe, or you are using a 3G Internet connection, then you&#8217;re probably going to find the demo quite sluggish. This is due to latency.</p>
<p>Ideal operating conditions are when your ping round-trip-time to www.edgynet.com is 60ms or less. It should still be bearable up to 100ms, but above that it starts to become painful.</p>
<p>At the moment our demo server is located in Germany, but in the future we expect to host application servers in other geographic locations.</p>
</p></div>
<p>We&#8217;ve used many open-source technologies to build the Edgynet system, and we&#8217;d like to take the opportunity to thank the following projects in particular:</p>
<ul>
<li>
      <a href="http://www.erlang.org">Erlang/OTP</a></p>
<p>Our server-side system is built in Erlang.</p>
</li>
<li>
      <a href="http://code.google.com/p/mochiweb/">MochiWeb</a></p>
<p>Handles all incoming HTTP requests.</p>
</li>
<li>
      <a href="http://jquery.com">jQuery</a></p>
<p>Our User Interface relies heavily on the functionality offered by jQuery.</p>
</li>
<li>
      <a href="http://cometd.org/">Cometd (Dojo Foundation)</a></p>
<p>We&#8217;re using the <a href="http://cometd.org/documentation/bayeux">Bayeux</a> protocol, developed by the Dojo Foundation, for client &#60;-&#62; server asynchronous messaging.</p>
<p>We are also using the <a href="http://cometd.org/documentation/cometd-javascript">jQuery Cometd implementation</a> for our client-side Bayeux handler.</p>
</li>
</ul>
<p>Many other Open-Source tools are being used to build and run the Edgynet website, including: <a href="http://www.debian.org/">Debian GNU/Linux</a>, <a href="http://www.gimp.org">Gimp</a>, <a href="www.inkscape.org">Inkscape</a>, <a href="http://ffmpeg.org">FFmpeg</a>, <a href="http://www.nagios.org">Nagios</a>, <a href="http://www.cacti.net">Cacti</a> and <a href="http://oss.oetiker.ch/rrdtool/">RRDtool</a>.</p>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Solving performance problems in pub-sub erlang server]]></title>
<link>http://timanovsky.wordpress.com/2009/08/20/solving-performance-problems-in-pub-sub-erlang-server/</link>
<pubDate>Thu, 20 Aug 2009 20:15:22 +0000</pubDate>
<dc:creator>Alexey Timanovsky</dc:creator>
<guid>http://timanovsky.wordpress.com/2009/08/20/solving-performance-problems-in-pub-sub-erlang-server/</guid>
<description><![CDATA[Intro So I wrote (see some prehistory here) a kind of notification server where clients can subscrib]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Intro</strong><br />
So I wrote (see some prehistory <a href="http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/">here</a>) a kind of notification server where clients can subscribe to events and be notified when event of interest happens.  Clients use HTTP long poll method to get notifications delivered, and one of the application of the server is chat room.</p>
<p><strong>Symptoms</strong><br />
In my case there were two problems:</p>
<ol>
<li>general lack of performance (I started optimizing somewhere from 200-300 messages per second)</li>
<li>under high load server would lock up, sometimes for extended period of time &#8211; it does not deliver any messages</li>
<li>even under moderate load performance is not stable and would drop eventually for some period of time (sometimes to complete lock up, sometimes not, sometimes for a couple of seconds, sometimes for longer time).</li>
<li>In-depth investigation with tcpdump has shown that server can not even accept connections.</li>
</ol>
<p><strong>Side note on server not accepting tcp connections</strong><br />
That is interesting how it happens though. I don&#8217;t know if it is specific Linux 2.6 behavior of it is a norm, but the sequence is:</p>
<ol>
<li>client sends SYN</li>
<li>server responds with ACK, but acknowledgment number set to some arbitrary big number</li>
<li>client drops connection by sending RST</li>
</ol>
<p>So should you see similar behavior note that this is just a symptom, not disease. The problem is somewhere dipper. In my case increasing TCP listen backlog from mochiweb&#8217;s default 30 helped a bit, fewer timeouts were observed, but still performance sucked.</p>
<p><strong>Fixing Root Cause</strong><br />
So how pub-sub servers in Erlang are generally built? You get a message being processed in some process, it might have been received from somewhere else or originates from this process . And then you have bunch of waiting processes representing connected subscribed clients waiting for a message be delivered. Each of these processes normally represents TCP connection or in my case HTTP long polling connection. And delivering message to this process releases it from wait state and allows message to be delivered to end user. There is of course some router module or process which determines a subset of processes (PIDs) to which the message should be delivered. How to do efficiently is very interesting topic but not for this post. Then you do something like<br />
<strong><code>lists:foreach(fun(Pid) -&#62; send_message(Pid, Message) end, PidList)</code></strong></p>
<p>The result of this is that each of processes from the target group (selected by router) becomes immediately available for execution. And if the group size is big, chances are that current process broadcasting this notifications will be preempted. And the thing is that this actually causes context switching storm. I&#8217;m not 100% sure how Erlang runtime is implemented, but it seems that if process receives a message it gets some kind of priority and is scheduled for execution, like it happens in some OSes. So the message sending loop may take quite awhile.</p>
<p>Now, if the message broadcast loop is more complex, say it consists of two nested loops, and inside it you do some non trivial operations followed by sending the message for one particular PID, then the things become very bad. Context switching overhead no matter how light it is in Erlang kills your performance.</p>
<p><strong>Recipe</strong></p>
<ol>
<li>If you have complex loops to calculate to which PID send the message, and you do message sending inside that loop &#8211; rewrite the code. First prepare list of PIDs using whatever complex procedures you have, then send messages to those PIDs in one shot.</li>
<li>Then sending messages to bunch of PIDs do temporarily boost performance of your thread so it won&#8217;t be preempted.</li>
</ol>
<p>Example:<br />
<strong><code><br />
PidList = generate_pid_list(WhatEver),<br />
OldPri = process_flag(priority, high),  % Raise priority, save old one<br />
lists:foreach(fun({Pid, Msg}) -&#62; send_message(Pid, Msg) end, PidList),<br />
process_flag(priority, OldPri)<br />
</code><br />
</strong><br />
That&#8217;s basically it. The result is that now I&#8217;m reliably achieving about 1.5k messages/sec with all stuff like HTTP/JSON parsing, ETS operations, logging, etc. I would like to pump this number few times higher, but at the moment that&#8217;s what I can get. I will come back when learn something new <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>PS. You may also find this discussion followed $1000 code challenge useful:<br />
<a href="http://groups.google.com/group/erlang-programming/browse_thread/thread/1931368998000836/b325e869a3eea26a">http://groups.google.com/group/erlang-programming/browse_thread/thread/1931368998000836/b325e869a3eea26a</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Toward a million-user long-poll HTTP application - nginx + erlang + mochiweb :)]]></title>
<link>http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/</link>
<pubDate>Thu, 08 Jan 2009 21:48:53 +0000</pubDate>
<dc:creator>Alexey Timanovsky</dc:creator>
<guid>http://timanovsky.wordpress.com/2009/01/09/toward-a-million-user-long-poll-http-application-nginx-erlang-mochiweb/</guid>
<description><![CDATA[Intro First, this post and title are inspired by the following great article, you absolutely must re]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>Intro</strong><br />
First, this post and title are inspired by the following great article, you absolutely must read if you are interested in the subject:<br />
<a href="http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1/">http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1/</a><br />
<a href="http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/">http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-2/</a><br />
<a href="http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3/">http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-3/</a></p>
<p>I&#8217;m quite far from 1M users, but still getting a load which out-of-the-box configuration can not cope with. What I&#8217;m doing is long-poll HTTP server which implements chat and some other real-time notifications for web clients. Nginx is used as a reverse proxy (HTTP router basically). Let&#8217;s say we want to handle <strong><em>N</em></strong> connections simultaneously (<strong><em>N</em></strong> should be much bigger than 1000 <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).  What parameters need to be changed? <em>Note: all numbers are approximate.</em></p>
<p><strong>1. Nginx</strong><br />
Number of file handlers (descriptors) provided by OS. It is configured in the script which launches nginx. In my case it is <code>/etc/init.d/nginx</code>.  So I just add<br />
<code><br />
ulimit -n <strong><em>N*2</em></strong><br />
</code><br />
Mind that proxy naturally uses two sockets per connection (uplink and downlink).</p>
<p>Now let&#8217;s take a look at Nginx config file (<code>/etc/nginx/nginx.conf</code> for me). Here is extract from Nginx manual on <strong>events</strong> module:</p>
<blockquote><p>
The worker_connections and worker_proceses from the main section allows you to calculate maxclients value:<br />
max_clients = worker_processes * worker_connections<br />
In a reverse proxy situation, max_clients becomes<br />
max_clients = worker_processes * worker_connections/4
</p></blockquote>
<p>So we have to set<br />
<code><br />
events {<br />
    worker_connections  <strong><em>N*4</em></strong>;<br />
}<br />
</code></p>
<p>Then as we use Nginx as a proxy not for a regular HTTP server, but for long-polling one, we have to tune Nginx parameters:<br />
<code><br />
location /my_url {<br />
             proxy_pass http://127.0.0.1:8000;<br />
             proxy_buffering off;<br />
             proxy_read_timeout 3600;<br />
        }<br />
</code><br />
So we forward all requests to &#8220;/my_url&#8221; to HTTP server running on localhost port 8000. We disable buffering in Nginx, and tell that it may take a while for the server to respond, so Nginx should wait and not timeout.</p>
<p>ok, we are done with Nginx, let&#8217;s go to the server</p>
<p><strong>2. Erlang</strong><br />
Again in start script we set number of available file descriptors:<br />
<code><br />
ulimit -n <strong><em>N</em></strong><br />
</code></p>
<p>Then we are passing two additional params to erlang:<br />
<code><br />
erl +K true  +P <strong><em>N</em></strong> <em>...you params here</em><br />
</code><br />
+K option enables kernel polling, which saves some CPU cycles when handling multitude of connections. +P says how many parallel processes Eralng VM can have, by default it is 32768. My application is based on mochiweb library and uses one process per connection (usual case for Erlang server applications), so we need to have at least <strong><em>N</em></strong></em> processes. Note that some recommend to set it to maximum possible value, roughly 137M, but It leads to that Erlang VM allocates about 1GB of memory, not a big deal per se as it is in virtual address space, but I can imagine what internal reference tables for this memory heap and erlang process tables/mailboxes/whatever are also big and can cause some overhead. So I&#8217;d prefer to be on a safer side and set it to the really required value. </p>
<p><strong>3. Application</strong><br />
The last thing we want is tell mochiweb server that we want more than default 2048 simultaneous connections. So I changing start parameters:<br />
<code><br />
    mochiweb_http:start([{max, <strong><em>N</em></strong> <em>},{name, ?MODULE}, {loop, Loop} &#124; Options]).<br />
</code></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[fun with mochiweb's html parser and xpath]]></title>
<link>http://ppolv.wordpress.com/2008/05/09/fun-with-mochiwebs-html-parser-and-xpath/</link>
<pubDate>Fri, 09 May 2008 23:07:41 +0000</pubDate>
<dc:creator>ppolv</dc:creator>
<guid>http://ppolv.wordpress.com/2008/05/09/fun-with-mochiwebs-html-parser-and-xpath/</guid>
<description><![CDATA[Some days ago, while reading Roberto Saccon&#8217;s blog, I noticed that mochiweb has an html parser]]></description>
<content:encoded><![CDATA[Some days ago, while reading Roberto Saccon&#8217;s blog, I noticed that mochiweb has an html parser]]></content:encoded>
</item>
<item>
<title><![CDATA[Open source software at Smarkets]]></title>
<link>http://blog.smarkets.com/2008/04/23/open-source-software-at-smarkets/</link>
<pubDate>Wed, 23 Apr 2008 11:29:59 +0000</pubDate>
<dc:creator>Hunter Morris</dc:creator>
<guid>http://blog.smarkets.com/2008/04/23/open-source-software-at-smarkets/</guid>
<description><![CDATA[I&#8217;m an unabashed open source fanboy. At Smarkets, I use a lot of software written by other peo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>I&#8217;m an unabashed open source fanboy.  At Smarkets, I use a lot of software written by other people.  Here is a quick summary of the Smarkets stack; think of them as geek shoutouts.</p>
<ul>
<li><a href="http://www.erlang.org/">Erlang</a> &#8211; Almost everything is built atop the Erlang/OTP application system. I like <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a>. It is easier to manage complexity in a language with reasonably isolated <a href="http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29">side effects</a>. Erlang&#8217;s <a href="http://en.wikipedia.org/wiki/Concurrency_%28computer_science%29">concurrency</a> primitives have been touted many times before, and conceptualising concurrent systems as communicating sequential processes now feels a lot more natural than other paradigms. As Damien Katz <a href="http://damienkatz.net/2008/04/lisp_as_blub.html">recently mentioned</a>, systems built atop Erlang/OTP don&#8217;t seem to suffer the same failures under high load as certain other garbage collected languages do.</li>
<li><a href="http://code.google.com/p/distel/">Distel</a> on <a href="http://www.gnu.org/software/emacs/">Emacs</a> &#8211; When writing code (and actually quite a bit more), I like Emacs. When writing Erlang, I like Distel. It provides a natural entry point for debugging pieces of Erlang code. Getting Emacs to communicate with an inferior Erlang VM is especially useful for rapid prototyping. Being able to do everything within Emacs is good for productivity.</li>
<li><a href="http://www.erlang.org/doc/apps/mnesia/index.html">Mnesia</a> &#8211; Arbitrary term storage is a simple way to avoid having to interface with another database management system. Because Mnesia is part of Erlang/OTP, you get it for free.</li>
<li><a href="http://code.google.com/p/mochiweb/">Mochiweb</a> and <a href="http://nginx.net/">nginx</a> &#8211; Thanks to <a href="http://bob.pythonmac.org/">Bob Ippolito</a> and Matthew Dempsky (and others I&#8217;m sure I&#8217;ve missed) for the mochiweb HTTP toolkit. It&#8217;s lightweight and embeddable, so it was very easy for us to integrate with our backend. Nginx performs well and is very simple to integrate with a backend powered by mochiweb.</li>
<li><a href="http://code.google.com/p/sgte/">sgte</a> and <a href="http://www.stringtemplate.org/">StringTemplate</a> &#8211; <a href="http://blog.sgconsulting.it/">Filippo Pacini&#8217;s</a> sgte template engine (&#8220;inspired by&#8221; StringTemplate) was the basis for our templating system.</li>
<li><a href="http://www.stacken.kth.se/project/yxa/">YXA</a> &#8211; While we don&#8217;t specifically deploy any SIP software, YXA is a great example of well-written Erlang. I learned a lot from reading through Magnus Ahltorp and Fredrik Thulin&#8217;s code. It&#8217;s been around for several years and has matured quite a bit as a result.</li>
<li><a href="http://en.wikipedia.org/wiki/Flat_file">Flat files</a> &#8211; Writing a binary file to disk is sometimes overlooked as a solid way to persist sequential data that&#8217;s only needed locally. I&#8217;m not sure who I should thank here, but I think the list would probably be pretty long.</li>
</ul>
</div>]]></content:encoded>
</item>

</channel>
</rss>
