<?xml version="1.0" encoding="UTF-8"?><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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eduardo Silva Pereira</title>
	<atom:link href="http://edsiper.linuxchile.cl/blog/feed/rss/" rel="self" type="application/rss+xml" />
	<link>http://edsiper.linuxchile.cl/blog</link>
	<description>edsiper's personal website</description>
	<lastBuildDate>Fri, 12 Apr 2013 18:38:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Monkey Project joins Google Summer of Code 2013</title>
		<link>http://edsiper.linuxchile.cl/blog/2013/04/12/monkey-project-joins-google-summer-of-code-2013/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2013/04/12/monkey-project-joins-google-summer-of-code-2013/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 18:38:28 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Announces]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Summer of Code]]></category>
		<category><![CDATA[Monkey]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=1064</guid>
12345		<description><![CDATA[<p>thanks <a href="http://google.com">Google</a> for the opportunity! , this week the results for the <a href="http://www.google-melange.com/gsoc/accepted_orgs/google/gsoc2013">Mentoring Organizations for Google Summer of Code 2013</a> were released. I am very happy to announce that <a href="http://www.google-melange.com/gsoc/org/google/gsoc2013/monkey">Monkey Project</a> will be part of the program as second consecutive year.</p>
<p>We are a very small group of people developing an open source stack for web technologies and take part of the program means a big recognition, we are glad to be able to mentor students that will be hacking with us during three months.</p>
<p>Our last year experience was very positive, most of projects were developed successfully and those students have take an important role in our community and project development in general, so we have high expectations for this second round, as you can see there is a good scope of project ideas to develop in areas such as protocols (SPDY), OSX, Raspberry Pi, Web Services, etc.</p>
<p>You can get more details about the incoming work in our <a href="http://monkey-project.com/gsoc2013/ideas">Monkey GSoC project ideas page</a>.</p>
]]></description>
			<content:encoded><![CDATA[<p>thanks <a href="http://google.com">Google</a> for the opportunity! , this week the results for the <a href="http://www.google-melange.com/gsoc/accepted_orgs/google/gsoc2013">Mentoring Organizations for Google Summer of Code 2013</a> were released. I am very happy to announce that <a href="http://www.google-melange.com/gsoc/org/google/gsoc2013/monkey">Monkey Project</a> will be part of the program as second consecutive year.</p>
<p>We are a very small group of people developing an open source stack for web technologies and take part of the program means a big recognition, we are glad to be able to mentor students that will be hacking with us during three months.</p>
<p>Our last year experience was very positive, most of projects were developed successfully and those students have take an important role in our community and project development in general, so we have high expectations for this second round, as you can see there is a good scope of project ideas to develop in areas such as protocols (SPDY), OSX, Raspberry Pi, Web Services, etc.</p>
<p>You can get more details about the incoming work in our <a href="http://monkey-project.com/gsoc2013/ideas">Monkey GSoC project ideas page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2013/04/12/monkey-project-joins-google-summer-of-code-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iOS Kernel Panic</title>
		<link>http://edsiper.linuxchile.cl/blog/2013/03/29/ios-kernel-panic/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2013/03/29/ios-kernel-panic/#comments</comments>
		<pubDate>Fri, 29 Mar 2013 20:35:42 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=1058</guid>
12345		<description><![CDATA[<p>today happened something that i was told many times that will not happen: iOS hanged in my Wife&#8217;s iPad, it wrote some trace messages alerting a Kernel Panic.</p>
<p><a href="http://edsiper.linuxchile.cl/ios_kernel_panic.jpg"><br />
<img class="aligncenter" title="iOS Kernel Panic (iPad)" src="http://edsiper.linuxchile.cl/ios_kp.jpg" alt="" width="800" height="533" /><br />
</a></p>
<p>Kernel Panics are Apple&#8217;s friends too <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></description>
			<content:encoded><![CDATA[<p>today happened something that i was told many times that will not happen: iOS hanged in my Wife&#8217;s iPad, it wrote some trace messages alerting a Kernel Panic.</p>
<p><a href="http://edsiper.linuxchile.cl/ios_kernel_panic.jpg"><br />
<img class="aligncenter" title="iOS Kernel Panic (iPad)" src="http://edsiper.linuxchile.cl/ios_kp.jpg" alt="" width="800" height="533" /><br />
</a></p>
<p>Kernel Panics are Apple&#8217;s friends too <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2013/03/29/ios-kernel-panic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Architecture of a Linux based Web Server</title>
		<link>http://edsiper.linuxchile.cl/blog/2013/02/27/architecture-of-a-linux-based-web-server/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2013/02/27/architecture-of-a-linux-based-web-server/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 22:16:17 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Duda I/O]]></category>
		<category><![CDATA[Linux Kernel]]></category>
		<category><![CDATA[Monkey]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=998</guid>
12345		<description><![CDATA[<p>this post is all about <a href="http://monkey-project.com">Monkey HTTP server</a>, i consider that is very important that besides we open our source code, the developers be also able to describe the project internals, there is no black magic, just thousands of hours of effort in programming, testing and improvement.</p>
<p><strong>Introduction</strong></p>
<p><a href="http://monkey-project.com">Monkey</a> is an open source project started on 2001 with the goal to learn C, the long story is <a href="http://monkey-project.com/documentation/history">here</a> . Along this years, the code have been improved in many aspects, since nomenclatures to heavy architecture changes, all have been made for good and nowadays thanks to the community of core developers and contributors around the project, <a href="http://monkey-project.com">Monkey</a> is one of the top performance web servers around, and i would claim that the best option for <a href="http://en.wikipedia.org/wiki/Embedded_Linux">Embedded Linux</a>.</p>
<p><strong>Understanding the basics of a human readable protocol: HTTP</strong></p>
<p>The <strong>H</strong>yper <strong>T</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol is basically a language with simple grammar to communicate two components: a HTTP client and a HTTP server. In a common context, the communication starts from a client performing a <em>request</em> to the server and for hence the server replying back with some result for the request performed. As a result we can consider a status response plus a content or simply an error.</p>
<p>Each HTTP request performed by the client is composed by a request method, URI, protocol version, and optionally a bunch of headers, so described that, we can say that a server must take care of:</p>
<ul>
<li>Listen for new connections</li>
<li>Accept connections</li>
<li>Once the connection is accepted, start reading the HTTP request sent by the client</li>
<li>Parse the HTTP request, understand what the client wants</li>
<li>Depending of the request type, the sever can: serve some content, close the connection because some exception, proxy back the request to somebody else, etc.</li>
<li>Close the connection or keep it opened waiting for more requests. This depends of the protocol version and client HTTP headers.</li>
</ul>
<p>Depending of the server target, it can be implemented in many ways with different architecture strategies, so the architecture described in this post only aims to describe what have worked better for us in terms of high performance and low resources usage.</p>
<p><strong>Architecture design facts</strong></p>
<ul>
<li><a href="http://monkey-project.com">Monkey</a> is a web server designed with a strong focus in Linux. It do <strong>not</strong> aims to be portable across other operating system, focusing in the top and widely used mainstream operating system allow us to put our energies and effort in one place in the best way, and of course take the most of Linux Kernel to achieve high performance.</li>
<li>Event driven: well known as <strong>asynchronous</strong>, an event driver web server aims to use non-blocking system calls to perform it works reducing the computing time in the user-space context, e.g: if we are sending a file content to a client, we do not block the whole process or thread when sending the data, instead we instruct the kernel through a system call to send N bytes from the file and just notify me where i am able to send more bytes, in the meanwhile.. i process other connections and send other pending data.</li>
<li>Embedded Friendly: our embedded context is Embedded Linux, we care a lot of resources consumption, that means that under a heavy load don&#8217;t use more than 2.5MB of memory. Even <a href="http://monkey-project.com">Monkey</a> binary size is around 80KB, once is load in memory it takes like 350KB, and depending of the load, more resources can be needed.</li>
<li>Small core, flexible API: it implements a basic core to handle <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> protocol, it exposes a flexible API through the plugin interface where is possible to hook plugins for transport layer, security, request type and event handlers.</li>
</ul>
<p><strong>Contexts</strong></p>
<p>In <a href="http://monkey-project.com">Monkey</a>, we have defined two contexts of work: process context and thread context. The process context represents the main process waiting for incoming connections and the scheduler balancing the new connection for the worker threads. The thread context belongs to each thread working the active connections:</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/architecture_general.png"><img class="aligncenter size-full wp-image-1012" title="architecture_general" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/architecture_general.png" alt="" width="600" height="174" /></a></p>
<p>The number of workers are defined in the configuration, it scale properly well in single and multi-core CPUs solutions. There is no need to set thread affinity through CPU masks, the <a href="http://kernel.org">Linux Kernel</a> Scheduler is smart enough to assign CPU time to each worker request, by default all workers are assign to all CPUs.</p>
<blockquote><p>From a system administrator point of view, is possible to assign each worker to a different set of CPUs, but this approach is not suggested unless we are totally aware about what the <a href="http://oreilly.com/catalog/linuxkernel/chapter/ch10.html">Linux scheduler</a> does in terms of interruptions,  context switches and CPU time for Kernel and User space applications. Do it only if you can do it better than the running scheduler.</p></blockquote>
<p><strong>Scheduler</strong></p>
<p>Before to enter in the server loop, the scheduler launch and initialize each worker, taking care of set the initial data structures and the interfaces for the interaction between the components mentioned, this stage involves the creation of a <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue per worker. Is good to mention that each <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue created through <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/epoll_create.2.html">epoll_create(2)</a> is managed through a specific file descriptor.</p>
<p>Once the workers are up and running, the next Scheduler job is to to manage the incoming connections. So for each new connection accepted, it determinate who is the lowest loaded worker and assign the connection to it. The chosen worker is the one that have less connections in its <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> interface, so the scheduler  goes around the worker counters and chose one. On this specific point the scheduler have two file descriptors: the connection file descriptor returned by <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/accept.2.html">accept(2)</a> and the file descriptor that represents the <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> of the chosen worker. So it basically register the new file descriptor in the proper <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue.</p>
<p><strong>Workers</strong></p>
<p>Each worker or thread, runs in an infinite loop through the <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> interface, which is basically a Linux specific polling mechanism to register, enqueue and notify about events in file descriptors registered by the Scheduler (sockets on this case).</p>
<p>The worker stay in a loop waiting for events in the <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/epoll_wait.2.html">epoll_wait(2)</a> system call. Every time the Scheduler register a new file descriptor, an event will be reported in the worker <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> interface, and it will do same when for subsequent events such as &#8220;there is data available for read&#8221; (EPOLLIN), &#8220;now you can write to the socket&#8221; (EPOLLOUT), &#8220;connection closed&#8221; (EPOLLHUP), etc.</p>
<p>So for each event triggered, the worker keeps a status of the connection to determinate if is a new connection, its receiving the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> request, <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> request completed, parsing the request or sending out some response. Besides events, every a fixed time of seconds set in the configuration, it checks the connections that timed out due to an incomplete request or another anomaly.</p>
<p><strong>Plugins Architecture</strong></p>
<p>Monkey defines three categories of API where the plugins can hook: Context, Events, Stages and Networking.</p>
<p style="padding-left: 30px;"><strong>Context<br />
</strong>Define callbacks  that can be invoked when the server is starting up, it covers the process and thread contexts described earlier.</p>
<p style="padding-left: 30px;"><strong>Events<br />
</strong>For every type of event reported in a worker loop, a plugin can implement a hook to perform specific actions:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_events.png"><img class="aligncenter size-medium wp-image-1042" title="api_events" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_events-300x106.png" alt="" width="300" height="106" /></a></p>
<p style="padding-left: 30px;"><strong>Stages<br />
</strong>Every new connection, enter in a stage status, so for each step of the HTTP cycle it passed along different phases, and each plugin can hook to a specific one:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_stages.png"><img class="aligncenter size-medium wp-image-1044" title="api_stages" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_stages-300x108.png" alt="" width="300" height="108" /></a></p>
<p style="padding-left: 30px;"><strong>Networking<br />
</strong>Monkey is not aware about networking, for hence it intentionally depends of a plugin that provides the transport layer, this approach allows to change from common sockets communication to encrypted one as SSL in a easy manner. The networking plugin only needs to provide the required API functions for the communication:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/level_networking.png"><img class="aligncenter size-medium wp-image-1047" title="level_networking" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/level_networking-300x176.png" alt="" width="300" height="176" /></a></p>
<p><strong>Scaling up</strong></p>
<p>Every time a connection have performed a successful request, this is allocated in a global list of the worker scope (implemented through a <a href="http://linux.die.net/man/3/pthread_key_create">pthread_key</a>). for each event reported, the worker needs to lookup the internal data associated to it, so the file descriptor or socket number  acts like a primary key for the search. The solution of data structure implemented for Monkey v1.2, is the use of <a href="http://www.kernel.org/doc/Documentation/rbtree.txt">red-black tree algorithm</a>. This algorithm have shown to behave very fairly and scalable when handling thousands of active connections per worker, maintaining a good balance between performance and cost.</p>
<p>The cost of each file descriptor lookup is critical for the server performance, having a O(n) solution will work fine for a few connections but under high concurrency a O(log(n)) solution will end up providing the highest performance.</p>
<p><strong>Memory Management</strong></p>
<p>One of the success key to reduce overhead in a server, is to reduce as much as possible the memory allocation requests performed  to the system within the main loop. Current Monkey implementation only performs 1 memory allocation per new connection, if it needed because the incoming request will post too much data, it will allocate more memory as it needs. Other web server solutions implements caching mechanism to reduce even more the memory allocations, as our focus is Embedded Linux we focus into speed at low resources usage, and implement a caching mechanism will increase our costs. So we dropped that common approach to do not abuse of system memory, just a decision based in the <em>target</em>.</p>
<p><strong>Linux Kernel system calls</strong></p>
<p>The <a href="http://kernel.org">Linux Kernel</a> exposes a useful of non-portable set of system calls to achieve high performance when creating networking applications. The first one is <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a>, as described earlier this interface allow to watch a set of file descriptors for certain defined events. Similar solutions like select(2) or poll(2) do not perform so well as <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> does.</p>
<p>When sending a static file, the old-fashioned way is to open the file, get the file descriptor and perform multiples <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/read.2.html">read(2)</a>/<a href="http://www.kernel.org/doc/man-pages/online/pages/man2/write.2.html">write(2)</a> to write out the file content. This operation requires the <a href="http://kernel.org">Kernel</a> to <em>copy</em> data between <em>Kernel</em> and <em>User</em> spaces back and forward which obviously generate an overhead. As solution, the <a href="http://kernel.org">Linux Kernel</a> implements a <em><a href="http://www.linuxjournal.com/article/6345">Zero-Copy</a></em> strategy through the system call <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a>. </em>This system call do not copy data to user space, instead it allows to send it directly to other file descriptor achieving good performance reducing the latency of the old fashioned way described.</p>
<p>In our architecture, the L<em>ogger </em>plugin requires to transfer data through a pipe(2)  (a unidirectional data channel that can be used for interprocess communication). A common mechanism is to use <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/read.2.html">read(2)</a> and <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/write.2.html">write(2)</a> on each end, but in a similar way as <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a></em> works, a new system call takes place for this kind of situation called <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em>. This system call moves data from one point to other without the <em>copy-data </em>overhead. The main difference between <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a></em> and <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em>, is that <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em> requires that one end must be a <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/pipe.2.html">pipe(2)</a></em>.</p>
<p>In my <a href="http://edsiper.linuxchile.cl/blog/2013/02/21/linux-tcp-fastopen-in-your-sockets/">previous post</a>, i mentioned how to usage the new <a href="http://kernel.org">Linux Kernel</a> feature called <a href="http://lwn.net/Articles/508865/">TCP_FASTOPEN</a>, being something very simple to implement, it requires the cooperation of both sides: the client and the server. If you have full control of your networking application (client and server), consider to use <a href="http://lwn.net/Articles/508865/">TCP_FASTOPEN</a>, it will increase performance decreasing the TCP handshake roundtrip.</p>
<p><strong>Monkey Plugins</strong></p>
<p>Based in the architecture and API described, the following plugins are distributed as part of the core:</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Liana</span>: basic sockets connectivity layer</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">PolarSSL</span>: provides a transport layer based in SSL</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Cheetah</span>: plugin that provides a command line interface to query the internals of a running server through a unix socket</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Mandril</span>: security layer that aims to restrict the access by URI strings or sub networks.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Dirlisting</span>: directory listing</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Logger</span>: log writer</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">CGI</span>: old fashioned CGI interface</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">FastCGI</span>: provide fast-cgi support</p>
<p style="padding-left: 30px;">&nbsp;</p>
<p><strong>Bonus track: Full HTTP Stack for web services implementation</strong></p>
<p><img class="alignleft" title="Duda I/O stack" src="http://duda.io/img/duda_architecture.png" alt="" width="250" height="329" />Besides to be a common web server to serve static or dynamic content, <a href="http://monkey-project.com">Monkey</a> is a full stack for the development of web applications. In order to provide an easy API for web application or web services development, we have created <a href="http://duda.io">Duda I/O </a>, which is an event-driven C framework for rapid development based in Monkey stack.</p>
<p><a href="http://duda.io">Duda</a> implements a core API of pseudo-objects and provide extra features  through a packages system, everything in a friendly C API. The most relevant features supported at the moment are WebSocket, JSON, SQLite3, Redis, Base64 and SHA1.</p>
<p>Due to it high performance nature and open source ecosystem around, is being used in production from Embedded Linux products to Big Data solutions. The License of Duda allows to create closed-sourced services or applications and link them to Duda I/O stack at zero cost.</p>
<p>For more details please refer to <a href="http://duda.io">Duda I/O main site</a>.</p>
<p><a href="http://monkey-project.com">Monkey</a> organization believes in <a href="http://en.wikipedia.org/wiki/Open_source">Open Source</a> and is fully committed to create the best networking technology for different needs. If you are interested into participate as a contributor or testing our stack, feel free to reach us on our <a href="http://lists.monkey-project.com/listinfo">mailing list</a>s or irc channel #monkey at irc.freenode.net.</p>
]]></description>
			<content:encoded><![CDATA[<p>this post is all about <a href="http://monkey-project.com">Monkey HTTP server</a>, i consider that is very important that besides we open our source code, the developers be also able to describe the project internals, there is no black magic, just thousands of hours of effort in programming, testing and improvement.</p>
<p><strong>Introduction</strong></p>
<p><a href="http://monkey-project.com">Monkey</a> is an open source project started on 2001 with the goal to learn C, the long story is <a href="http://monkey-project.com/documentation/history">here</a> . Along this years, the code have been improved in many aspects, since nomenclatures to heavy architecture changes, all have been made for good and nowadays thanks to the community of core developers and contributors around the project, <a href="http://monkey-project.com">Monkey</a> is one of the top performance web servers around, and i would claim that the best option for <a href="http://en.wikipedia.org/wiki/Embedded_Linux">Embedded Linux</a>.</p>
<p><strong>Understanding the basics of a human readable protocol: HTTP</strong></p>
<p>The <strong>H</strong>yper <strong>T</strong>ext <strong>T</strong>ransfer <strong>P</strong>rotocol is basically a language with simple grammar to communicate two components: a HTTP client and a HTTP server. In a common context, the communication starts from a client performing a <em>request</em> to the server and for hence the server replying back with some result for the request performed. As a result we can consider a status response plus a content or simply an error.</p>
<p>Each HTTP request performed by the client is composed by a request method, URI, protocol version, and optionally a bunch of headers, so described that, we can say that a server must take care of:</p>
<ul>
<li>Listen for new connections</li>
<li>Accept connections</li>
<li>Once the connection is accepted, start reading the HTTP request sent by the client</li>
<li>Parse the HTTP request, understand what the client wants</li>
<li>Depending of the request type, the sever can: serve some content, close the connection because some exception, proxy back the request to somebody else, etc.</li>
<li>Close the connection or keep it opened waiting for more requests. This depends of the protocol version and client HTTP headers.</li>
</ul>
<p>Depending of the server target, it can be implemented in many ways with different architecture strategies, so the architecture described in this post only aims to describe what have worked better for us in terms of high performance and low resources usage.</p>
<p><strong>Architecture design facts</strong></p>
<ul>
<li><a href="http://monkey-project.com">Monkey</a> is a web server designed with a strong focus in Linux. It do <strong>not</strong> aims to be portable across other operating system, focusing in the top and widely used mainstream operating system allow us to put our energies and effort in one place in the best way, and of course take the most of Linux Kernel to achieve high performance.</li>
<li>Event driven: well known as <strong>asynchronous</strong>, an event driver web server aims to use non-blocking system calls to perform it works reducing the computing time in the user-space context, e.g: if we are sending a file content to a client, we do not block the whole process or thread when sending the data, instead we instruct the kernel through a system call to send N bytes from the file and just notify me where i am able to send more bytes, in the meanwhile.. i process other connections and send other pending data.</li>
<li>Embedded Friendly: our embedded context is Embedded Linux, we care a lot of resources consumption, that means that under a heavy load don&#8217;t use more than 2.5MB of memory. Even <a href="http://monkey-project.com">Monkey</a> binary size is around 80KB, once is load in memory it takes like 350KB, and depending of the load, more resources can be needed.</li>
<li>Small core, flexible API: it implements a basic core to handle <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> protocol, it exposes a flexible API through the plugin interface where is possible to hook plugins for transport layer, security, request type and event handlers.</li>
</ul>
<p><strong>Contexts</strong></p>
<p>In <a href="http://monkey-project.com">Monkey</a>, we have defined two contexts of work: process context and thread context. The process context represents the main process waiting for incoming connections and the scheduler balancing the new connection for the worker threads. The thread context belongs to each thread working the active connections:</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/architecture_general.png"><img class="aligncenter size-full wp-image-1012" title="architecture_general" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/architecture_general.png" alt="" width="600" height="174" /></a></p>
<p>The number of workers are defined in the configuration, it scale properly well in single and multi-core CPUs solutions. There is no need to set thread affinity through CPU masks, the <a href="http://kernel.org">Linux Kernel</a> Scheduler is smart enough to assign CPU time to each worker request, by default all workers are assign to all CPUs.</p>
<blockquote><p>From a system administrator point of view, is possible to assign each worker to a different set of CPUs, but this approach is not suggested unless we are totally aware about what the <a href="http://oreilly.com/catalog/linuxkernel/chapter/ch10.html">Linux scheduler</a> does in terms of interruptions,  context switches and CPU time for Kernel and User space applications. Do it only if you can do it better than the running scheduler.</p></blockquote>
<p><strong>Scheduler</strong></p>
<p>Before to enter in the server loop, the scheduler launch and initialize each worker, taking care of set the initial data structures and the interfaces for the interaction between the components mentioned, this stage involves the creation of a <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue per worker. Is good to mention that each <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue created through <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/epoll_create.2.html">epoll_create(2)</a> is managed through a specific file descriptor.</p>
<p>Once the workers are up and running, the next Scheduler job is to to manage the incoming connections. So for each new connection accepted, it determinate who is the lowest loaded worker and assign the connection to it. The chosen worker is the one that have less connections in its <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> interface, so the scheduler  goes around the worker counters and chose one. On this specific point the scheduler have two file descriptors: the connection file descriptor returned by <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/accept.2.html">accept(2)</a> and the file descriptor that represents the <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> of the chosen worker. So it basically register the new file descriptor in the proper <a href="http://www.kernel.org/doc/man-pages/online/pages/man4/epoll.4.html">epoll(7)</a> queue.</p>
<p><strong>Workers</strong></p>
<p>Each worker or thread, runs in an infinite loop through the <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> interface, which is basically a Linux specific polling mechanism to register, enqueue and notify about events in file descriptors registered by the Scheduler (sockets on this case).</p>
<p>The worker stay in a loop waiting for events in the <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/epoll_wait.2.html">epoll_wait(2)</a> system call. Every time the Scheduler register a new file descriptor, an event will be reported in the worker <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> interface, and it will do same when for subsequent events such as &#8220;there is data available for read&#8221; (EPOLLIN), &#8220;now you can write to the socket&#8221; (EPOLLOUT), &#8220;connection closed&#8221; (EPOLLHUP), etc.</p>
<p>So for each event triggered, the worker keeps a status of the connection to determinate if is a new connection, its receiving the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> request, <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">HTTP</a> request completed, parsing the request or sending out some response. Besides events, every a fixed time of seconds set in the configuration, it checks the connections that timed out due to an incomplete request or another anomaly.</p>
<p><strong>Plugins Architecture</strong></p>
<p>Monkey defines three categories of API where the plugins can hook: Context, Events, Stages and Networking.</p>
<p style="padding-left: 30px;"><strong>Context<br />
</strong>Define callbacks  that can be invoked when the server is starting up, it covers the process and thread contexts described earlier.</p>
<p style="padding-left: 30px;"><strong>Events<br />
</strong>For every type of event reported in a worker loop, a plugin can implement a hook to perform specific actions:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_events.png"><img class="aligncenter size-medium wp-image-1042" title="api_events" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_events-300x106.png" alt="" width="300" height="106" /></a></p>
<p style="padding-left: 30px;"><strong>Stages<br />
</strong>Every new connection, enter in a stage status, so for each step of the HTTP cycle it passed along different phases, and each plugin can hook to a specific one:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_stages.png"><img class="aligncenter size-medium wp-image-1044" title="api_stages" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/api_stages-300x108.png" alt="" width="300" height="108" /></a></p>
<p style="padding-left: 30px;"><strong>Networking<br />
</strong>Monkey is not aware about networking, for hence it intentionally depends of a plugin that provides the transport layer, this approach allows to change from common sockets communication to encrypted one as SSL in a easy manner. The networking plugin only needs to provide the required API functions for the communication:</p>
<p style="padding-left: 30px;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/level_networking.png"><img class="aligncenter size-medium wp-image-1047" title="level_networking" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2013/02/level_networking-300x176.png" alt="" width="300" height="176" /></a></p>
<p><strong>Scaling up</strong></p>
<p>Every time a connection have performed a successful request, this is allocated in a global list of the worker scope (implemented through a <a href="http://linux.die.net/man/3/pthread_key_create">pthread_key</a>). for each event reported, the worker needs to lookup the internal data associated to it, so the file descriptor or socket number  acts like a primary key for the search. The solution of data structure implemented for Monkey v1.2, is the use of <a href="http://www.kernel.org/doc/Documentation/rbtree.txt">red-black tree algorithm</a>. This algorithm have shown to behave very fairly and scalable when handling thousands of active connections per worker, maintaining a good balance between performance and cost.</p>
<p>The cost of each file descriptor lookup is critical for the server performance, having a O(n) solution will work fine for a few connections but under high concurrency a O(log(n)) solution will end up providing the highest performance.</p>
<p><strong>Memory Management</strong></p>
<p>One of the success key to reduce overhead in a server, is to reduce as much as possible the memory allocation requests performed  to the system within the main loop. Current Monkey implementation only performs 1 memory allocation per new connection, if it needed because the incoming request will post too much data, it will allocate more memory as it needs. Other web server solutions implements caching mechanism to reduce even more the memory allocations, as our focus is Embedded Linux we focus into speed at low resources usage, and implement a caching mechanism will increase our costs. So we dropped that common approach to do not abuse of system memory, just a decision based in the <em>target</em>.</p>
<p><strong>Linux Kernel system calls</strong></p>
<p>The <a href="http://kernel.org">Linux Kernel</a> exposes a useful of non-portable set of system calls to achieve high performance when creating networking applications. The first one is <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a>, as described earlier this interface allow to watch a set of file descriptors for certain defined events. Similar solutions like select(2) or poll(2) do not perform so well as <a href="http://www.kernel.org/doc/man-pages/online/pages/man7/epoll.7.html">epoll(7)</a> does.</p>
<p>When sending a static file, the old-fashioned way is to open the file, get the file descriptor and perform multiples <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/read.2.html">read(2)</a>/<a href="http://www.kernel.org/doc/man-pages/online/pages/man2/write.2.html">write(2)</a> to write out the file content. This operation requires the <a href="http://kernel.org">Kernel</a> to <em>copy</em> data between <em>Kernel</em> and <em>User</em> spaces back and forward which obviously generate an overhead. As solution, the <a href="http://kernel.org">Linux Kernel</a> implements a <em><a href="http://www.linuxjournal.com/article/6345">Zero-Copy</a></em> strategy through the system call <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a>. </em>This system call do not copy data to user space, instead it allows to send it directly to other file descriptor achieving good performance reducing the latency of the old fashioned way described.</p>
<p>In our architecture, the L<em>ogger </em>plugin requires to transfer data through a pipe(2)  (a unidirectional data channel that can be used for interprocess communication). A common mechanism is to use <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/read.2.html">read(2)</a> and <a href="http://www.kernel.org/doc/man-pages/online/pages/man2/write.2.html">write(2)</a> on each end, but in a similar way as <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a></em> works, a new system call takes place for this kind of situation called <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em>. This system call moves data from one point to other without the <em>copy-data </em>overhead. The main difference between <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/sendfile.2.html">sendfile(2)</a></em> and <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em>, is that <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/splice.2.html">splice(2)</a></em> requires that one end must be a <em><a href="http://www.kernel.org/doc/man-pages/online/pages/man2/pipe.2.html">pipe(2)</a></em>.</p>
<p>In my <a href="http://edsiper.linuxchile.cl/blog/2013/02/21/linux-tcp-fastopen-in-your-sockets/">previous post</a>, i mentioned how to usage the new <a href="http://kernel.org">Linux Kernel</a> feature called <a href="http://lwn.net/Articles/508865/">TCP_FASTOPEN</a>, being something very simple to implement, it requires the cooperation of both sides: the client and the server. If you have full control of your networking application (client and server), consider to use <a href="http://lwn.net/Articles/508865/">TCP_FASTOPEN</a>, it will increase performance decreasing the TCP handshake roundtrip.</p>
<p><strong>Monkey Plugins</strong></p>
<p>Based in the architecture and API described, the following plugins are distributed as part of the core:</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Liana</span>: basic sockets connectivity layer</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">PolarSSL</span>: provides a transport layer based in SSL</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Cheetah</span>: plugin that provides a command line interface to query the internals of a running server through a unix socket</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Mandril</span>: security layer that aims to restrict the access by URI strings or sub networks.</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Dirlisting</span>: directory listing</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">Logger</span>: log writer</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">CGI</span>: old fashioned CGI interface</p>
<p style="padding-left: 30px;"><span style="text-decoration: underline;">FastCGI</span>: provide fast-cgi support</p>
<p style="padding-left: 30px;">&nbsp;</p>
<p><strong>Bonus track: Full HTTP Stack for web services implementation</strong></p>
<p><img class="alignleft" title="Duda I/O stack" src="http://duda.io/img/duda_architecture.png" alt="" width="250" height="329" />Besides to be a common web server to serve static or dynamic content, <a href="http://monkey-project.com">Monkey</a> is a full stack for the development of web applications. In order to provide an easy API for web application or web services development, we have created <a href="http://duda.io">Duda I/O </a>, which is an event-driven C framework for rapid development based in Monkey stack.</p>
<p><a href="http://duda.io">Duda</a> implements a core API of pseudo-objects and provide extra features  through a packages system, everything in a friendly C API. The most relevant features supported at the moment are WebSocket, JSON, SQLite3, Redis, Base64 and SHA1.</p>
<p>Due to it high performance nature and open source ecosystem around, is being used in production from Embedded Linux products to Big Data solutions. The License of Duda allows to create closed-sourced services or applications and link them to Duda I/O stack at zero cost.</p>
<p>For more details please refer to <a href="http://duda.io">Duda I/O main site</a>.</p>
<p><a href="http://monkey-project.com">Monkey</a> organization believes in <a href="http://en.wikipedia.org/wiki/Open_source">Open Source</a> and is fully committed to create the best networking technology for different needs. If you are interested into participate as a contributor or testing our stack, feel free to reach us on our <a href="http://lists.monkey-project.com/listinfo">mailing list</a>s or irc channel #monkey at irc.freenode.net.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2013/02/27/architecture-of-a-linux-based-web-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linux TCP FASTOPEN in your sockets</title>
		<link>http://edsiper.linuxchile.cl/blog/2013/02/21/linux-tcp-fastopen-in-your-sockets/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2013/02/21/linux-tcp-fastopen-in-your-sockets/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 03:46:35 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Linux Kernel]]></category>
		<category><![CDATA[Monkey]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=943</guid>
12345		<description><![CDATA[<p>Few years ago the concept of TCP_FASTOPEN (TFO) was introduced as a solution to improve performance on TCP connections reducing one roundtrip of the handshake process. The first operating system that implements TFO is Linux and have been demonstrated good improvements when used in a common network.</p>
<p>The implementation in the <a href="http://kernel.org">Linux Kernels</a> have been made by parts, being Linux Kernel 3.6.1 the first one into implement the client side requirements and then Linux Kernel 3.7 who implements the server side socket behavior.</p>
<p><strong>Client side</strong></p>
<p>In a common TCP client flow, the following calls takes place:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create socket file descriptor */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span>domain<span style="color: #339933;">,</span> type<span style="color: #339933;">,</span> protocol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect to the target server/port */</span>
connect<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span>...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* send some data */</span>
send<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* wait for some reply and read into a local buffer */</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>bytes  <span style="color: #339933;">=</span> recv<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When using TCP_FASTOPEN the behavior its a little different. You not longer need to use connect(2), instead you use sendto(2) and it also gives you the opportunity to let the Kernel buffer some initial outgoing data. For short, the call sendto(2) its like an implicit connect(2) and send/write(2) same time:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect and send out some data */</span>
sendto<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> buf_len<span style="color: #339933;">,</span> MSG_FASTOPEN<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* write more data */</span>
send<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* wait for some reply and read into a local buffer */</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>bytes  <span style="color: #339933;">=</span> recv<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p lang="C"><strong>Server side</strong></p>
<p lang="C">A common (old-fashion) TCP server is created with the following calls:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect and send out some data */</span>
bind<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> addr<span style="color: #339933;">,</span> addrlen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* this socket will listen for incoming connections */</span>
listen<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> backlog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Adding TCP_FASTOPEN support to the server side code is very easy, the required changes are minimum, you only need to set a new socket option between bind(2) and listen(2):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* a hint value for the Kernel */</span>
<span style="color: #993333;">int</span> qlen <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* bind the address */</span>
bind<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> addr<span style="color: #339933;">,</span> addrlen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* change the socket options to TCO_FASTOPEN */</span>
setsockopt<span style="color: #009900;">&#40;</span>sockfd<span style="color: #339933;">,</span> SOL_TCP<span style="color: #339933;">,</span> TCP_FASTOPEN<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>qlen<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>qlen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* this socket will listen for incoming connections */</span>
listen<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> backlog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Required macros</strong></p>
<p>Even you are running the latest Linux Kernel 3.8, you will face some problems as in most of the cases the required macro values for  TCP_FASTOPEN and MSG_FASTOPEN will not be available  at compile time. As a workaround you can include the following code in one of your header files:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* 
 * A generic protection in case you include this 
 * from multiple files 
 */</span>
<span style="color: #339933;">#ifndef _KERNEL_FASTOPEN</span>
<span style="color: #339933;">#define _KERNEL_FASTOPEN</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* conditional define for TCP_FASTOPEN */</span>
<span style="color: #339933;">#ifndef TCP_FASTOPEN</span>
<span style="color: #339933;">#define TCP_FASTOPEN   23</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* conditional define for MSG_FASTOPEN */</span>
<span style="color: #339933;">#ifndef MSG_FASTOPEN</span>
<span style="color: #339933;">#define MSG_FASTOPEN   0x20000000</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#endif</span></pre></td></tr></table></div>

<p><strong>Enabling TCP_FASTOPEN in your Kernel</strong></p>
<p>By default the TCP_FASTOPEN feature is not enabled at runtime (unless you instructed that in the sysctl.conf file). Before to test this new feature make sure is enabled with the following command:</p>
<blockquote><p># echo 1 &gt; /proc/sys/net/ipv4/tcp_fastopen</p></blockquote>
<p>If you try to use a client with TCP_FASTOPEN enabled, its mandatory that the server have this same option set in the listener socket, otherwise the client will faill at the connection phase (due to protocol mismatch).</p>
<p>For a TCP_FASTOPEN server, it does not matter if the client uses the new protocol or not, it will work anyways. So if you develop a TCP server you can give it a try adding a simple system call to add this feature. If your project is open source, feel free to use the header macros example provided above.</p>
<p>Btw, of course <a href="http://monkey-project.com">Monkey Web Server</a> have added this feature recently in our <a href="http://git.monkey-project.com/?p=monkey;a=commitdiff;h=5a6696bf90a9b563c1a7c22752ac171102b13462">development repository</a></p>
<p><strong>References</strong></p>
<ul>
<li><a title="Linux Weekly News" href="http://lwn.net/Articles/508865/">http://lwn.net/Articles/508865/</a></li>
<li><a title="Kernel Newbies" href="http://kernelnewbies.org/Linux_3.7#head-cd32b65674184083465d349ad6d772c828fbbd8b">http://kernelnewbies.org/Linux_3.7#head-cd32b65674184083465d349ad6d772c828fbbd8b</a><a href="http://git.monkey-project.com/?p=monkey;a=object;h=cd32b65674184083465d349ad6d772c828fbbd8b"></a></li>
</ul>
<p><strong><br />
</strong></p>
]]></description>
			<content:encoded><![CDATA[<p>Few years ago the concept of TCP_FASTOPEN (TFO) was introduced as a solution to improve performance on TCP connections reducing one roundtrip of the handshake process. The first operating system that implements TFO is Linux and have been demonstrated good improvements when used in a common network.</p>
<p>The implementation in the <a href="http://kernel.org">Linux Kernels</a> have been made by parts, being Linux Kernel 3.6.1 the first one into implement the client side requirements and then Linux Kernel 3.7 who implements the server side socket behavior.</p>
<p><strong>Client side</strong></p>
<p>In a common TCP client flow, the following calls takes place:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create socket file descriptor */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span>domain<span style="color: #339933;">,</span> type<span style="color: #339933;">,</span> protocol<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect to the target server/port */</span>
connect<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span>...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* send some data */</span>
send<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* wait for some reply and read into a local buffer */</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>bytes  <span style="color: #339933;">=</span> recv<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When using TCP_FASTOPEN the behavior its a little different. You not longer need to use connect(2), instead you use sendto(2) and it also gives you the opportunity to let the Kernel buffer some initial outgoing data. For short, the call sendto(2) its like an implicit connect(2) and send/write(2) same time:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect and send out some data */</span>
sendto<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buffer<span style="color: #339933;">,</span> buf_len<span style="color: #339933;">,</span> MSG_FASTOPEN<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* write more data */</span>
send<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* wait for some reply and read into a local buffer */</span> 
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>bytes  <span style="color: #339933;">=</span> recv<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> ...<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p lang="C"><strong>Server side</strong></p>
<p lang="C">A common (old-fashion) TCP server is created with the following calls:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* connect and send out some data */</span>
bind<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> addr<span style="color: #339933;">,</span> addrlen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* this socket will listen for incoming connections */</span>
listen<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> backlog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Adding TCP_FASTOPEN support to the server side code is very easy, the required changes are minimum, you only need to set a new socket option between bind(2) and listen(2):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* a hint value for the Kernel */</span>
<span style="color: #993333;">int</span> qlen <span style="color: #339933;">=</span> <span style="color: #0000dd;">5</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* create the socket */</span>
fd <span style="color: #339933;">=</span> socket<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* bind the address */</span>
bind<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> addr<span style="color: #339933;">,</span> addrlen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* change the socket options to TCO_FASTOPEN */</span>
setsockopt<span style="color: #009900;">&#40;</span>sockfd<span style="color: #339933;">,</span> SOL_TCP<span style="color: #339933;">,</span> TCP_FASTOPEN<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>qlen<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>qlen<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* this socket will listen for incoming connections */</span>
listen<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> backlog<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Required macros</strong></p>
<p>Even you are running the latest Linux Kernel 3.8, you will face some problems as in most of the cases the required macro values for  TCP_FASTOPEN and MSG_FASTOPEN will not be available  at compile time. As a workaround you can include the following code in one of your header files:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* 
 * A generic protection in case you include this 
 * from multiple files 
 */</span>
<span style="color: #339933;">#ifndef _KERNEL_FASTOPEN</span>
<span style="color: #339933;">#define _KERNEL_FASTOPEN</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* conditional define for TCP_FASTOPEN */</span>
<span style="color: #339933;">#ifndef TCP_FASTOPEN</span>
<span style="color: #339933;">#define TCP_FASTOPEN   23</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* conditional define for MSG_FASTOPEN */</span>
<span style="color: #339933;">#ifndef MSG_FASTOPEN</span>
<span style="color: #339933;">#define MSG_FASTOPEN   0x20000000</span>
<span style="color: #339933;">#endif</span>
&nbsp;
<span style="color: #339933;">#endif</span></pre></td></tr></table></div>

<p><strong>Enabling TCP_FASTOPEN in your Kernel</strong></p>
<p>By default the TCP_FASTOPEN feature is not enabled at runtime (unless you instructed that in the sysctl.conf file). Before to test this new feature make sure is enabled with the following command:</p>
<blockquote><p># echo 1 &gt; /proc/sys/net/ipv4/tcp_fastopen</p></blockquote>
<p>If you try to use a client with TCP_FASTOPEN enabled, its mandatory that the server have this same option set in the listener socket, otherwise the client will faill at the connection phase (due to protocol mismatch).</p>
<p>For a TCP_FASTOPEN server, it does not matter if the client uses the new protocol or not, it will work anyways. So if you develop a TCP server you can give it a try adding a simple system call to add this feature. If your project is open source, feel free to use the header macros example provided above.</p>
<p>Btw, of course <a href="http://monkey-project.com">Monkey Web Server</a> have added this feature recently in our <a href="http://git.monkey-project.com/?p=monkey;a=commitdiff;h=5a6696bf90a9b563c1a7c22752ac171102b13462">development repository</a></p>
<p><strong>References</strong></p>
<ul>
<li><a title="Linux Weekly News" href="http://lwn.net/Articles/508865/">http://lwn.net/Articles/508865/</a></li>
<li><a title="Kernel Newbies" href="http://kernelnewbies.org/Linux_3.7#head-cd32b65674184083465d349ad6d772c828fbbd8b">http://kernelnewbies.org/Linux_3.7#head-cd32b65674184083465d349ad6d772c828fbbd8b</a><a href="http://git.monkey-project.com/?p=monkey;a=object;h=cd32b65674184083465d349ad6d772c828fbbd8b"></a></li>
</ul>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2013/02/21/linux-tcp-fastopen-in-your-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GSoC Mentors Summit 2012 at Google Plex</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/10/31/gsoc-mentors-summit-2012-at-google-plex/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/10/31/gsoc-mentors-summit-2012-at-google-plex/#comments</comments>
		<pubDate>Wed, 31 Oct 2012 06:12:44 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Summer of Code]]></category>
		<category><![CDATA[Monkey]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=883</guid>
12345		<description><![CDATA[<p>As a member of <a href="http://monkey-project.com">Monkey Project</a> which have joined as a mentoring organization for the <a href="http://www.google-melange.com/gsoc/homepage/google/gsoc2012">Google Summer of Code 2012</a> program, we were invited to assist to the Mentors Summit conference at <a href="http://en.wikipedia.org/wiki/Googleplex">Googleplex</a> in California, US. Two members of our community flight to Google to represent the organization: <a href="http://tty.cl/authors/freyes.html">Felipe Reyes</a> and <a href="http://edsiper.linuxchile.cl">I</a>.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0415.jpg"><img class="aligncenter size-medium wp-image-895" title="Felipe Reyes and I at Google" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0415-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Be part of a project who was selected for GSoC 2012 is really exciting, because of the recognition as a solid open source project and the given opportunity to mentor three students around the world and instruct them about collaboration and core development in our project. It was a hard work and at the end, the other exciting part begins: the Mentors Summit.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0413.jpg"><img class="size-medium wp-image-904 aligncenter" title="Google Plex" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0413-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>The event took place in California, it started on Friday 19th at Wild Palms hotel with an open dinner around the pool and free beer for everyone, no formal things, just eat together and met great people behind each project <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On Saturday 20th, we went to the famous Googleplex, to take breakfast before the event starts, and i cannot omit to mention that is TRUE, <a href="http://www.google.com">Google</a> have a great free-food services for everyone, i was amazed with the great details that they have for their employees, the place is well designed with a lot of colors around and the general campus is pretty friendly.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0436.jpg"><img class="aligncenter size-medium wp-image-897" title="Food!" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0436-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0393.jpg"><img class="aligncenter size-medium wp-image-908" title="Handshaking everyone" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0393-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>We ran into different (and parallel) sessions with topics about GSoC it self and technical things about each project, it was an <a href="http://en.wikipedia.org/wiki/Unconference">unconference</a> so each people proposed their own topic in a board with a flexible schedule. Honestly i was not prepared to give a talk as i was not aware that we could propose technical sessions.. but well, we sign up for a talk about <a href="http://monkey-project.com">Monkey</a>, we mostly talked about project internals and <a href="http://duda.io">Duda web services</a>, it went pretty well, interesting discussions about the project were raised and new horizons could come&#8230;</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0459.jpg"><img class="aligncenter size-medium wp-image-893" title="Monkey's Talk" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0459-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>I attended some technical and GSoC sessions, it was a really good opportunity for Google and the mentoring organizations to discuss ways to improve the program, i am impressed about how the Open Source department is committed to help organizations to grow and create networks with other projects. Its a difficult work but the synergy around people involved in this program makes things easier, everybody was open to contribute, i would say that GSoC more than a program is a real community, an open program it self.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0437.jpg"><img class="aligncenter size-medium wp-image-901" title="GSoC Meeting" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0437-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0381.jpg"><img class="aligncenter size-medium wp-image-924" title="planing " src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0381-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>What a surprise, I finally met the good guys from the <a href="http://osuosl.org/">Open Source Lab</a>, who we have been working together with us for about two years, they provide and maintain our hosting infrastructure, thanks!. In the right James Lopeman from <a href="http://kernel.org">Kernel.org</a> .</p>
<div id="attachment_932" class="wp-caption aligncenter" style="width: 310px"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0406.jpg"><img class="size-medium wp-image-932" title="OSUOSL and Kernel.org" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0406-300x200.jpg" alt="" width="300" height="200" /></a><p class="wp-caption-text">OSL at left, Kernel.org at right</p></div>
<p>&nbsp;</p>
<p>At night, social activities continues in the hotel with a new dinner around the pool and free drinks, have fun, share different technical interests and more and more&#8230;</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0519.jpg"><img class="size-thumbnail wp-image-910 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0519-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0514.jpg"><img class="size-thumbnail wp-image-911 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0514-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0503.jpg"><img class="size-thumbnail wp-image-913 alignleft" title="fun" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0503-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517.jpg"></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517.jpg"><img class="size-thumbnail wp-image-915 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0510.jpg"><img class="size-thumbnail wp-image-918 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0510-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0491.jpg"><img class="alignleft size-thumbnail wp-image-921" title="more beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0491-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="text-align: center;">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Summary</h3>
<p>A great event, i went without clear expectations it was something totally great, i have attended many conferences in the past and i have to say that this have been on the best in terms of organization, people and objectives.</p>
<p>I hope Google Summer of Code runs again in 2013, if so, we will do the best to get <a href="http://monkey-project.com">Monkey</a> in.</p>
]]></description>
			<content:encoded><![CDATA[<p>As a member of <a href="http://monkey-project.com">Monkey Project</a> which have joined as a mentoring organization for the <a href="http://www.google-melange.com/gsoc/homepage/google/gsoc2012">Google Summer of Code 2012</a> program, we were invited to assist to the Mentors Summit conference at <a href="http://en.wikipedia.org/wiki/Googleplex">Googleplex</a> in California, US. Two members of our community flight to Google to represent the organization: <a href="http://tty.cl/authors/freyes.html">Felipe Reyes</a> and <a href="http://edsiper.linuxchile.cl">I</a>.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0415.jpg"><img class="aligncenter size-medium wp-image-895" title="Felipe Reyes and I at Google" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0415-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>Be part of a project who was selected for GSoC 2012 is really exciting, because of the recognition as a solid open source project and the given opportunity to mentor three students around the world and instruct them about collaboration and core development in our project. It was a hard work and at the end, the other exciting part begins: the Mentors Summit.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0413.jpg"><img class="size-medium wp-image-904 aligncenter" title="Google Plex" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0413-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>The event took place in California, it started on Friday 19th at Wild Palms hotel with an open dinner around the pool and free beer for everyone, no formal things, just eat together and met great people behind each project <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>On Saturday 20th, we went to the famous Googleplex, to take breakfast before the event starts, and i cannot omit to mention that is TRUE, <a href="http://www.google.com">Google</a> have a great free-food services for everyone, i was amazed with the great details that they have for their employees, the place is well designed with a lot of colors around and the general campus is pretty friendly.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0436.jpg"><img class="aligncenter size-medium wp-image-897" title="Food!" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0436-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0393.jpg"><img class="aligncenter size-medium wp-image-908" title="Handshaking everyone" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0393-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>We ran into different (and parallel) sessions with topics about GSoC it self and technical things about each project, it was an <a href="http://en.wikipedia.org/wiki/Unconference">unconference</a> so each people proposed their own topic in a board with a flexible schedule. Honestly i was not prepared to give a talk as i was not aware that we could propose technical sessions.. but well, we sign up for a talk about <a href="http://monkey-project.com">Monkey</a>, we mostly talked about project internals and <a href="http://duda.io">Duda web services</a>, it went pretty well, interesting discussions about the project were raised and new horizons could come&#8230;</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0459.jpg"><img class="aligncenter size-medium wp-image-893" title="Monkey's Talk" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0459-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>I attended some technical and GSoC sessions, it was a really good opportunity for Google and the mentoring organizations to discuss ways to improve the program, i am impressed about how the Open Source department is committed to help organizations to grow and create networks with other projects. Its a difficult work but the synergy around people involved in this program makes things easier, everybody was open to contribute, i would say that GSoC more than a program is a real community, an open program it self.</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0437.jpg"><img class="aligncenter size-medium wp-image-901" title="GSoC Meeting" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0437-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0381.jpg"><img class="aligncenter size-medium wp-image-924" title="planing " src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0381-300x200.jpg" alt="" width="300" height="200" /></a></p>
<p>What a surprise, I finally met the good guys from the <a href="http://osuosl.org/">Open Source Lab</a>, who we have been working together with us for about two years, they provide and maintain our hosting infrastructure, thanks!. In the right James Lopeman from <a href="http://kernel.org">Kernel.org</a> .</p>
<div id="attachment_932" class="wp-caption aligncenter" style="width: 310px"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0406.jpg"><img class="size-medium wp-image-932" title="OSUOSL and Kernel.org" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0406-300x200.jpg" alt="" width="300" height="200" /></a><p class="wp-caption-text">OSL at left, Kernel.org at right</p></div>
<p>&nbsp;</p>
<p>At night, social activities continues in the hotel with a new dinner around the pool and free drinks, have fun, share different technical interests and more and more&#8230;</p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0519.jpg"><img class="size-thumbnail wp-image-910 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0519-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0514.jpg"><img class="size-thumbnail wp-image-911 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0514-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0503.jpg"><img class="size-thumbnail wp-image-913 alignleft" title="fun" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0503-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517.jpg"></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517.jpg"><img class="size-thumbnail wp-image-915 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0517-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0510.jpg"><img class="size-thumbnail wp-image-918 alignleft" title="beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0510-150x150.jpg" alt="" width="150" height="150" /></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0491.jpg"><img class="alignleft size-thumbnail wp-image-921" title="more beer" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/10/DSC_0491-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p style="text-align: center;">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3>Summary</h3>
<p>A great event, i went without clear expectations it was something totally great, i have attended many conferences in the past and i have to say that this have been on the best in terms of organization, people and objectives.</p>
<p>I hope Google Summer of Code runs again in 2013, if so, we will do the best to get <a href="http://monkey-project.com">Monkey</a> in.</p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/10/31/gsoc-mentors-summit-2012-at-google-plex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duda I/O: Websocket Chat</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/09/24/duda-io-websocket-chat/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/09/24/duda-io-websocket-chat/#comments</comments>
		<pubDate>Mon, 24 Sep 2012 16:20:48 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Duda I/O]]></category>
		<category><![CDATA[Monkey]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=857</guid>
12345		<description><![CDATA[<p>There is not much to explain, <a href="http://tools.ietf.org/html/rfc6455">Websocket</a> is being used widely for realtime notifications over the web and <a href="http://duda.io">Duda I/O</a> supports websocket through a package. I have written a simple chat example at server side to demostrate how it can be used, the front-end part is a tweaked client where i just performed minor modifications:</p>
<p style="text-align: left;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat.png"></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat1.png"><img class="aligncenter size-full wp-image-860" title="duda_websocketchat" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat1.png" alt="" width="540" height="256" /></a></p>
<p style="text-align: left;">The interest part is the service code side:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;webservice.h&quot;</span>
<span style="color: #339933;">#include &quot;packages/websocket/websocket.h&quot;</span>
&nbsp;
DUDA_REGISTER<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Duda I/O Examples&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;WebSocket Chat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> cb_on_message<span style="color: #009900;">&#40;</span>duda_request_t <span style="color: #339933;">*</span>dr<span style="color: #339933;">,</span> ws_request_t <span style="color: #339933;">*</span>wr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    websocket<span style="color: #339933;">-&gt;</span>broadcast<span style="color: #009900;">&#40;</span>wr<span style="color: #339933;">,</span> wr<span style="color: #339933;">-&gt;</span>payload<span style="color: #339933;">,</span> wr<span style="color: #339933;">-&gt;</span>payload_len<span style="color: #339933;">,</span> WS_OPCODE_TEXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cb_handshake<span style="color: #009900;">&#40;</span>duda_request_t <span style="color: #339933;">*</span>dr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    websocket<span style="color: #339933;">-&gt;</span>handshake<span style="color: #009900;">&#40;</span>dr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> duda_main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* Load the websocket package */</span>
    duda_load_package<span style="color: #009900;">&#40;</span>websocket<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;websocket&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*
     * Define a callback, on every websocket message received,
     * trigger cb_on_message.
     */</span>
    websocket<span style="color: #339933;">-&gt;</span>set_callback<span style="color: #009900;">&#40;</span>WS_ON_MESSAGE<span style="color: #339933;">,</span> cb_on_message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Associate a static URL with a callback */</span>
    map<span style="color: #339933;">-&gt;</span>static_add<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/handshake/&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;cb_handshake&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Initialize the broadcaster interface */</span>
    websocket<span style="color: #339933;">-&gt;</span>broadcaster<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In duda_main() we initialize the web service, loading the websocket package and setting a callback function to invoke when a websocket message arrives. Then we map the URL path who wWebsocket handshake and finally we instruct the websocket package to launch the <strong>Broadcaster</strong> service, this last one is necessary if you want to send broadcast messages.</p>
<p><strong>Getting started</strong><br />
If you want a simple steps to try this example do:</p>
<ul>
<li>git clone git://git.monkey-project.com/dudac</li>
<li>git clone git://git.monkey-project.com/duda-examples</li>
<li>cd dudac/ &#038;&#038; ./dudac -g</li>
<li>./dudac -w /path/to/duda-examples/050_websocket_chat/</li>
</ul>
<p> Now you can point your browser at http://localhost:2001/wschat/</p>
<p><strong>Documentation</strong></p>
<p>For more details about the Websocket package and its available methods, please refer to the <a href="http://duda.io/api/packages/websocket.html">Websocket API documentation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>There is not much to explain, <a href="http://tools.ietf.org/html/rfc6455">Websocket</a> is being used widely for realtime notifications over the web and <a href="http://duda.io">Duda I/O</a> supports websocket through a package. I have written a simple chat example at server side to demostrate how it can be used, the front-end part is a tweaked client where i just performed minor modifications:</p>
<p style="text-align: left;"><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat.png"></a><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat1.png"><img class="aligncenter size-full wp-image-860" title="duda_websocketchat" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_websocketchat1.png" alt="" width="540" height="256" /></a></p>
<p style="text-align: left;">The interest part is the service code side:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;webservice.h&quot;</span>
<span style="color: #339933;">#include &quot;packages/websocket/websocket.h&quot;</span>
&nbsp;
DUDA_REGISTER<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Duda I/O Examples&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;WebSocket Chat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">void</span> cb_on_message<span style="color: #009900;">&#40;</span>duda_request_t <span style="color: #339933;">*</span>dr<span style="color: #339933;">,</span> ws_request_t <span style="color: #339933;">*</span>wr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    websocket<span style="color: #339933;">-&gt;</span>broadcast<span style="color: #009900;">&#40;</span>wr<span style="color: #339933;">,</span> wr<span style="color: #339933;">-&gt;</span>payload<span style="color: #339933;">,</span> wr<span style="color: #339933;">-&gt;</span>payload_len<span style="color: #339933;">,</span> WS_OPCODE_TEXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> cb_handshake<span style="color: #009900;">&#40;</span>duda_request_t <span style="color: #339933;">*</span>dr<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    websocket<span style="color: #339933;">-&gt;</span>handshake<span style="color: #009900;">&#40;</span>dr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> duda_main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #808080; font-style: italic;">/* Load the websocket package */</span>
    duda_load_package<span style="color: #009900;">&#40;</span>websocket<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;websocket&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/*
     * Define a callback, on every websocket message received,
     * trigger cb_on_message.
     */</span>
    websocket<span style="color: #339933;">-&gt;</span>set_callback<span style="color: #009900;">&#40;</span>WS_ON_MESSAGE<span style="color: #339933;">,</span> cb_on_message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Associate a static URL with a callback */</span>
    map<span style="color: #339933;">-&gt;</span>static_add<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/handshake/&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;cb_handshake&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;">/* Initialize the broadcaster interface */</span>
    websocket<span style="color: #339933;">-&gt;</span>broadcaster<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In duda_main() we initialize the web service, loading the websocket package and setting a callback function to invoke when a websocket message arrives. Then we map the URL path who wWebsocket handshake and finally we instruct the websocket package to launch the <strong>Broadcaster</strong> service, this last one is necessary if you want to send broadcast messages.</p>
<p><strong>Getting started</strong><br />
If you want a simple steps to try this example do:</p>
<ul>
<li>git clone git://git.monkey-project.com/dudac</li>
<li>git clone git://git.monkey-project.com/duda-examples</li>
<li>cd dudac/ &#038;&#038; ./dudac -g</li>
<li>./dudac -w /path/to/duda-examples/050_websocket_chat/</li>
</ul>
<p> Now you can point your browser at http://localhost:2001/wschat/</p>
<p><strong>Documentation</strong></p>
<p>For more details about the Websocket package and its available methods, please refer to the <a href="http://duda.io/api/packages/websocket.html">Websocket API documentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/09/24/duda-io-websocket-chat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duda I/O</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/09/19/duda-io/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/09/19/duda-io/#comments</comments>
		<pubDate>Wed, 19 Sep 2012 03:57:48 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Announces]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Monkey]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=824</guid>
12345		<description><![CDATA[<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_architecture.png"><img class="size-full wp-image-827 alignright" title="duda_architecture" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_architecture.png" alt="" width="200" height="263" /></a>Since a few months i have been working in a C web services framework called <a href="http://duda.io">Duda I/O</a>, this can be considered a child of <a href="http://monkey-project.com">Monkey Project</a>.  Duda I/O runs on top of Monkey and aims to expose a C friendly API for building fast and scalable web services. It&#8217;s totally open source under the LGPLv2.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;">Framework Components</span></h3>
<p><span style="text-decoration: underline;"><br />
</span></p>
<p><strong>DudaC: </strong>Formally <em>Duda Client Manager</em>, it is a helper for the development and easy deployment of web services. It takes care of the setup of the development environment cloning the respective stack components and building each one. It also allows to run a web service on fly just pointing to it source code.</p>
<dl><strong>Duda Plugin: </strong>This plugin is an extension for <a href="http://monkey-project.com/">Monkey Web Server</a>, it mainly wraps the Monkey API and expose a more friendly C API for building web services. This plugin also takes care to hide the complexity of the HTTP stack in terms of threading, balancing and asynchronous socket events.</p>
<p><strong>HTTP Server: </strong>As mentioned earlier, the HTTP stack is powered by <a href="http://monkey-project.com/">Monkey</a>, a high performant and <em>Open Source Web Server</em>. Monkey is a HTTP/1.1 non-blocking web server implmented through a strategy of a number of fixed threads each one holding their own events queue. Its pretty scalable and can take the most of SMP systems. 
<dd>
</dd>
<p><strong>Web Services: </strong>A <em>Web Service</em> is a software component built on top of Duda Plugin API which execute different instructions through a mapping of HTTP URL requests and callback functions. In technical terms is a shared library loaded by Duda on runtime.</p>
<p>&nbsp;</p>
<h3><strong><span style="text-decoration: underline;">Features</span></strong></h3>
<p><strong><span style="text-decoration: underline;"><br />
</span></strong></p>
</dl>
<p><strong>Non-blocking: </strong>The whole HTTP stack is based in the non-blocking model for sockets, this means that it works on top of asynchronous events. Each working thread can scale to thousands of active connections. Is good to mention that a non-blocking model will not reduce the computing time or delays caused by the blocking calls used in your web service.</p>
<p><strong>Lightweight: </strong>For a normal web service running, the global size of the running components in memory can be around of 400KB. The memory used will depends of your web service implementation and packages loaded. The stack components as Duda and Monkey aims to be lightweight and optimize the resources used.</p>
<p><strong>Service oriented:</strong> One of the main features of Duda, is that it allow to register multiple web services under the same HTTP instance, as well each service can be assigned to a different Virtual Host (a Virtual Host can hold multiple web services).</p>
<p>Each service can map static URLs to specific callback functions or use the Map interfaces provided by Duda, this last one is pretty much similar to REST and provides a very useful set of methods to handle each request resources such as: methods, parameters and body content.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;"><strong>API Objects</strong></span></h3>
<p><span style="text-decoration: underline;"><strong><br />
</strong></span></p>
<p>When building/running a web service, a set of C pseudo-objects are exported to perform the setup and define callbacks for certains events, as well many objects are helpers to build responses and minimize the effort for the developer. Some API Objects available are:</p>
<ul>
<li>Console</li>
<li>Cookie</li>
<li>Event</li>
<li>Param</li>
<li>Response</li>
<li>Request</li>
<li>Session</li>
</ul>
<p>Each object expose a set of methods, for more details about the available methods for each objects refer to the <a href="http://duda.io/api/">API documentation</a>.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;">API Packages</span></h3>
<p><span style="text-decoration: underline;"><br />
</span></p>
<p>Besides the built-in API Objects available, Duda supports a packages system which aims to load on demand external objects to extend the core API capabilities. Some packages available are the following:</p>
<ul>
<li>Base64</li>
<li>JSON</li>
<li>SHA1</li>
<li>SQLite</li>
<li>Websocket</li>
</ul>
<p>Packages are included in Duda per users demand, if you miss some specific package functionality let us know to consider it development and further inclusion.</p>
<p>If you want to know more about Duda please refer to the following links:</p>
<ul>
<li>Main site: <a href="http://duda.io/">http://duda.io</a></li>
<li>Documentation: <a href="http://duda.io/documentation/overview">http://duda.io/documentation/overview</a></li>
<li>Mailing list:     <a href="http://lists.monkey-project.com/listinfo/duda">http://lists.monkey-project.com/listinfo/duda</a></li>
<li>Hello world in 5 steps: <a href="http://duda.io/documentation/hello_world_5_steps">http://duda.io/documentation/hello_world_5_steps</a></li>
</ul>
<p>more news coming soon, if you want to stay tuned make sure to register in the new mailing list&#8230;</p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_architecture.png"><img class="size-full wp-image-827 alignright" title="duda_architecture" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/09/duda_architecture.png" alt="" width="200" height="263" /></a>Since a few months i have been working in a C web services framework called <a href="http://duda.io">Duda I/O</a>, this can be considered a child of <a href="http://monkey-project.com">Monkey Project</a>.  Duda I/O runs on top of Monkey and aims to expose a C friendly API for building fast and scalable web services. It&#8217;s totally open source under the LGPLv2.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;">Framework Components</span></h3>
<p><span style="text-decoration: underline;"><br />
</span></p>
<p><strong>DudaC: </strong>Formally <em>Duda Client Manager</em>, it is a helper for the development and easy deployment of web services. It takes care of the setup of the development environment cloning the respective stack components and building each one. It also allows to run a web service on fly just pointing to it source code.</p>
<dl><strong>Duda Plugin: </strong>This plugin is an extension for <a href="http://monkey-project.com/">Monkey Web Server</a>, it mainly wraps the Monkey API and expose a more friendly C API for building web services. This plugin also takes care to hide the complexity of the HTTP stack in terms of threading, balancing and asynchronous socket events.</p>
<p><strong>HTTP Server: </strong>As mentioned earlier, the HTTP stack is powered by <a href="http://monkey-project.com/">Monkey</a>, a high performant and <em>Open Source Web Server</em>. Monkey is a HTTP/1.1 non-blocking web server implmented through a strategy of a number of fixed threads each one holding their own events queue. Its pretty scalable and can take the most of SMP systems. 
<dd>
</dd>
<p><strong>Web Services: </strong>A <em>Web Service</em> is a software component built on top of Duda Plugin API which execute different instructions through a mapping of HTTP URL requests and callback functions. In technical terms is a shared library loaded by Duda on runtime.</p>
<p>&nbsp;</p>
<h3><strong><span style="text-decoration: underline;">Features</span></strong></h3>
<p><strong><span style="text-decoration: underline;"><br />
</span></strong></p>
</dl>
<p><strong>Non-blocking: </strong>The whole HTTP stack is based in the non-blocking model for sockets, this means that it works on top of asynchronous events. Each working thread can scale to thousands of active connections. Is good to mention that a non-blocking model will not reduce the computing time or delays caused by the blocking calls used in your web service.</p>
<p><strong>Lightweight: </strong>For a normal web service running, the global size of the running components in memory can be around of 400KB. The memory used will depends of your web service implementation and packages loaded. The stack components as Duda and Monkey aims to be lightweight and optimize the resources used.</p>
<p><strong>Service oriented:</strong> One of the main features of Duda, is that it allow to register multiple web services under the same HTTP instance, as well each service can be assigned to a different Virtual Host (a Virtual Host can hold multiple web services).</p>
<p>Each service can map static URLs to specific callback functions or use the Map interfaces provided by Duda, this last one is pretty much similar to REST and provides a very useful set of methods to handle each request resources such as: methods, parameters and body content.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;"><strong>API Objects</strong></span></h3>
<p><span style="text-decoration: underline;"><strong><br />
</strong></span></p>
<p>When building/running a web service, a set of C pseudo-objects are exported to perform the setup and define callbacks for certains events, as well many objects are helpers to build responses and minimize the effort for the developer. Some API Objects available are:</p>
<ul>
<li>Console</li>
<li>Cookie</li>
<li>Event</li>
<li>Param</li>
<li>Response</li>
<li>Request</li>
<li>Session</li>
</ul>
<p>Each object expose a set of methods, for more details about the available methods for each objects refer to the <a href="http://duda.io/api/">API documentation</a>.</p>
<p>&nbsp;</p>
<h3><span style="text-decoration: underline;">API Packages</span></h3>
<p><span style="text-decoration: underline;"><br />
</span></p>
<p>Besides the built-in API Objects available, Duda supports a packages system which aims to load on demand external objects to extend the core API capabilities. Some packages available are the following:</p>
<ul>
<li>Base64</li>
<li>JSON</li>
<li>SHA1</li>
<li>SQLite</li>
<li>Websocket</li>
</ul>
<p>Packages are included in Duda per users demand, if you miss some specific package functionality let us know to consider it development and further inclusion.</p>
<p>If you want to know more about Duda please refer to the following links:</p>
<ul>
<li>Main site: <a href="http://duda.io/">http://duda.io</a></li>
<li>Documentation: <a href="http://duda.io/documentation/overview">http://duda.io/documentation/overview</a></li>
<li>Mailing list:     <a href="http://lists.monkey-project.com/listinfo/duda">http://lists.monkey-project.com/listinfo/duda</a></li>
<li>Hello world in 5 steps: <a href="http://duda.io/documentation/hello_world_5_steps">http://duda.io/documentation/hello_world_5_steps</a></li>
</ul>
<p>more news coming soon, if you want to stay tuned make sure to register in the new mailing list&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/09/19/duda-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GSoC and Monkey Roadmap</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/08/14/gsoc-monkey-roadmap/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/08/14/gsoc-monkey-roadmap/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 04:13:56 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Monkey]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=817</guid>
12345		<description><![CDATA[<p><strong>GSoC Update<br />
</strong>we are almost finishing the <a href="http://code.google.com/soc">Google Summer of Code</a> program and the students have done a great job on <a href="http://monkey-project.com">Monkey Project</a>, i have to admit that i am quite impressed by the quality of the work delivered. It has been a good experience for both sides, in name of the community i can only say <strong>&#8220;good job!&#8221;</strong>.  I will share more details and a final evaluation once the program ends officially, as well you will see a mini-post in the <a href="http://google-opensource.blogspot.com/">Google Code blog</a> early in September.</p>
<p><strong>Monkey Roadmap</strong></p>
<p>The latest release version of <a href="http://monkey-project.com/Announcements/v1.0.1">Monkey is v1.0.1</a>, in our development repository we have created a the <a href="http://git.monkey-project.com/?p=monkey;a=shortlog;h=refs/heads/v1.1.0">branch for v1.1.0</a>, this last one is in code-freeze status, that means that we are preparing the release and the a few tasks are involved such as: minor bug fixing, test the code base, verify possible regressions, do cleanups, package the binaries for Debian/Ubuntu, write the release notes, etc. So we hope to have some news at the end of this week, more detail will be shared in the release notes.</p>
<p>In <a href="http://git.monkey-project.com/?p=monkey;a=shortlog">GIT Master</a>, we keep the good work for Monkey v1.2 and we are planning the release for mid of October 2012, the most relevant features listed at the moment is the inclusion of the <a href="http://fastcgi.com">FastCGI</a> plugin and the replacement of SSL layer provided by <a href="http://matrixssl.org">MatrixSSL</a> in favor of the SSL layer provided by <a href="http://polarssl.org">PolarSSL</a>.</p>
<p><strong>Duda Roadmap</strong></p>
<p>Our <a href="http://duda.io">web services framework</a> is still under <a href="http://git.monkey-project.com/?p=duda;a=summary">active development</a>, we are still working in some improvements before to deliver an official release, if you are interested on how is going you can check the development repository, or as well check the current <a href="http://duda.io/api/event.html">API documentation</a>.</p>
<p>For any of the project listed, If you have a desired feature/extension, please let us know, we are focusing on delivering a high quality open source web server stack based on people needs <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></description>
			<content:encoded><![CDATA[<p><strong>GSoC Update<br />
</strong>we are almost finishing the <a href="http://code.google.com/soc">Google Summer of Code</a> program and the students have done a great job on <a href="http://monkey-project.com">Monkey Project</a>, i have to admit that i am quite impressed by the quality of the work delivered. It has been a good experience for both sides, in name of the community i can only say <strong>&#8220;good job!&#8221;</strong>.  I will share more details and a final evaluation once the program ends officially, as well you will see a mini-post in the <a href="http://google-opensource.blogspot.com/">Google Code blog</a> early in September.</p>
<p><strong>Monkey Roadmap</strong></p>
<p>The latest release version of <a href="http://monkey-project.com/Announcements/v1.0.1">Monkey is v1.0.1</a>, in our development repository we have created a the <a href="http://git.monkey-project.com/?p=monkey;a=shortlog;h=refs/heads/v1.1.0">branch for v1.1.0</a>, this last one is in code-freeze status, that means that we are preparing the release and the a few tasks are involved such as: minor bug fixing, test the code base, verify possible regressions, do cleanups, package the binaries for Debian/Ubuntu, write the release notes, etc. So we hope to have some news at the end of this week, more detail will be shared in the release notes.</p>
<p>In <a href="http://git.monkey-project.com/?p=monkey;a=shortlog">GIT Master</a>, we keep the good work for Monkey v1.2 and we are planning the release for mid of October 2012, the most relevant features listed at the moment is the inclusion of the <a href="http://fastcgi.com">FastCGI</a> plugin and the replacement of SSL layer provided by <a href="http://matrixssl.org">MatrixSSL</a> in favor of the SSL layer provided by <a href="http://polarssl.org">PolarSSL</a>.</p>
<p><strong>Duda Roadmap</strong></p>
<p>Our <a href="http://duda.io">web services framework</a> is still under <a href="http://git.monkey-project.com/?p=duda;a=summary">active development</a>, we are still working in some improvements before to deliver an official release, if you are interested on how is going you can check the development repository, or as well check the current <a href="http://duda.io/api/event.html">API documentation</a>.</p>
<p>For any of the project listed, If you have a desired feature/extension, please let us know, we are focusing on delivering a high quality open source web server stack based on people needs <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/08/14/gsoc-monkey-roadmap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>About Monkey v/s G-Wan and reputation</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/08/02/monkey_gwan_reputation/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/08/02/monkey_gwan_reputation/#comments</comments>
		<pubDate>Thu, 02 Aug 2012 22:22:14 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=765</guid>
12345		<description><![CDATA[<p>Weeks ago i <a href="http://monkey-project.com/benchmarks/x86_64_monkey_gwan">performed some benchmarks</a> to test <a href="http://monkey-project.com">Monkey project</a> againts other webservers, i have included the test for one closed source web server which <strong>claims</strong> to be (or not to be?) the fastest on earth: <a href="http://gwan.com/">GWan</a>. My benchmark shows that <a href="http://monkey-project.com">Monkey</a> is faster than <a href="http://gwan.com">GWan</a> under certain conditions: number of request per second for a file &gt;= 200KB.</p>
<p>One person around our community started to perform his own bencharks and shared his findings with <a href="http://gwan.com/about">Pierre</a> the author of <a href="http://gwan.com">GWan</a>. Looks like Pierre&#8217;s feelings were hurt and his ironic words expressed a strongly disagree because there is a project that performs  better than <a href="http://gwan.com">G-Wan</a>. He started to put in doubt my reputation and abused of the usage of my employer&#8217;s name:</p>
<p style="text-align: center;"><a href="http://gwan.com/blog/20120728.html">What makes an expert &#8220;cheat&#8221;? http://gwan.ch/blog/20120728.html</a></p>
<p><strong>Oracle and I</strong></p>
<p>Pierre, let&#8217;s make the things clear here. <a href="http://www.oracle.com">Oracle</a> is my employer and it have not any relationship with the <a href="http://monkey-project.com">Monkey</a> <a href="http://en.wikipedia.org/wiki/Open_source">open source</a> project. It looks like a lack of professionalism to abuse of <a href="http://oracle.com">Oracle</a> name to increase visibility and try to pseudo-expose your startup in a different manner, why to mention the &#8216;<a href="http://oracle.com">Oracle</a>&#8216; word 12 times without need it ?, there are other ways to positionate your blog with the search engines.</p>
<p>&nbsp;</p>
<p><strong>G-Wan benchmaks</strong></p>
<p>The <a href="http://gwan.com/about">G-Wan author</a> decided the best way to bencharmk his software, so he went straigforward to benchmark under two specific <strong>static</strong> conditions:</p>
<ul>
<li>KeepAlive       : all test are made under keep alive</li>
<li>Small file sizes: the tests are performed with a file of 100 bytes</li>
</ul>
<p>If the benchmark method is static as the used here, its useful when measuring current version againts development version, and see how it behave each other, and this is good. But you cannot use the same method to measure other web servers, let&#8217;s perform a brief analysis:</p>
<p><strong><span style="text-decoration: underline;">KeepAlive</span></strong></p>
<p>The <a href="http://en.wikipedia.org/wiki/HTTP_persistent_connection">KeepAlive HTTP</a> feature (default in <a href="http://www.ietf.org/rfc/rfc2616.txt">HTTP/1.1</a>), aims to keep the communication channel open between the client and the server to perform multiple request in a FIFO way, this approach reduces latency due to the avoidance of the TCP handshake and less network traffic. In a HTTP KeepAlive session for example, you can perform 1000000 request over the same persistent channel if the server allows that.</p>
<p>As stated before, using HTTP KeepAlive the transfer of user-level data is faster. But there is an important point that we cannot omit to mention when we are under a *benchmark* context: if the web server use threads to balance the work due to SMP or other need, using KeepAlive sessions we will *hide* the overhead of the connection balancing between workers and for hence the internal scheduling and time to start processing each request. So use KeepAlive for benchmarking is useful to measure just a part of the web<br />
server core and *not* a fundament to determinate which is the fastest solution in the world.</p>
<p>From a real-life perspective, an HTTP Client (browser) using KeepAlive, rarely will perform more than 25 request over the same channel. So the tests under KeepAlive does not reflect how the Internet/HTTP world behave.</p>
<p><span style="text-decoration: underline;"><strong>Small file sizes</strong></span></p>
<p><a href="http://gwan.com"> G-Wan</a> perform caching over requested files in memory when they are pretty small, so when testing a 100 bytes file, this is not hitting I/O and is not requiring to perform extra expensive system call. This is the common approach over almost all web servers, a few KB of extra memory is not bad to avoid I/O.</p>
<p>Caching is good, but testing againts the same small cached file, it&#8217;s just trying to determinate how fast is accessing memory buffer and sending out the same data.</p>
<p>Now having describe how the static benchmark is done, sounds like a good plan to determinate that G-Wan is the fastest solution available testing *only* under KeepAlive mode plus the same small cached file for all requests ?, not really.</p>
<p>Every person who wants to benchmark G-WAN and break one of those rules (KeepAlive/small file), will realize than Monkey and NginX performs faster than G-Wan.</p>
<p>G-Wan author claims that testing in non-keepalive mode is equal to &#8220;test the TCP IP stack rather than the user-mode code of the server&#8221;, which is totally wrong, a web server depends on TCP/IP stack and meassuring the performance of a web server is more than test a simple access to a memory buffer in user space.</p>
<p><strong>Measuring tool</strong></p>
<p>The G-Wan benchmarks are done using a wrapper utility called &#8216;ab wrapper&#8217;, described by Pierre as the &#8220;most capable tool&#8221; (<a href="http://gwan.ch/source/ab.c">http://gwan.ch/source/ab.c</a>), the sad part is that it cannot perform well with files of a few KB, it get stuck when used with <a href="http://redmine.lighttpd.net/projects/weighttp/wiki">Weighttp</a> backend or when is used without keepalive mode. It&#8217;s a good idea of tool as it takes snapshots of user-mode/kernel-mode stats once a concurrent round of request is finished.</p>
<p>As the code of ab.c it&#8217;s not legible and is spawning third party utilities to perform it&#8217;s job, i wrote a similar tool but based in proc filesystem, the tool name is &#8216;<a href="http://github.com/edsiper/wr">watch resources</a>&#8216; (aka <a href="http://github.com/edsiper/wr">wr</a>) and i have published the code on GitHUB:</p>
<p style="text-align: center;"><a href="http://github.com/edsiper/wr">http://github.com/edsiper/wr</a></p>
<p>So with this new tool i have performed a new set of tests of benchmark using concurrency as ab.c does and having more accurate memory usage for the results.</p>
<p><strong>Benchmark: Monkey v/s G-Wan </strong></p>
<p>This test have been made in the following way:</p>
<ul>
<li>Wrapper by <a href="http://github.com/edsiper/wr">Watch Resources</a> tool</li>
<li><a href="http://redmine.lighttpd.net/projects/weighttp/wiki">Weighttp</a> backend to stress the server</li>
<li>The URL tested hits a file of <strong>200KB</strong></li>
<li>Concurrency tests from 100 to 1000 (100 concurrents to 1000), increasing the level with 10 concurrents.</li>
<li>KeepAlive enable</li>
<li>Backend stress tool with 10 workers</li>
<li>Each round did 500.000 requests</li>
</ul>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/08/wr_monkey_gwan.png"><img class="aligncenter size-full wp-image-793" title="wr_monkey_gwan" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/08/wr_monkey_gwan.png" alt="" width="650" height="680" /></a></p>
<p><strong>Requests per second</strong></p>
<ul>
<li>Monkey did an average of <strong><span style="color: #008000;">29231</span></strong> requests per second</li>
<li>G-Wan did an average of <strong><span style="color: #ff0000;">17222</span></strong> request per second</li>
</ul>
<p><a href="http://monkey-project.com">Monkey</a> did <strong><span style="color: #993300;">42%</span></strong> more requests than <a href="http://gwan.com">G-Wan</a> under the same conditions</p>
<p><strong>Memory Usage</strong></p>
<p>Its expected to see high level of memory consumption as the concurrency hits a major load in the server so the goal is to optimize the resources and reduce memory allocations when they are not necessary:</p>
<ul>
<li>Monkey consumed an average of <strong><span style="color: #008000;">3.4MB</span></strong> along the whole test</li>
<li>G-Wan consumed an average of <strong><span style="color: #ff0000;">7.09MB</span></strong> along the whole test</li>
</ul>
<p><a href="http://gwan.com">G-Wan</a> consumed <strong><span style="color: #993300;">52% more</span></strong> memory than <a href="http://monkey-project.com">Monkey</a> for the same test</p>
<p><strong>User and system time</strong></p>
<p>In the Linux Kernel (OS) design which comes from Unix family, exist two executions context or virtual address spaces: User space and Kernel Space (or System space). The User space belongs to the container of user applications and related resources plus an interface to communicate to the Kernel, as well the Kernel Space and its roles covers I/O, Memory allocations, Scheduling of user space tasks and others.</p>
<p>All job that occurred in a user process/task and which do not require a direct Kernel intervention is called user space, everything else is Kernel Space. We call User-time to the CPU cycles consumed by the user user task, and we call Kernel/System time to the CPU cycles consumed by the user space task through a system call to the Kernel.</p>
<p>So this metric shows how much CPU time is spent in user and system space, and depending of the point of view it could be good or not so good:</p>
<ul>
<li>Monkey user time: 5267 milliseconds</li>
<li>G-Wan user time: 3830 milliseconds</li>
<li>Monkey Kernel/System time 36159 milliseconds</li>
<li>G-Wan Kernel/System time 50999 milliseconds</li>
</ul>
<p>G-Wan have focused too much into reduce user-time being a non-friendly program running under the Linux Kernel. Monkey is a project devoted to run over a Linux Kernel and that&#8217;s the reason about why it runs pretty optimized. Having a basic knowledge of Linux system calls is not hard to achieve a great performance.</p>
<p>In the blog post mentioned earlier in the graphics comments it states:</p>
<blockquote><p>As opposed to Monkey, with G-Wan, the Kernel is using CPU resources faster than G-Wan user mode CPU usage. As a result, the Linux Kernel is the bottleneck far before G-Wan</p></blockquote>
<p>The previous comment, denotes a lack of understanding about how the Linux Kernel works internally, there is no knowledge of user/system spaces or scheduling. Referring to the G-Wan project history it comes from Windows so we can excuse the lack of knowledge on Linux. Rarely the Linux Kernel at this operation level is a bottleneck.</p>
<p>For short, in order to avoid misunderstandings i already have learned my lesson and i will provide more detailed benchmarks from now. In the meanwhile G-Wan have a couple of things to fix.. starting from it design ?.</p>
<p>Other points that i forgot to mention:</p>
<ul>
<li>The test in Monkey took <strong><span style="color: #003300;">25 minutes and 58 seconds</span></strong>. G-Wan took <strong><span style="color: #ff0000;">44 minutes and 23 seconds</span></strong></li>
<li>If you want to validate the information on this post, you can download the source reports and graphics from <a href="http://edsiper.linuxchile.cl/monkey_gwan_benchmark.tar.gz">here</a>.</li>
<li>I am emaling Pierre about this blog post</li>
</ul>
]]></description>
			<content:encoded><![CDATA[<p>Weeks ago i <a href="http://monkey-project.com/benchmarks/x86_64_monkey_gwan">performed some benchmarks</a> to test <a href="http://monkey-project.com">Monkey project</a> againts other webservers, i have included the test for one closed source web server which <strong>claims</strong> to be (or not to be?) the fastest on earth: <a href="http://gwan.com/">GWan</a>. My benchmark shows that <a href="http://monkey-project.com">Monkey</a> is faster than <a href="http://gwan.com">GWan</a> under certain conditions: number of request per second for a file &gt;= 200KB.</p>
<p>One person around our community started to perform his own bencharks and shared his findings with <a href="http://gwan.com/about">Pierre</a> the author of <a href="http://gwan.com">GWan</a>. Looks like Pierre&#8217;s feelings were hurt and his ironic words expressed a strongly disagree because there is a project that performs  better than <a href="http://gwan.com">G-Wan</a>. He started to put in doubt my reputation and abused of the usage of my employer&#8217;s name:</p>
<p style="text-align: center;"><a href="http://gwan.com/blog/20120728.html">What makes an expert &#8220;cheat&#8221;? http://gwan.ch/blog/20120728.html</a></p>
<p><strong>Oracle and I</strong></p>
<p>Pierre, let&#8217;s make the things clear here. <a href="http://www.oracle.com">Oracle</a> is my employer and it have not any relationship with the <a href="http://monkey-project.com">Monkey</a> <a href="http://en.wikipedia.org/wiki/Open_source">open source</a> project. It looks like a lack of professionalism to abuse of <a href="http://oracle.com">Oracle</a> name to increase visibility and try to pseudo-expose your startup in a different manner, why to mention the &#8216;<a href="http://oracle.com">Oracle</a>&#8216; word 12 times without need it ?, there are other ways to positionate your blog with the search engines.</p>
<p>&nbsp;</p>
<p><strong>G-Wan benchmaks</strong></p>
<p>The <a href="http://gwan.com/about">G-Wan author</a> decided the best way to bencharmk his software, so he went straigforward to benchmark under two specific <strong>static</strong> conditions:</p>
<ul>
<li>KeepAlive       : all test are made under keep alive</li>
<li>Small file sizes: the tests are performed with a file of 100 bytes</li>
</ul>
<p>If the benchmark method is static as the used here, its useful when measuring current version againts development version, and see how it behave each other, and this is good. But you cannot use the same method to measure other web servers, let&#8217;s perform a brief analysis:</p>
<p><strong><span style="text-decoration: underline;">KeepAlive</span></strong></p>
<p>The <a href="http://en.wikipedia.org/wiki/HTTP_persistent_connection">KeepAlive HTTP</a> feature (default in <a href="http://www.ietf.org/rfc/rfc2616.txt">HTTP/1.1</a>), aims to keep the communication channel open between the client and the server to perform multiple request in a FIFO way, this approach reduces latency due to the avoidance of the TCP handshake and less network traffic. In a HTTP KeepAlive session for example, you can perform 1000000 request over the same persistent channel if the server allows that.</p>
<p>As stated before, using HTTP KeepAlive the transfer of user-level data is faster. But there is an important point that we cannot omit to mention when we are under a *benchmark* context: if the web server use threads to balance the work due to SMP or other need, using KeepAlive sessions we will *hide* the overhead of the connection balancing between workers and for hence the internal scheduling and time to start processing each request. So use KeepAlive for benchmarking is useful to measure just a part of the web<br />
server core and *not* a fundament to determinate which is the fastest solution in the world.</p>
<p>From a real-life perspective, an HTTP Client (browser) using KeepAlive, rarely will perform more than 25 request over the same channel. So the tests under KeepAlive does not reflect how the Internet/HTTP world behave.</p>
<p><span style="text-decoration: underline;"><strong>Small file sizes</strong></span></p>
<p><a href="http://gwan.com"> G-Wan</a> perform caching over requested files in memory when they are pretty small, so when testing a 100 bytes file, this is not hitting I/O and is not requiring to perform extra expensive system call. This is the common approach over almost all web servers, a few KB of extra memory is not bad to avoid I/O.</p>
<p>Caching is good, but testing againts the same small cached file, it&#8217;s just trying to determinate how fast is accessing memory buffer and sending out the same data.</p>
<p>Now having describe how the static benchmark is done, sounds like a good plan to determinate that G-Wan is the fastest solution available testing *only* under KeepAlive mode plus the same small cached file for all requests ?, not really.</p>
<p>Every person who wants to benchmark G-WAN and break one of those rules (KeepAlive/small file), will realize than Monkey and NginX performs faster than G-Wan.</p>
<p>G-Wan author claims that testing in non-keepalive mode is equal to &#8220;test the TCP IP stack rather than the user-mode code of the server&#8221;, which is totally wrong, a web server depends on TCP/IP stack and meassuring the performance of a web server is more than test a simple access to a memory buffer in user space.</p>
<p><strong>Measuring tool</strong></p>
<p>The G-Wan benchmarks are done using a wrapper utility called &#8216;ab wrapper&#8217;, described by Pierre as the &#8220;most capable tool&#8221; (<a href="http://gwan.ch/source/ab.c">http://gwan.ch/source/ab.c</a>), the sad part is that it cannot perform well with files of a few KB, it get stuck when used with <a href="http://redmine.lighttpd.net/projects/weighttp/wiki">Weighttp</a> backend or when is used without keepalive mode. It&#8217;s a good idea of tool as it takes snapshots of user-mode/kernel-mode stats once a concurrent round of request is finished.</p>
<p>As the code of ab.c it&#8217;s not legible and is spawning third party utilities to perform it&#8217;s job, i wrote a similar tool but based in proc filesystem, the tool name is &#8216;<a href="http://github.com/edsiper/wr">watch resources</a>&#8216; (aka <a href="http://github.com/edsiper/wr">wr</a>) and i have published the code on GitHUB:</p>
<p style="text-align: center;"><a href="http://github.com/edsiper/wr">http://github.com/edsiper/wr</a></p>
<p>So with this new tool i have performed a new set of tests of benchmark using concurrency as ab.c does and having more accurate memory usage for the results.</p>
<p><strong>Benchmark: Monkey v/s G-Wan </strong></p>
<p>This test have been made in the following way:</p>
<ul>
<li>Wrapper by <a href="http://github.com/edsiper/wr">Watch Resources</a> tool</li>
<li><a href="http://redmine.lighttpd.net/projects/weighttp/wiki">Weighttp</a> backend to stress the server</li>
<li>The URL tested hits a file of <strong>200KB</strong></li>
<li>Concurrency tests from 100 to 1000 (100 concurrents to 1000), increasing the level with 10 concurrents.</li>
<li>KeepAlive enable</li>
<li>Backend stress tool with 10 workers</li>
<li>Each round did 500.000 requests</li>
</ul>
<p><a href="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/08/wr_monkey_gwan.png"><img class="aligncenter size-full wp-image-793" title="wr_monkey_gwan" src="http://edsiper.linuxchile.cl/blog/wp-content/uploads/2012/08/wr_monkey_gwan.png" alt="" width="650" height="680" /></a></p>
<p><strong>Requests per second</strong></p>
<ul>
<li>Monkey did an average of <strong><span style="color: #008000;">29231</span></strong> requests per second</li>
<li>G-Wan did an average of <strong><span style="color: #ff0000;">17222</span></strong> request per second</li>
</ul>
<p><a href="http://monkey-project.com">Monkey</a> did <strong><span style="color: #993300;">42%</span></strong> more requests than <a href="http://gwan.com">G-Wan</a> under the same conditions</p>
<p><strong>Memory Usage</strong></p>
<p>Its expected to see high level of memory consumption as the concurrency hits a major load in the server so the goal is to optimize the resources and reduce memory allocations when they are not necessary:</p>
<ul>
<li>Monkey consumed an average of <strong><span style="color: #008000;">3.4MB</span></strong> along the whole test</li>
<li>G-Wan consumed an average of <strong><span style="color: #ff0000;">7.09MB</span></strong> along the whole test</li>
</ul>
<p><a href="http://gwan.com">G-Wan</a> consumed <strong><span style="color: #993300;">52% more</span></strong> memory than <a href="http://monkey-project.com">Monkey</a> for the same test</p>
<p><strong>User and system time</strong></p>
<p>In the Linux Kernel (OS) design which comes from Unix family, exist two executions context or virtual address spaces: User space and Kernel Space (or System space). The User space belongs to the container of user applications and related resources plus an interface to communicate to the Kernel, as well the Kernel Space and its roles covers I/O, Memory allocations, Scheduling of user space tasks and others.</p>
<p>All job that occurred in a user process/task and which do not require a direct Kernel intervention is called user space, everything else is Kernel Space. We call User-time to the CPU cycles consumed by the user user task, and we call Kernel/System time to the CPU cycles consumed by the user space task through a system call to the Kernel.</p>
<p>So this metric shows how much CPU time is spent in user and system space, and depending of the point of view it could be good or not so good:</p>
<ul>
<li>Monkey user time: 5267 milliseconds</li>
<li>G-Wan user time: 3830 milliseconds</li>
<li>Monkey Kernel/System time 36159 milliseconds</li>
<li>G-Wan Kernel/System time 50999 milliseconds</li>
</ul>
<p>G-Wan have focused too much into reduce user-time being a non-friendly program running under the Linux Kernel. Monkey is a project devoted to run over a Linux Kernel and that&#8217;s the reason about why it runs pretty optimized. Having a basic knowledge of Linux system calls is not hard to achieve a great performance.</p>
<p>In the blog post mentioned earlier in the graphics comments it states:</p>
<blockquote><p>As opposed to Monkey, with G-Wan, the Kernel is using CPU resources faster than G-Wan user mode CPU usage. As a result, the Linux Kernel is the bottleneck far before G-Wan</p></blockquote>
<p>The previous comment, denotes a lack of understanding about how the Linux Kernel works internally, there is no knowledge of user/system spaces or scheduling. Referring to the G-Wan project history it comes from Windows so we can excuse the lack of knowledge on Linux. Rarely the Linux Kernel at this operation level is a bottleneck.</p>
<p>For short, in order to avoid misunderstandings i already have learned my lesson and i will provide more detailed benchmarks from now. In the meanwhile G-Wan have a couple of things to fix.. starting from it design ?.</p>
<p>Other points that i forgot to mention:</p>
<ul>
<li>The test in Monkey took <strong><span style="color: #003300;">25 minutes and 58 seconds</span></strong>. G-Wan took <strong><span style="color: #ff0000;">44 minutes and 23 seconds</span></strong></li>
<li>If you want to validate the information on this post, you can download the source reports and graphics from <a href="http://edsiper.linuxchile.cl/monkey_gwan_benchmark.tar.gz">here</a>.</li>
<li>I am emaling Pierre about this blog post</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/08/02/monkey_gwan_reputation/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Google Summer of Code &amp; Monkey</title>
		<link>http://edsiper.linuxchile.cl/blog/2012/07/20/google-summer-of-code-monkey/</link>
		<comments>http://edsiper.linuxchile.cl/blog/2012/07/20/google-summer-of-code-monkey/#comments</comments>
		<pubDate>Fri, 20 Jul 2012 20:25:32 +0000</pubDate>
		<dc:creator>Eduardo Silva</dc:creator>
				<category><![CDATA[Announces]]></category>
		<category><![CDATA[Monkey]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">http://edsiper.linuxchile.cl/blog/?p=761</guid>
12345		<description><![CDATA[<p>Last week we did the review of the mid-term evaluation of <a href="http://code.google.com/soc">Google Summer of Code</a>, on this second round of the program 2/3 of our students continue hacking <a href="http://monkey-project.com">Monkey</a>, by now i can mention that we have fully implemented the following by students:</p>
<ul>
<li>Monkey Library: <a href="http://monkey-project.com">Monkey</a> now can be converted in a shared library, that means that you can use Monkey stack using the lib API</li>
<li>Monkey CGI Plugin: when we moved to a event-driven model in Monkey 0.10.0 (two years ago), we decided to remove the CGI support as it lack of performance, due to people requirements and one successful student who already finished his initial project, he decided to move forward with extra tasks, so the CGI support is officially back for the next release v1.1.</li>
<li>Redis Support: our <a href="http://duda.io">web services framework called Duda</a>, implements packages to add extra features or make the use of third party components in an easy manner, <a href="http://redis.io">Redis</a> package is ready for <a href="http://duda.io">Duda</a> and will be merged into mainline within the next week.</li>
</ul>
<p>Ongoing tasks by the students are: complete the merge of library support in Monkey mainline, FastCGI support, Memcache support for Duda&#8230; exciting times <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
]]></description>
			<content:encoded><![CDATA[<p>Last week we did the review of the mid-term evaluation of <a href="http://code.google.com/soc">Google Summer of Code</a>, on this second round of the program 2/3 of our students continue hacking <a href="http://monkey-project.com">Monkey</a>, by now i can mention that we have fully implemented the following by students:</p>
<ul>
<li>Monkey Library: <a href="http://monkey-project.com">Monkey</a> now can be converted in a shared library, that means that you can use Monkey stack using the lib API</li>
<li>Monkey CGI Plugin: when we moved to a event-driven model in Monkey 0.10.0 (two years ago), we decided to remove the CGI support as it lack of performance, due to people requirements and one successful student who already finished his initial project, he decided to move forward with extra tasks, so the CGI support is officially back for the next release v1.1.</li>
<li>Redis Support: our <a href="http://duda.io">web services framework called Duda</a>, implements packages to add extra features or make the use of third party components in an easy manner, <a href="http://redis.io">Redis</a> package is ready for <a href="http://duda.io">Duda</a> and will be merged into mainline within the next week.</li>
</ul>
<p>Ongoing tasks by the students are: complete the merge of library support in Monkey mainline, FastCGI support, Memcache support for Duda&#8230; exciting times <img src='http://edsiper.linuxchile.cl/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://edsiper.linuxchile.cl/blog/2012/07/20/google-summer-of-code-monkey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
