<?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>airodig.com</title>
	<atom:link href="http://airodig.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://airodig.com</link>
	<description>airodig hacking industries</description>
	<lastBuildDate>Tue, 27 Jul 2010 21:53:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Node.js &#8212; Non Blocking Evented ServerSide Javascript</title>
		<link>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/</link>
		<comments>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 21:53:33 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[evented]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[jade]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[v8]]></category>
		<category><![CDATA[web frameworks]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=401</guid>
		<description><![CDATA[&#8220;Because nothing blocks, less-than-expert programmers are able to develop fast systems.&#8221; http://nodejs.org Birds Eye View of Node.js I&#8217;m sure you&#8217;ve all seen/heard stuff about using real-time websockets &#8212; this guy used node.js but a lot of ppl don&#8217;t know that there is so much more to this framework than meets the eye. First off, it [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
  <i>&#8220;Because nothing blocks, less-than-expert programmers are able to develop fast systems.&#8221;</i><br /> <a href="http://nodejs.org" nofollow="true" title="node js">http://nodejs.org</a><br />
</center></p>
<p><strong>Birds Eye View of Node.js</strong></p>
<p>I&#8217;m sure you&#8217;ve all seen/heard stuff about using <a href="http://jeffkreeftmeijer.com/2010/experimenting-with-node-js/" tite="node.js cursor demo">real-time websockets</a> &#8212; this guy used node.js but a lot of ppl don&#8217;t know that there is so much more to this framework than meets the eye.</p>
<p>First off, it has no locks, is non-blocking in as many places as possible and uses very little memory. Oh yeh, pretty much everything has a callback, following an evented model. Some POSIX operations return a &#8216;promise&#8217; which signal a &#8216;success&#8217; or &#8216;error&#8217;. Node is ridiculously powerful as you can see by reading over the api. There is so much here to do and really allows you to do some &#8216;system-level&#8217; style of programming with a whole slew of POSIX style (compliant?) system calls</p>
<p><strong>Concurrency without Multi-Threading?</strong><br />
Most of the built in hard-core concurrency comes from the evented nature of the framework. Being able to immediately respond to incoming requests while something is off reading from a database provides much needed clock cycles. Right now it appears there is no straight-forward way of utilizing multiple cores other than putting a load balancer of sorts in front and sending over unix sockets or something but there are plans to including forking in the future so that different processes may emerge taking advantage of the cores and utilize message passing to talk to each other. You can of course fork new processes using the system calls available.</p>
<p>Apparently the developers of node are looking towards using <a href="http://www.whatwg.org/specs/web-workers/current-work/" nofollow="true">web workers</a> available in HTML5 which will also alleviate some concurrency issues.</p>
<p>So who uses it? Is it production quality yet? Well, you can always ask the good folks over at <a href="http://plurk.com" title="plurk" nofollow="true">Plurk.com</a> (twitter for japan) who run it w/over 100k concurrent users &#8212; apparently this runs on one box with 8 proccesses&#8230;. uhhhh&#8230;</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/wtf-pics-galactic-mugging.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/wtf-pics-galactic-mugging-241x300.jpg" alt="wtf" title="wtf-pics-galactic-mugging" width="241" height="300" class="aligncenter size-medium wp-image-437" /></a><br />
</center></p>
<p><center>&#8230;. that&#8217;s what I was thinking <strong>tha fuck!?</strong></center></p>
<p>&#8230; maybe I should go spend some time in japan &#8230; I keep finding all sorts of shit I like from there</p>
<p><strong>Hello World in Node.js</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #003366; font-weight: bold;color: #577A61;">var</span> sys <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'sys'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
sys.<span style="color: #660066;">puts</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'hello!'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>so first off we include the sys lib then we do our puts statement .. pretty simple<br />
let&#8217;s take a look at a </p>
<p><strong>Simple Node.js HTTP Server</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #003366; font-weight: bold;color: #577A61;">var</span> http <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'http'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
http.<span style="color: #660066;">createServer</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #003366; font-weight: bold;color: #577A61;">function</span> <span style="color: #009900;color: #CCC;">&#40;</span>req<span style="color: #339933;color: #CCC;">,</span> res<span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
  res.<span style="color: #660066;">writeHead</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">200</span><span style="color: #339933;color: #CCC;">,</span> <span style="color: #009900;color: #CCC;">&#123;</span><span style="color: #3366CC;color: #666666;">'Content-Type'</span><span style="color: #339933;color: #CCC;">:</span> <span style="color: #3366CC;color: #666666;">'text/plain'</span><span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  res.<span style="color: #660066;">end</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'Hello World<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #660066;">listen</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">8124</span><span style="color: #339933;color: #CCC;">,</span> <span style="color: #3366CC;color: #666666;">&quot;127.0.0.1&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'Server running at http://127.0.0.1:8124/'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>yeh&#8230; it doesn&#8217;t really get too hard but this shows the evented nature of node &#8212; shit is retardo fast</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/Wiley-Coyote-Rockets.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/Wiley-Coyote-Rockets-300x226.jpg" alt="wiley coyote rockets" title="Wiley Coyote Rockets" width="300" height="226" class="aligncenter size-medium wp-image-427" /></a><br />
</center></p>
<p><strong>Speed Demon Benches</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">1000</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">8124</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">6792.23</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span></pre></div></div>

<p>&#8230; but it&#8217;s not just for HTTP</p>
<p>if you have any need for networking this is a badass framework to be using. It uses a microkernel design by including modules that you need rather than a bunch of shit you <b>*might*</b> use &#8212; big win in my favor..even down to sys/http modules.</p>
<p>you can find a list of <a href="http://wiki.github.com/ry/node/modules" title="node.js modules">supporting modules here</a></p>
<p><strong>Binary Data</strong></p>
<p>I&#8217;m including this section here because when I was looking for information on sending bytes here and there I found lots of articles on the internet saying this was not easily done with node.js &#8212; this IS EASILY DONE now. You <b>CAN</b> make a buffer with binary data now and <u>NOT</u> have to specify &#8216;utf8&#8242;, &#8216;ascii&#8217;, &#8216;base64&#8242;, etc&#8230;the <i>&#8216;net2 branch&#8217;</i> that you might see referenced to on the net is already merged in and the <a href="http://nodejs.org/api.html" title="node.js api docs" nofollow="true">api docs</a> are current though can be rather confusing after reading older documentation found around&#8230;so ignore that old shit &#8212; so, just to clarify, if you are sending binary data through some random socket you can do that now.</p>
<p><strong>Want to see an example of this mysterious byte buffer?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">  Buffer <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'buffer'</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #660066;">Buffer</span><span style="color: #339933;color: #CCC;">;</span>
  buf <span style="color: #339933;color: #CCC;">=</span> <span style="color: #003366; font-weight: bold;color: #577A61;">new</span> Buffer<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">8</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  <span style="color: #000066; font-weight: bold;color: #B83A24;">for</span><span style="color: #009900;color: #CCC;">&#40;</span>i <span style="color: #339933;color: #CCC;">=</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span> i <span style="color: #339933;color: #CCC;">&lt;</span> <span style="color: #CC0000;background-color: #000000; color: #DDD;">8</span><span style="color: #339933;color: #CCC;">;</span> i<span style="color: #339933;color: #CCC;">+=</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">1</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span> buf<span style="color: #009900;color: #CCC;">&#91;</span>i<span style="color: #009900;color: #CCC;">&#93;</span> <span style="color: #339933;color: #CCC;">=</span> <span style="color: #CC0000;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span> <span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p><center><i>be careful as your buffer will be initialized with random data so I&#8217;d advise clearing it first</i></center></p>
<p>very interesting that you can do this now since javascript doesn&#8217;t like binary data that well</p>
<p>buffer.copy does a memcpy() &#8230;. begging to get owned by some hackers &#8212; remember to sanitize your data</p>
<p><strong>Downloading/Installing</strong></p>
<p>before doing anything else go ahead and grab the latest (as of this writing):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">wget</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>nodejs.org<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>dist<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>node-v0.1.102.tar.gz
.<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>configure <span style="color: #000000; font-weight: bold;color: #CCC;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #000000; font-weight: bold;color: #CCC;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span></pre></div></div>

<p>woohoo! simple build process ftw</p>
<p>want to use express? it&#8217;s pretty cool, like sinatra and it&#8217;ll allow you to get to know the most tubular npm tool.</p>
<p>let&#8217;s check our version because all of this code is bleeding edge stuff</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ node <span style="color: #660033;">-v</span>
v0.1.102</pre></div></div>

<p>also, let&#8217;s grab <a href="http://github.com/isaacs/npm" title="node.js package manager">npm</a> first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">git clone http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>github.com<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>isaacs<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>npm
<span style="color: #7a0874; font-weight: bold;color: #8FB394;">cd</span> npm; <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span></pre></div></div>

<p>now we can install <a href="http://expressjs.com/" nofollow="true">express</a> and it&#8217;s supporting modules that we want:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> jade
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">less</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> connect
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> express</pre></div></div>

<p>playing with it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">mkdir</span> test<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>; <span style="color: #7a0874; font-weight: bold;color: #8FB394;">cd</span> <span style="color: #7a0874; font-weight: bold;color: #8FB394;">test</span>;
express <span style="color: #666666; font-style: italic;"># generates a new app</span>
node app.js <span style="color: #666666; font-style: italic;"># to start the server</span>
<span style="color: #666666; font-style: italic;"># switch to a diff. window</span>
curl 127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">3000</span></pre></div></div>

<p>speed?<br />
much slower than native node.js but hey, it takes a lot of pain away<br />
it&#8217;s still slightly retarded fast compared to say rails and django</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">1000</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">3000</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">1200.16</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span></pre></div></div>

<p><strong>Support &#038;&#038; References</strong><br />
shit tons of ppl on the #node.js irc channel</p>
<p>Need something to show the boss &#8212; <a href="http://www.paulbarry.com/node/" nofollow="true">some slides</a></p>
<p>My mind is literally wheeling with the crazy shit that this framework allows you to do&#8230; particularly remotely&#8230;</p>
<p>Last thing before you leave, <a href="http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html" title="node.js presented by ryan dahl at jsconf 2009" nofollow="true">watch this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stopping the OOM Pain &#8212; Removing JVM Memory Leaks</title>
		<link>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/</link>
		<comments>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:11:20 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=386</guid>
		<description><![CDATA[If you are like me you probably have to be working in several different languages at any given time and monitoring more than a handful of daemons. Sometimes your tests do not catch crucial items that they should be catching. As my loyal readers might already know I do not consider myself as knowledgeable about [...]]]></description>
			<content:encoded><![CDATA[<p>If you are like me you probably have to be working in several different languages at any given time and monitoring more than a handful of daemons. Sometimes your tests do not catch crucial items that they should be catching. As my loyal readers might already know I do not consider myself as knowledgeable about the JVM and java as I should be. These past couple of days were a lesson in humliity when it comes to garbage collection on the JVM.</p>
<p>I grew up learning how to write code using C from man pages managing memory on my own. Malloc and free were my friends and I would pride myself on running <a href="http://valgrind.org" nofollow="true">valgrind</a> on a paritcular piece of code passing through it&#8217;s tests.</p>
<p><center><br />
<img src="http://airodig.com/wp-content/uploads/2010/07/final.gif" /><br />
</center></p>
<p>The JVM of course uses a managed memory model with it&#8217;s garbage collector. This means no more memory leaks right? <b>Wrong.</b></p>
<h2>Example:</h2>
<p>Let&#8217;s suppose you have an object you instantiated called Blah. Blah gets used but is never de-referenced nor does it have a way to tell the GC that it is a candidate for removing. (You never actually remove an object &#8212; you just tell the garbage collector that is is ready to be removed. </p>
<p><i>&#8221; Note the wording: Just because an object is a candidate for collection doesn&#8217;t mean it will be immediately collected.&#8221;</i> <a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997429" nofollow="true" />Candidate for Removal</a></p>
<p>What happens after you instantitate 300k of these Blah objects that use 80 bytes a pop? You just lost 22 meg that you won&#8217;t regain until you kill that process!</p>
<p>So to cut to the chase I had a tomcat servlet that kept dying about once a week and I didn&#8217;t allocate any time to look at it what the problem was until now as I could just restart it and everything would be peachy. I finally decided to look at it.</p>
<p>This is what I did.</p>
<h2>Get a Heap Dump</h2>
<p>First, you need to obtain a heap dump &#8212; without the heap dump you are having better luck at the casino. Chances are if you are crashing cause of an OOM memory error you won&#8217;t be able to get your heap dump from the production site &#8212; we don&#8217;t really want to screw with that anyways.</p>
<p>So, let&#8217;s duplicate our results on our dev box. Like I said before, we were looking at a tomcat servlet that was not working so in theory we should be able to hit our servlet with enough requests to trigger some heap growth.</p>
<p>I wrote a quick little script in ruby to slam our servlet, here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#008000; font-style:italic;color: #CDC;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'uri'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'net/http'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'cgi'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'timeout'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'monitor'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;color: #343832;">File</span>.<span style="color:#CC0066; font-weight:bold;color: #8FB394;">open</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">'b.txt'</span>, <span style="color:#996600;color: #666666;">'r'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>f<span style="color:#006600; font-weight:bold;color: #CCC;">|</span> <span style="color:#0066ff; font-weight:bold;color: blue;">@filetopost</span> = f.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#0066ff; font-weight:bold;color: blue;">@params</span> = <span style="color:#006600; font-weight:bold;color: #CCC;">&#123;</span><span style="color:#996600;color: #666666;">'text'</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;color: #343832;">CGI</span>::escapeHTML<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>@filetopost<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>, <span style="color:#996600;color: #666666;">'submit'</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#996600;color: #666666;">'Submit'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> pingsite
  500.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>i<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
    x = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">post_form</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#CC00FF; font-weight:bold;color: #343832;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">'http://127.0.0.1:8080/upload/process'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>, <span style="color:#0066ff; font-weight:bold;color: blue;">@params</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;color: #8FB394;">puts</span> i
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
threads = <span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span>
<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>1..20<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>i<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
  threads <span style="color:#006600; font-weight:bold;color: #CCC;">&lt;&lt;</span> <span style="color:#CC00FF; font-weight:bold;color: #343832;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span>
    pingsite
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
threads.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>t<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
  t.<span style="color:#9900CC;">join</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span></pre></div></div>

<p>This essentially as you might have guessed posts the contents of a text file through a form to our servlet for processing (text into xml). It makes 10k requests (500 at 20 threads).</p>
<p><b>BEFORE</b> you run this you&#8217;ll want to hop into jconsole. <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" nofollow="true">JConsole</a> will allow you to watch the action live as you see your heap grow and be garbage collected. You&#8217;ll see that the faster the heap grows the faster the garbage collector will start to run so your graph will start to have it&#8217;s lines closer together. What you are wanting to do here is just make the graph curve upward &#8212; that&#8217;s it.</p>
<p>Once you have a graph that looks like this:</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/heap.png"><img src="http://airodig.com/wp-content/uploads/2010/07/heap-162x300.png" alt="" title="heap" width="162" height="300" class="aligncenter size-medium wp-image-403" /></a><br />
</center></p>
<p>we are ready for the next step. This graph actually grew up into the 400s and was much more pronounced by the time my 10k requests were done &#8212; all you really need to do is show proof that there is a growth &#8212; the more the merrier as it should help you drill down more easily to determine what is piling up.</p>
<h2>Dump the Heap</h2>
<p>Find out the process we need to dump:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">ps</span> aux <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">grep</span> tomcat</pre></div></div>

<p>dump it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">jmap -dump:live,<span style="color: #007800;">format</span>=b,<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">file</span></span>=heap.bin <span style="color: #000000;background-color: #000000; color: #DDD;">6608</span></pre></div></div>

<p>The dump will need to be initiated by the same user owning the tomcat process or someone with perms for it (tomcat6, root, joebob, whatever).</p>
<p>Great! Let&#8217;s take a quick look at the size</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">ls</span> <span style="color: #660033;">-lh</span> heap.bin</pre></div></div>

<p>200 meg! WTF!?</p>
<h2>Get Relevant Stats</h2>
<p>Ok, now let&#8217;s hop into jvisualvm (visualvm). I went ahead and changed the perms on the dump file so I could run it as my own user. Once in visualvm we want to go to our classes view in the top right hand corner. From here we can sort by # of instances or % of how much the heap is towards the object. I focused on instance count because that seemed like something that would let me know what was up. I noticed that at least one thing was wrong here. I had something like 300k prepared statement instances being built &#8212; what the fuck?! </p>
<h2>Fix the Problem</h2>
<p>So I went back to my code and did a .close() on them.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">        <span style="color: #666666; font-style: italic;color: #CDC;">// note this is scala</span>
        pStmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
&nbsp;
        pStmt.<span style="color: #006633;">close</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span>stmt <span style="color: #339933;color: #CCC;">!=</span> <span style="color: #000066; font-weight: bold;color: #577A61;">null</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
          stmt.<span style="color: #006633;">close</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<h2>Measure Again to Ensure the Problem is Fixed</h2>
<p>After this was done we compile our jar, throw it back to our servlet, <b>restart</b> tomcat and run through our bulk POSTing again. The theory here is that we should be able to have a noticeable impact our instance count for prepared statements and have a noticeably different graph as well. I did not know that simply copying your webapp over to the root directory was not enough &#8212; you NEED to restart tomcat to get accurate results as items in the PermGen space will be duplicated if you simply copy a new webapp over (and after doing that a couple of times you&#8217;ll find a nice little PermGen OOM error in your catalina log files.)</p>
<p>Here&#8217;s the new graph:</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/dramatic.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/dramatic-160x300.jpg" alt="" title="dramatic" width="160" height="300" class="aligncenter size-medium wp-image-404" /></a><br />
</center></p>
<p>The new heap size is :<b>20 meg!!</b></p>
<p>Well, we might not have squashed all of our bugs but I&#8217;d bet good money that this servlet doesn&#8217;t die again in the next week or so.</p>
<h2>Other Profiling Tools I Used but Did not Like:</h2>
<p><b>jhat</b>: I tried this out and it seems like it is supposed to be used on remote servers, however, there was absolute NO thought put into making it a nice UI to use by a human and it didn&#8217;t particularly lend itself well to a computer looking at information so frankly I think it&#8217;s a piece of shit.</p>
<p><b>Memory Analyzer</b>: Speaking of piece of shit, this rotten crap came with Eclipse (now, I have my own opinions about how horrible eclipse is to begin with so maybe that&#8217;s just my prejudice rubbing off) but this kept crashing every fucking time I tried to load the heap. I tried passing in the arguments -Xms128m -Xmx1024m and all but it just did not like me. Fuck it &#8212; I got the job done regardless.</p>
<p>Anyways, I hope this information was somewhat useful for someone else &#8212; while documentation exists on the internet for this it wasn&#8217;t the most readily available info.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Join the Sax Parsing Party</title>
		<link>http://airodig.com/2010/07/01/join-the-sax-parsing-party/</link>
		<comments>http://airodig.com/2010/07/01/join-the-sax-parsing-party/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 03:24:03 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=388</guid>
		<description><![CDATA[Many people utilize the DOM based parsing methods available in easy to use libraries throughout most languages but few ever need to utilize the power of SAX. Let me invite you to the party! We&#8217;ve all been there &#8212; we need to parse an xml document so we pull out some xpath expression and get [...]]]></description>
			<content:encoded><![CDATA[<p>Many people utilize the DOM based parsing methods available in easy to use libraries throughout most languages but few ever need to utilize the power of SAX. Let me invite you to the party!</p>
<p>We&#8217;ve all been there &#8212; we need to parse an xml document so we pull out some xpath expression and get to work on grabbing our little bit of data from our document.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">token = <span style="color:#6666ff; font-weight:bold;">REXML::XPath</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>doc, <span style="color:#996600;color: #666666;">&quot;/books/title/&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span></pre></div></div>

<p>This works great and is easy to use no matter your language of choice for <b>MOST</b> things. Now, let&#8217;s pretend this particular document is 10 meg &#8212; fuck that, let&#8217;s pretend it&#8217;s 100 meg &#8212; actually let&#8217;s get real and call it 2.5 gig of xml. </p>
<p><center><b><i>2.5!!! WTF!? That won&#8217;t fit into my memory!?!?</i></b></center></p>
<p>No, it won&#8217;t if you are using DOM parsing since that is based upon building a tree. That is if you are willing to wait for the fucker to even load itself into the tree &#8212; forget the memory usage.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/xml-rom-tree.png"><img src="http://airodig.com/wp-content/uploads/2010/07/xml-rom-tree-300x152.png" alt="" title="xml-rom-tree" width="300" height="152" class="aligncenter size-medium wp-image-394" /></a><br />
</center></p>
<p>I ran into this problem earlier today &#8212; memory hit a little over what the document size was in htop but the cpu just kept <a href="http://www.youtube.com/watch?v=eFTLKWw542g">burning while the world was turning</a>. I eventually killed it and contemplated splitting the xml apart &#8212; of course &#8230; I was going to run into the exact same problem if I continued to utilize the old worn out DOM parsing methods.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/fuuu.png"><img src="http://airodig.com/wp-content/uploads/2010/07/fuuu-300x224.png" alt="" title="fuuu" width="300" height="224" class="aligncenter size-medium wp-image-395" /></a><br />
</center></p>
<p>This is when I was turned onto SAX parsing from some random mailing list plea for help. All I need to know I learnt from man pages and mailing lists. I had ran across SAX in the past but was not too excited that I had to prepare a language <b>JUST</b> to parse my document rather than pass it some tried and true xpath &#8212; basically I was used to parsing html DOM &#8212; NOT million line xml documents. I had read that it was faster in the past but my feeble attempts at comparing documents of the 200k size were just an exercise in futility to find any meaning in using SAX. </p>
<p><center><br />
<i>Needless to say knowing the power of SAX is like shooting Columbian cocaine, XPath is drinking a pot of coffee, and regex is getting punched in the nuts while you are asleep.</i><br />
</center></p>
<p>Now let me address the audience in what happened. That little job I killed that was bitch-smacking one of my cores around for over 10 minutes and using over 10% of 6gig of memory did the EXACT same extraction under 10 seconds utilizing something like 0.1% of memory and only 70%ish CPU. I, to use the phrase slightly, shit a fucking brick!</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/ShitBrick.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/ShitBrick-300x227.jpg" alt="" title="ShitBrick" width="300" height="227" class="aligncenter size-medium wp-image-391" /></a><br />
</center></p>
<p>Want to see an utterly contrived example of pulling 40+k urls from a sitemap which tied up my cores for-fucking-ever using old style DOM parsing but was done in less than 10 seconds with SAX?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rexml/document'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rexml/streamlistener'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'mysql'</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">include</span> REXML
&nbsp;
MY = Mysql.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;host&quot;</span>, <span style="color:#996600;color: #666666;">&quot;luser&quot;</span>, <span style="color:#996600;color: #666666;">&quot;assword&quot;</span>, <span style="color:#996600;color: #666666;">&quot;dbname&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">class</span> ParseThatShit
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">include</span> <span style="color:#6666ff; font-weight:bold;">REXML::StreamListener</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> tag_start<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#006600; font-weight:bold;color: #CCC;">*</span>args<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> text<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>data<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;color: #577A61;">return</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">if</span> data =~ <span style="color:#006600; font-weight:bold;color: #CCC;">/</span>^\w<span style="color:#006600; font-weight:bold;color: #CCC;">*</span>$<span style="color:#006600; font-weight:bold;color: #CCC;">/</span>
    <span style="color:#0000FF; font-weight:bold;color: #577A61;">return</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">if</span> data =~ <span style="color:#006600; font-weight:bold;color: #CCC;">/</span>\d\.\d<span style="color:#006600; font-weight:bold;color: #CCC;">/</span>
    st = MY.<span style="color:#9900CC;">prepare</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;insert into links (name) values (?)&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    st.<span style="color:#9900CC;">execute</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>data<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    st.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
pts = ParseThatShit.<span style="color:#9900CC;">new</span>
xmlfile = <span style="color:#CC00FF; font-weight:bold;color: #343832;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;big-ass-sitemap.xml&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
Document.<span style="color:#9900CC;">parse_stream</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>xmlfile, pts<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span></pre></div></div>

<p>Remember boys and girls &#8212; this <b>Example</b> is just an example to show you the power of SAX &#8212; does it take more LOC than a 3 line xpath block? Yeh, but so does your mother.</p>
<p>Use the power of SAX and drink the spice while you slip into the higher dimension of parsing power!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/01/join-the-sax-parsing-party/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dancing Your Way into EffortLess Web Development with Dancer and Perl</title>
		<link>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/</link>
		<comments>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/#comments</comments>
		<pubDate>Wed, 26 May 2010 20:27:56 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dancer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=352</guid>
		<description><![CDATA[Sentiments found on hackernews and dzone recently regarding Perl: &#8220;fuck a bunch of perl monk motherfuckers!&#8221; &#8220;perl sucks!&#8221; &#8220;perl can suck a dick!&#8221; ok, well that was slightly exagerrated =) but .. so seems the sentiment sometimes browsing certain portions of the net (dzone, hackernews, etc.) Really, imo perl was one of the first dynamic [...]]]></description>
			<content:encoded><![CDATA[<h1 style="margin: 10px;">Sentiments found on hackernews and dzone recently regarding Perl:</h1>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;fuck a bunch of perl monk motherfuckers!&#8221;</u></p>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;perl sucks!&#8221;</u></p>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;perl can suck a dick!&#8221;</u></p>
<p>ok, well that was slightly exagerrated =)</p>
<p>but .. so seems the sentiment sometimes browsing certain portions of the net<br />
(dzone, hackernews, etc.)</p>
<p>Really, imo perl was one of the first dynamic interpreted languages that a <strong>LOT</strong> of people<br />
got on board with and really opened the door to web development&#8230; say what<br />
you want but perl was the &#8220;first web language&#8221;™</p>
<h2>Dancer</h2>
<p>A couple of weeks I ran into <a href="http://perldancer.org/" title="perl web framework" nofollow="true">dancer</a>. I was really quite interested because it&#8217;s cousin,<br />
<a href="http://www.sinatrarb.com/" title="sinatra rub framework" nofollow="true">sinatra</a> from rubyland is my favorite framework from that language.</p>
<p>I have to admit that I have not used perl for a while but I had dancer up and tapping it&#8217;s toes<br />
within minutes and it is pretty damn fast.</p>
<p>can I sum it up?<br />
yes &#8230;. dancer turns perl web development from this&#8230;<br />
<center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/perl.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/perl-270x300.jpg" alt="perl" title="perl" width="270" height="300" class="aligncenter size-medium wp-image-358" /></a><br />
</center></p>
<p><center><br />
into this&#8230;<br />
</center></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/perl-camel.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/perl-camel-231x300.jpg" alt="marlboros camel" title="perl-camel" width="231" height="300" class="aligncenter size-medium wp-image-366" /></a><br />
</center</p>
<h2>installing</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> cpan Dancer</pre></div></div>

<p>cpan will block when it&#8217;s dling new modules so make sure to pay attn to any visual beeps if you are in screen or something, or you could always use expect or whatever</p>
<p><strong>Sample Hello World written in Dancer</strong></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #666666; font-style: italic;color: #CDC;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;color: #577A61;">use</span> Dancer<span style="color: #339933;color: #CCC;">;</span>
&nbsp;
get <span style="color: #ff0000;">'/hi'</span> <span style="color: #339933;color: #CCC;">=&gt;</span> <span style="color: #000000; font-weight: bold;color: #577A61;">sub</span> <span style="color: #009900;color: #CCC;">&#123;</span>
  <span style="color: #ff0000;color: #666666;">&quot;Hello World!&quot;</span>
<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
dance<span style="color: #339933;color: #CCC;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ <span style="color: #c20cb9; font-weight: bold;color: #577A61;">perl</span> .<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>hi.pl</pre></div></div>

<p>hit it up at: http://127.0.0.1:3000/hi</p>
<p><strong>Some Slightly Drunken Made Benchmarks:</strong><br />
<i>That last red bar should be at 672 request/second.</i></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/benches.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/benches-300x150.jpg" alt="" title="benches" width="300" height="150" class="aligncenter size-medium wp-image-362" /></a><br />
</center></p>
<p>need some more example code? check out the <a nofollow="true" href="http://github.com/sukria/perldancer-website" title="dancer website source">dancer website source</a> built using dancer</p>
<h2>Deploying Dancer into Production</h2>
<p>I&#8217;d avoid abusing this <strong>ass-rocking software</strong> with something as terrible as apache as you just won&#8217;t get the same performance and you&#8217;ll have to do stupid CGI/FastCGI tricks. However, if you must use apache (because you are already using it for 10 other websites on the same box) then you can still use PSGI.</p>
<p>Dancer runs best under <a nofollow="true" href="http://plackperl.org/" title="PSGI/PLACK">PSGI/PLACK</a></p>
<p>Wait! What the fuck is that shit? PSGI is a spec akin to Python&#8217;s <a href="http://wsgi.org/wsgi/" title="WSGI" nofollow="true">WSGI</a> while PLACK is to <a title="ruby rack" nofollow="true" href="http://rack.rubyforge.org/">ruby&#8217;s Rack</a>.</p>
<p>confused? just use <strong><a href="http://github.com/miyagawa/Starman" title="starman -- perl web server" nofollow="true">Starman</a>!!</strong>&#8211; <a href="http://search.cpan.org/~miyagawa/Starman-0.1000/lib/Starman.pm" title="starman" nofollow="true">Perl Reference</a></p>
<p><strong>StarMan Features</strong></p>
<ul>
<li>preforking web server that reaps dead kids and does auto restarts</li>
<li>can utilize unix sockets</li>
<li>very little memory footprint (like 7-12 meg little)</li>
<li>No Win32 Support, yes this is a feature</li>
</ul>
<p>It&#8217;s also written by Japanese hackers. I don&#8217;t think I need to mention why Japanese hackers rock..</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/05/yukihiro_matsumoto.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/yukihiro_matsumoto-201x300.jpg" alt="Yukihiro Matsumoto" title="yukihiro_matsumoto" width="201" height="300" class="aligncenter size-medium wp-image-355" /></a><br />
</center></p>
<p>back to dancer&#8230;</p>
<p><strong>supported session engines by default:</strong></p>
<ul>
<li>memory (no persistence &#8212; useful for debugging)</li>
<li>yaml file-based (puke!)</li>
<li>memcached (distributed production env ftw!)</li>
<li>cookie (make sure you protect your shit from timing attacks)</li>
</ul>
<p><strong>other features:</strong></p>
<ul>
<li>wilcard routing path matching</li>
<li>before filters</li>
</ul>
<p>In comparison to Catalyst? Well, the most obvious is that Dancer is light-weight &#8212; like cheerleader on prom night light-weight.</p>
<h2>In Closing</h2>
<p>For my next &#8216;small&#8217; project this will probably be written with Dancer rather than Sinatra.<br />
Yes, the terse syntax of perl might not meet the eloquence of ruby but for memory usage<br />
Dancer will win hands down everytime.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Oriented with OrientDB</title>
		<link>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/</link>
		<comments>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/#comments</comments>
		<pubDate>Sat, 22 May 2010 18:46:47 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[document database]]></category>
		<category><![CDATA[graph database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[orientdb]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=341</guid>
		<description><![CDATA[Was on the nosql mailing list the other day and I ran across a message from Cliff Moon trolling it up &#8220;I find the name of your database to be extremely racist.&#8221; To tell you the truth I usually am ctrl-D&#8217;ng (mutt mass deleting) all threads from this mailing list since I just do not [...]]]></description>
			<content:encoded><![CDATA[<p>Was on the nosql mailing list the other day and I ran across a <a href="http://groups.google.com/group/nosql-discussion/browse_thread/thread/9195b95348477716/9b150aefddcd2718#msg_b4fb3cc1dfffed63">message</a> from <a href="http://twitter.com/moonpolysoft">Cliff Moon</a> trolling it up </p>
<p><center></p>
<h2>
<b><i>&#8220;I find the name of your database to be extremely racist.&#8221;</i></b><br />
</h2>
<p></center></p>
<p>To tell you the truth I usually am ctrl-D&#8217;ng (mutt mass deleting) all threads from this mailing list since I just do not have time to read them all. This of course caught my eye though and I&#8217;ve been waiting for a day to set aside some time to write up an article on it. So that day is today and this is that article.</p>
<p>These guys make a TON of claims and the description page is chockful of buzzwords describing what exactly OrientDB is. Let&#8217;s take a quick look.<br />
<strong>Features</strong></p>
<ul>
<li>Written in Java</li>
<li>40k inserts/second on commodity hardware</li>
<li>Document/Graph Based DataBase</li>
<li>Supports Schema-less, schema-full, schema-mixed modes</li>
<li>Security Profiling for users/roles Based Access</li>
<li>Supports SQL as a query language</li>
<li>ACID compliant with support for transactions</li>
<li>Less than 400k Footprint for Full Server (embeddable)</li>
</ul>
<p>It is truthly very easy to get started unlike other solutions out there. It unfortuantely has a XML config file but the default one that comes with the release I downloaded (0.9.13) clocks in at only 22 lines and is fairly readable. It listens for binary connections on port 2424 by default and a built-in web interface on 2480 by default. The <a href="http://orient.googlecode.com/files/orient-database-0.9.14.zip">package I downloaded</a> came with jars ready to go so there was no bullshit to configure or anything but if you grab sources ant should work things out for you.</p>
<p><b>Example:</b></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">svn</span> checkout https:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>orient.googlecode.com<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>svn<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>trunk<span style="color: #000000; font-weight: bold;color: #CCC;">/</span> orient
<span style="color: #7a0874; font-weight: bold;color: #8FB394;">export</span> <span style="color: #007800;">JAVA_HOME</span>=<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>jvm<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>java-<span style="color: #000000;background-color: #000000; color: #DDD;">6</span>-sun-1.6.0.20<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">chmod</span> a+x build.sh
.<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>build.sh</pre></div></div>

<p>Like any good startup script it proudly displays it&#8217;s ascii logo.<br />
It really is quite a nice little web interface I have to admit. For those of you who have/want to care about licenses it is under the Apache 2.0 License. There are currently 12 members on it&#8217;s <a href="http://groups.google.com/group/orient-database/about">google groups mailing list</a>.</p>
<p><strong>Web Interface</strong><br />
The web interface has a RESTful interface that supports GET, PUT, POST, and DELETE operations. This is really cool because then you can do all your requests with javascript and pull down result sets with json. Being able to put this crap behind a load balancer allows you to scale like a motherfucker when it comes to reads, which is one reason why other databases that have RESTful interfaces caught on so quickly. It has a built in profiler that really rocks out and I firmly believe all software should have built in shit like this &#8212; it is just common sense for applications like this. There are tabs right next to it that show you configurations, connections and and database pools &#8212; cool stuff indeed.</p>
<div id="attachment_348" class="wp-caption aligncenter" style="width: 310px"><a href="http://airodig.com/wp-content/uploads/2010/05/profiler.png"><img src="http://airodig.com/wp-content/uploads/2010/05/profiler-300x168.png" alt="OrientDB Profiler" title="profiler" width="300" height="168" class="size-medium wp-image-348" /></a><p class="wp-caption-text">OrientDB Profiler</p></div>
<p>The schema view is pretty cool as well as you can see all of your classes (tables) , their record count and their cluster count. Physical clusters make for fast IO, whereas logicals save space but are slower. Of course in the day and age of pocket terrabyte storage drives &#8212; who the hell needs more space? We need ram and cpu damnit!</p>
<p><strong>Security</strong><br />
I must say that out of all the NoSQL solutions out there <a href="http://www.orientechnologies.com/">OrientDB</a> really fucking shines with it&#8217;s security built-in from the get-go &#8212; almost every other system out there has added it on as an *optional* feature &#8212; as if security should ever be treated that way &#8212; it&#8217;s like modern day programmers for some reason still do not know that 14 year old kids have scripts that scan the net for open things like this &#8212; some mid-20s kids have those exact same scripts. <img src='http://airodig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Apparently the underlying data structure is a &#8220;RB+Tree&#8221; which as the authors point out is a mix of Red-Black and B+ Tree algos &#8212; this they assert give you the best mix of balancing, speed, and 50% less memory usage.</p>
<p>All in all this is a pretty nice offering and I might need to play with again here in the future. I have a couple million xml documents I&#8217;m thinking about transforming to json. What are your thoughts on this fellow readers?</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Play with Java and Scala Web Apps</title>
		<link>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/</link>
		<comments>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 19:56:59 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[webapps]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=323</guid>
		<description><![CDATA[I got wind of the play framework a couple of months ago and have been passively reading their mailing list each day. I have to say &#8212; it&#8217;s very active and the framework is just top notch. We here at telematter have used a lot of the frameworks in ruby land and our main app [...]]]></description>
			<content:encoded><![CDATA[<p>I got wind of the <a href="http://playframework.org">play framework</a> a couple of months ago and have been passively reading their mailing list each day. I have to say &#8212; it&#8217;s very active and the framework is just top notch. We here at <a href="http://telematter.com">telematter</a> have used a lot of the frameworks in ruby land and our main app is written in merb. Lately though merb has become a ghost-town of support, documentation, and community involvement. Upgrading a server takes an exorbinant amount of time, patience and the willingness <b>NOT</b> to throw you computer through the window.</p>
<p><a href="http://yehudakatz.com/2010/04/17/ruby-require-order-problems/">Dependencies are a big problem</a> here but so are the tests. With the ruby community&#8217;s ever so crushing pride about various ways to accomplish a task you usually wind up having to either pick between the options of using a LOT of plugins/dependencies or not using any. Also, you know you have problems when after spending the better part of a morning upgrading your dev environment you can&#8217;t run your tests.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/for-your-butthole.gif"><img src="http://airodig.com/wp-content/uploads/2010/04/for-your-butthole-263x300.gif" alt="" title="for-your-butthole" width="263" height="300" class="aligncenter size-medium wp-image-332" /></a><br />
</center></p>
<p>So we started looking at different web application frameworks. We have a rather large existing codebase in java already to do some text parsing but xml config files and the ever-growing concern of java developers to deal with encapsulation in the most fucked up manner imaginable leads us having java with a sour taste in our mouths. Scala on the other hand has been what I have deemed <i><b>&#8220;what java SHOULD have been&#8221;</b></i>. Seriously, that language is so elegant compared to it&#8217;s predecessor that they should just scrap everything and move on from that point forward. The JVM is really solid shit but java itself &#8212; ehh&#8230;</p>
<p>Anyways on to the meat of this quick article. Why do I like play?</p>
<ul>
<li> class reloading</li>
<li> easy setup</li>
<li>fucking awesome test runner</li>
<li> great documentation &#038;&#038; active community </li>
<li> NO xml config files </li>
<li> use with scala </li>
</ul>
<h2>Class Reloading</h2>
<p>  Do I even need to explain this one? Having the ability to reload your classes on the fly without having to go through configuration hell is so ridiculously helpful it&#8217;s insane. Your development productivity will gain leaps and bounds and with integrated auto-testing you are assured a winner.</p>
<h2>Easy Setup</h2>
<p>  It does not get easier than a:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">wget</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>download.playframework.org<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>releases<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>play-1.0.2.1.zip
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">unzip</span> play<span style="color: #000000; font-weight: bold;color: #CCC;">*</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">cp</span> <span style="color: #660033;">-R</span> play<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>play
play new my_new_app
play run</pre></div></div>

<h2>Fucking Awesome Test Runner</h2>
<p> I need to attach these screenshots to show you the awesomeness of this.</p>
<p><b>Test Index</b><br />
<center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/Screenshot.png"><img src="http://airodig.com/wp-content/uploads/2010/04/Screenshot-300x168.png" alt="play framework test index" title="play framework test index" width="300" height="168" class="aligncenter size-medium wp-image-324" /></a><br />
</center></p>
<p><b>Selenium Test Runner</b></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/Screenshot-1.png"><img src="http://airodig.com/wp-content/uploads/2010/04/Screenshot-1-300x168.png" alt="play framework selenium test" title="play framework selenium test" width="300" height="168" class="aligncenter size-medium wp-image-326" /></a><br />
</center></p>
<h2>Great Documentation &#038;&#038; Active Community </h2>
<p>  When you first boot up Play (and it boots FAST) you will find that you have all the basics to start hacking up the HelloWorld into whatever you wish. A simple click of the mouse gives you your environment settings (which show you everything from paths to thread info, to monitors). Play also has a cool little route built in http://127.0.0.1:9000/@documentation that has screencasts, sample apps, faqs, and pretty much everything you need to know to start playing around.</p>
<p>  Admittedly there were only 12 users online in IRC earlier today when I wrote it but the mailing list has ~30 emails/day with active development/discussion.</p>
<h2>NO XML Config Files </h2>
<p> Yes, that&#8217;s right ladies and gentlemen &#8212; no goddamn config files written in fucking XML. WTF! Your main config file, application.conf is just your basic java properties set &#8212; no need to get all crazy and declare everything under the sun.</p>
<p>  What&#8217;s the routes look like?</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"># Routes
# <span style="color: #000000; font-weight: bold;color: #B83A24;">This</span> file defines all application routes <span style="color: #009900;color: #CCC;">&#40;</span>Higher priority routes first<span style="color: #009900;color: #CCC;">&#41;</span>
# ~~~~
&nbsp;
# Home page
GET     <span style="color: #339933;color: #CCC;">/</span>                                       Application.<span style="color: #006633;">index</span>
&nbsp;
# <span style="color: #003399;color: #8FB394;">Map</span> <span style="color: #000000; font-weight: bold;color: #B83A24;">static</span> resources from the <span style="color: #339933;color: #CCC;">/</span>app<span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span> folder to the <span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span> path
GET     <span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span><span style="color: #339933;color: #CCC;">/</span>                                staticDir<span style="color: #339933;color: #CCC;">:</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span>
&nbsp;
# <span style="color: #000000; font-weight: bold;color: #B83A24;">Catch</span> all
<span style="color: #339933;color: #CCC;">*</span>       <span style="color: #339933;color: #CCC;">/</span><span style="color: #009900;color: #CCC;">&#123;</span>controller<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #339933;color: #CCC;">/</span><span style="color: #009900;color: #CCC;">&#123;</span>action<span style="color: #009900;color: #CCC;">&#125;</span>                  <span style="color: #009900;color: #CCC;">&#123;</span>controller<span style="color: #009900;color: #CCC;">&#125;</span>.<span style="color: #009900;color: #CCC;">&#123;</span>action<span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p>yeh&#8230;.. they are that simple looking</p>
<h2>Use with Scala </h2>
<p>  There is a <a href="http://www.playframework.org/modules/scala">scala module</a> that I highly recommend you download and use &#8212; oh and if you like scala &#8212; you can get on the <a href="http://www.playframework.org/modules/akka">akka</a> bandwagon as well. It&#8217;s also highly recommended.</p>
<p>Do yourself a favor and <a href="http://playframework.org">Play Now</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Mighty Awesome Power of Scala</title>
		<link>http://airodig.com/2010/03/21/the-mighty-awesome-power-of-scala/</link>
		<comments>http://airodig.com/2010/03/21/the-mighty-awesome-power-of-scala/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 15:38:49 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=308</guid>
		<description><![CDATA[Over at work we (I) have been getting pretty fed up with ruby lately. There is way too much fanboyism and not enough code. So I&#8217;ve been looking at doing things in different frameworks lately. This of course always leads to me having to try out new languages that I might have only looked at [...]]]></description>
			<content:encoded><![CDATA[<p><div id="attachment_313" class="wp-caption alignleft" style="width: 304px"><a href="http://airodig.com/wp-content/uploads/2010/03/ruby-rhod.jpg"><img src="http://airodig.com/wp-content/uploads/2010/03/ruby-rhod.jpg" alt="" title="ruby-rhod" width="294" height="283" class="size-full wp-image-313" /></a><p class="wp-caption-text">Ruby FanBoy</p></div>Over at work we (I) have been getting pretty fed up with ruby lately. There is way too much fanboyism and not enough code. So I&#8217;ve been looking at doing things in different frameworks lately. This of course always leads to me having to try out new languages that I might have only looked at a couple of times before. Two things that I&#8217;d look in a web framework to make my life easier are:</p>
<p><b>1) class reloading</b><br />
<b>2) dynamic typing OR a sweet ass type inference engine</b></p>
<p>I could not stress these two points more. I do NOT want to have to recompile/reload my classes every time I make a simple edit to the code &#8212; having this with ruby/merb has just made tremendous strides in how fast we can flesh out features. I also HATE having to declare types for my methods, variables, etc. I think it&#8217;s a waste of time and good code should not have to do that (especially if you are using type inference like all good languages do).</p>
<p>So eventually I came across lift which I thought sucked right out since it likes maven/xml. Seriously, xml files were NOT meant to be configuration files &#8212; goto hell!</p>
<p>However, recently on another front my colleague and I have already been looking at languages that run on the JVM for another project for the same website. We&#8217;ve been looking into scalability concerns with big data and have both concluded that we want/need the power of the JVM but really do not like java particularly too much. This has led us to look at the two up and comers: Scala and Clojure. Recently I got ahold of the pragprog book and started flipping through it&#8217;s pages. One section in particular caught my eye. The author in a matter of 5-10 lines or so was able to open up a file, scrape some xml from the web, parse it and then save it. I was like &#8212; WHAT THE FUCK!? In java the exact same code would have had to have gone through the verbosity monster making machine and clock in at 20-30 lines easily.</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/03/easy.jpg"><img src="http://airodig.com/wp-content/uploads/2010/03/easy-300x231.jpg" alt="" title="easy" width="300" height="231" class="aligncenter size-medium wp-image-315" /></a></center><br />
So I kept reading the book! Another thing that immediately jumped out at me &#8212; where&#8217;s all your fucking semi-colons!? Oh those? We don&#8217;t need no fucking semi-colons in our language! </p>
<p><b style="font-size: 1.5em;">Motherfucking <3</b></p>
<p>This was enough for me to seriously start thinking about re-writing our main java project. This particular project has 10 (count them ten) antlr grammars and quite a few supporting classes along with CLI wrappers to said classes. We have quite a few test suites for each class thankfully otherwise this project would probably not be so possible without seriously killing it.</p>
<p>I first started converting one of our main classes over. Replace the for loops, drop the semicolons, take out the public identifiers, etc. Let&#8217;s try to compile. Oh noes! We don&#8217;t have access to these methods anymore. This is where javap comes in handy when you are converting from java &#8211;> scala. Javap will show you what the REAL class name or method name is for each language. Keep in mind my original intention was to just get a scala class to compile and use it FROM java. Now I&#8217;m on route to be using everything from scala but it really doesn&#8217;t matter &#8212; as long as you have class files and as long as those class files have access to the right methods/variables you are set.</p>
<p>Let&#8217;s say we have a seat class written in scala:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #0000ff; font-weight: bold;color: #B83A24;">package</span> com.<span style="color: #000000;">bluffware</span><span style="color: #000080;color: #CCC;">;</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;color: #B83A24;">class</span> Seat<span style="color: #F78811;color: #CCC;">&#40;</span><span style="color: #F78811;color: #CCC;">&#41;</span> <span style="color: #F78811;color: #CCC;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> id<span style="color: #000080;color: #CCC;">:</span>Int <span style="color: #000080;color: #CCC;">=</span> <span style="color: #F78811;background-color: #000000; color: #DDD;">0</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> number<span style="color: #000080;color: #CCC;">:</span>Int <span style="color: #000080;color: #CCC;">=</span> <span style="color: #F78811;background-color: #000000; color: #DDD;">0</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> seat<span style="color: #000080;color: #CCC;">_</span>id<span style="color: #000080;color: #CCC;">:</span>Int <span style="color: #000080;color: #CCC;">=</span> <span style="color: #F78811;background-color: #000000; color: #DDD;">0</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> sitout<span style="color: #000080;color: #CCC;">:</span>String <span style="color: #000080;color: #CCC;">=</span> <span style="color: #6666FF;color: #666666;">&quot;&quot;</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> position<span style="color: #000080;color: #CCC;">:</span>String <span style="color: #000080;color: #CCC;">=</span> <span style="color: #6666FF;color: #666666;">&quot;&quot;</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> button<span style="color: #000080;color: #CCC;">:</span>String <span style="color: #000080;color: #CCC;">=</span> <span style="color: #6666FF;color: #666666;">&quot;&quot;</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> player<span style="color: #000080;color: #CCC;">:</span>String <span style="color: #000080;color: #CCC;">=</span> <span style="color: #6666FF;color: #666666;">&quot;&quot;</span>
  <span style="color: #0000ff; font-weight: bold;color: #B83A24;">var</span> amount<span style="color: #000080;color: #CCC;">:</span>String <span style="color: #000080;color: #CCC;">=</span> <span style="color: #6666FF;color: #666666;">&quot;&quot;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;color: #CDC;">// might want to add utg, cutoff later on..</span>
<span style="color: #F78811;color: #CCC;">&#125;</span></pre></div></div>

<p>You might think that from java you can do a simple:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">seat <span style="color: #339933;color: #CCC;">=</span> Seat.<span style="color: #000000; font-weight: bold;color: #B83A24;">new</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
seat.<span style="color: #006633;">number</span> <span style="color: #339933;color: #CCC;">=</span> <span style="color: #cc66cc;background-color: #000000; color: #DDD;">2</span><span style="color: #339933;color: #CCC;">;</span>
myContainer.<span style="color: #006633;">seats</span> <span style="color: #339933;color: #CCC;">+=</span> seat<span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>Well you can&#8217;t cause javap shows that there is NO access to number.</p>
<p>If you are accessing this class from java you&#8217;ll need to do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">seat <span style="color: #339933;color: #CCC;">=</span> Seat.<span style="color: #000000; font-weight: bold;color: #B83A24;">new</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
seat.<span style="color: #006633;">number_</span>\$eq<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #cc66cc;background-color: #000000; color: #DDD;">2</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
myContainer.<span style="color: #006633;">seats</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>.\$plus\$eq<span style="color: #009900;color: #CCC;">&#40;</span>seat<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p><i>The escapes are for antlr &#8212; in normal java it&#8217;d just be _$eq(var)</i></p>
<p>Really though, the only time when you are going to have to do this is if you<br />
have a java class that you need to be compiled through java &#8212; if you can convert<br />
it to scala go ahead and do so.</p>
<p>Depending on the size and scope of your project it might make sense to convert<br />
a bit to scala and do it piece-meal and then have other classes that access the scala<br />
class to change the way they use it.</p>
<p>Really in our project now the only thing that uses this is our antlr grammars which<br />
I&#8217;m going to be at sometime finally finishing the <a href="http://github.com/feydr/antlr-scala">scala antlr target</a>.</p>
<p>Anyways, if you have not tried out scala yet and you are a java dev &#8212; what are you<br />
waiting for!? It&#8217;s easier than you think &#8212; make sure you have some tests for a small<br />
class you&#8217;d like to convert then start doing it!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/03/21/the-mighty-awesome-power-of-scala/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hacking it Up with Lex, Yacc and Apache</title>
		<link>http://airodig.com/2010/03/05/hacking-it-up-with-lex-yacc-and-apache/</link>
		<comments>http://airodig.com/2010/03/05/hacking-it-up-with-lex-yacc-and-apache/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:00:25 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[lex]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[yacc]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=278</guid>
		<description><![CDATA[So&#8230;. I got drunk a week or so ago and decided I&#8217;d start my own programming language. this is not the first time I have done this &#8212; back 7-8 years ago when I was in school I did the exact same thing. I program in ruby and java most everyday and love the speed [...]]]></description>
			<content:encoded><![CDATA[<p>So&#8230;. I got drunk a week or so ago and decided I&#8217;d start my own programming language. this is not the first time I have done this &#8212; back 7-8 years ago when I was in school I did the exact same thing. I program in ruby and java most everyday and love the speed of java but hate it&#8217;s syntax. On the other hand I love ruby but hate its performance.</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/03/Coffee-Mug-Far-Side-Damned-if-You-Do-Dont.jpg"><img src="http://airodig.com/wp-content/uploads/2010/03/Coffee-Mug-Far-Side-Damned-if-You-Do-Dont-300x277.jpg" alt="damned if you do" title="Coffee Mug - Far Side Damned if You Do Dont" width="300" height="277" class="aligncenter size-medium wp-image-290" /></a></center></p>
<p>I&#8217;ve also been in the process of doing some serious benchmarking lately against webservers and other things while managing to piss people off when I start quoting scripture from the mountaintop regarding performance &#8212; which is the one thing I pay most attention to on whatever project I am working on. &#8220;Fast enough&#8221; is not faster or fastest.</p>
<p>This led me to examine what exactly I&#8217;m trying to do on various web projects and what I need to do to get it done. Primarily I want to serve up an application via the web to the world. To this end I want an environment that is either ridiculous fast at compiling/loading classes or I want an interpreter. Furthermore this environment should be able to serve up web pages. My first search started re-analyzing common types of web servers.</p>
<p><strong>Types of WebServers</strong></p>
<ul>
<li>CGI</li>
<li>FastCGI</li>
<li>Native Code</li>
<li>Your Own WebServer</li>
</ul>
<p>Let&#8217;s review them real quick:</p>
<p><b>CGI</b><br />
CGI is probably the first thing people <strong>used to</strong> turn to when they want to serve up a script written in some language but do NOT want to write the webserver themselves since the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html">grammar of HTTP</a> is not the prettiest thing (from what I&#8217;ve been told).</p>
<p>Your typical cgi script is EXTREMELY easy to do.<br />
Here&#8217;s an example:</p>
<p>First edit your /etc/apache/apache.conf like so:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ScriptAlias <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>www<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span></pre></div></div>

<p>Now just put this simple two line ruby script into<br />
that directory &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#008000; font-style:italic;color: #CDC;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">puts</span> <span style="color:#996600;color: #666666;">&quot;Content-type: text/html<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>&quot;</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">puts</span> <span style="color:#996600;color: #666666;">&quot;test&quot;</span></pre></div></div>

<p>&#8230; and change the permissions.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">chmod</span> <span style="color: #660033;">-R</span> <span style="color: #000000;background-color: #000000; color: #DDD;">755</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>www<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">chown</span> <span style="color: #660033;">-R</span> www-data:www-data <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>www<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>init.d<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>restart</pre></div></div>

<p>Now you can navigate to your url at http://127.0.0.1/cgi-bin/test.rb and see a webpage!</p>
<p>Of course, it&#8217;s not very fast &#8230;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">1</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>test.rb
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">150.45</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span>
&nbsp;
ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">10</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>test.rb
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">435.64</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span>
&nbsp;
ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>test.rb
=<span style="color: #000000; font-weight: bold;color: #CCC;">&gt;</span> Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">421.97</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span></pre></div></div>

<p>For this reason a lot of people do not use straight up CGI in production environments anymore.</p>
<p><b>FastCGI</b></p>
<p>FastCGI is &#8216;faster&#8217; than CGI since it loads the interpreter once and therefore does not have to keep loading it up everytime a page is requested. In reality it can be just as slow though if you have to load a ton of different components like notable ruby frameworks merb and rails. Other than this there really is not much difference between CGI and FastCGI &#8212; so it&#8217;s out of our game as well.</p>
<p><b>Native Code</b><br />
This is what we are going to be looking at. Native code can take your requested webfile &#8212; parse it and return the contents immediately &#8212; this is the fastest way outside of creating your own webserver and having to consult <a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html">Beej</a> (cause I&#8217;m assuming you are writing your language in something fast like C right??? Right!?? Typically when people choose this option they are looking at options like phusion passenger where they make their own nginx or apache module. This is retarded fast.</p>
<p><b>Your Own WebServer</b><br />
There are very good reasons for not rolling your own web server. There are quite a few edge cases in HTTP you need to support and various browsers have &#8216;weird&#8217; ways of handling things. This is not to even mention that you are going to leave out quite a few people who would rather use apache or nginx. However, ruby&#8217;s webrick would be an example of &#8216;rolling your own&#8217;.</p>
<p>So let&#8217;s take a second look at writing an apache module (cause let&#8217;s face it &#8212; nginx is cool but apache is adopted everywhere else).</p>
<p><b>Compiling your Module</b></p>
<p>You&#8217;ll want to grab modules/experimental/mod_example.c from an apache 2.2 directory. You obviously don&#8217;t need the majority of the crap in it. I&#8217;ve included the most important part here:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #808080; font-style: italic;color: #CDC;">/* This example just takes a pointer to the request record as its only 
* argument */</span>
<span style="color: #993333;color: #343832;">static</span> <span style="color: #993333;color: #343832;">int</span> webit_handler<span style="color: #009900;color: #CCC;">&#40;</span>request_rec <span style="color: #339933;color: #CCC;">*</span>r<span style="color: #009900;color: #CCC;">&#41;</span>
<span style="color: #009900;color: #CCC;">&#123;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* We decline to handle a request if hello-handler is not the value 
         * of r-&gt;handler */</span>
        <span style="color: #b1b100;color: #B83A24;">if</span> <span style="color: #009900;color: #CCC;">&#40;</span>strcmp<span style="color: #009900;color: #CCC;">&#40;</span>r<span style="color: #339933;color: #CCC;">-&gt;</span>handler<span style="color: #339933;color: #CCC;">,</span> <span style="color: #ff0000;color: #666666;">&quot;webit-handler&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
                <span style="color: #b1b100;color: #B83A24;">return</span> DECLINED<span style="color: #339933;color: #CCC;">;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* The following line just prints a message to the errorlog */</span>
        ap_log_error<span style="color: #009900;color: #CCC;">&#40;</span>APLOG_MARK<span style="color: #339933;color: #CCC;">,</span> APLOG_NOERRNO<span style="color: #339933;color: #CCC;">|</span>APLOG_NOTICE<span style="color: #339933;color: #CCC;">,</span> <span style="color: #0000dd;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">,</span> r<span style="color: #339933;color: #CCC;">-&gt;</span>server<span style="color: #339933;color: #CCC;">,</span>
        <span style="color: #ff0000;color: #666666;">&quot;mod_webit: %s&quot;</span><span style="color: #339933;color: #CCC;">,</span> <span style="color: #ff0000;color: #666666;">&quot;Loaded to kick ass!&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* We set the content type before doing anything else */</span>
        ap_set_content_type<span style="color: #009900;color: #CCC;">&#40;</span>r<span style="color: #339933;color: #CCC;">,</span> <span style="color: #ff0000;color: #666666;">&quot;text/html&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* If the request is for a header only, and not a request for 
         * the whole content, then return OK now. We don't have to do 
         * anything else. */</span>
        <span style="color: #b1b100;color: #B83A24;">if</span> <span style="color: #009900;color: #CCC;">&#40;</span>r<span style="color: #339933;color: #CCC;">-&gt;</span>header_only<span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
                <span style="color: #b1b100;color: #B83A24;">return</span> OK<span style="color: #339933;color: #CCC;">;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* Now we just print the contents of the document using the 
         * ap_rputs and ap_rprintf functions. More information about 
         * the use of these can be found in http_protocol.h */</span>
        ap_rputs<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #ff0000;color: #666666;">&quot;&lt;HTML&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;color: #CCC;">,</span> r<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
        ap_rputs<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #ff0000;color: #666666;">&quot;Hello world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;color: #CCC;">,</span> r<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
        ap_rprintf<span style="color: #009900;color: #CCC;">&#40;</span>r<span style="color: #339933;color: #CCC;">,</span> <span style="color: #ff0000;color: #666666;">&quot;%s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;color: #CCC;">,</span> parseThatShit<span style="color: #009900;color: #CCC;">&#40;</span>r<span style="color: #339933;color: #CCC;">-&gt;</span>filename<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
        ap_rputs<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #ff0000;color: #666666;">&quot;&lt;/HTML&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #339933;color: #CCC;">,</span>r<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
        <span style="color: #808080; font-style: italic;color: #CDC;">/* We can either return OK or DECLINED at this point. If we return 
        * OK, then no other modules will attempt to process this request */</span>
        <span style="color: #b1b100;color: #B83A24;">return</span> OK<span style="color: #339933;color: #CCC;">;</span>
<span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p>Your handler is what you want to focus in on. It receives a request and at that<br />
point you can do whatever the hell you want with it. I have chosen here to take<br />
whatever file the user gave to me and sent it off to parseThatShit which returns<br />
a charstar.</p>
<p>You can compile it with the following:<br />
(I have chosen c99 for better or for worse &#8212; I&#8217;ll leave your discriminatory comments up to<br />
the internet to judge.)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> apxs2 <span style="color: #660033;">-c</span> <span style="color: #660033;">-i</span> -Wc,-std=c99 <span style="color: #660033;">-a</span> mod_webit.c 
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>etc<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>init.d<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>restart</pre></div></div>

<p>Let&#8217;s setup apache to accept this wonderfulness:<br />
(make sure your module was installed in the same path as mine)</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">LoadModule webit_module <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache2<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>modules<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>mod_webit.so
&nbsp;
Listen <span style="color: #000000;background-color: #000000; color: #DDD;">82</span>
&nbsp;
<span style="color: #000000; font-weight: bold;color: #CCC;">&lt;</span>VirtualHost 127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">82</span><span style="color: #000000; font-weight: bold;color: #CCC;">&gt;</span>
    SetHandler webit-handler
    ServerName 127.0.0.1
    DocumentRoot <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>home<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>feydr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>random-hacking<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>webit<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>www<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>views
<span style="color: #000000; font-weight: bold;color: #CCC;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;color: #CCC;">&gt;</span></pre></div></div>

<p>Don&#8217;t forget that the log files are you friend &#8212; if nothing happens check the logs! It&#8217;s probably because you didn&#8217;t compile with debugging support and you haven&#8217;t spent enough time in gdb land. Let&#8217;s go segfaults! Duhm, duh duh duhm!</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>var<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>log<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache2<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>error.log
<span style="color: #000000; font-weight: bold;color: #CCC;">***</span> stack smashing detected <span style="color: #000000; font-weight: bold;color: #CCC;">***</span>: <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>sbin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache2 terminated
<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>Wed Mar 03 <span style="color: #000000;background-color: #000000; color: #DDD;">17</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">13</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">35</span> <span style="color: #000000;background-color: #000000; color: #DDD;">2010</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>notice<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> child pid <span style="color: #000000;background-color: #000000; color: #DDD;">318</span> <span style="color: #7a0874; font-weight: bold;color: #8FB394;">exit</span> signal Segmentation fault <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span><span style="color: #000000;background-color: #000000; color: #DDD;">11</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>Wed Mar 03 <span style="color: #000000;background-color: #000000; color: #DDD;">17</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">13</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">42</span> <span style="color: #000000;background-color: #000000; color: #DDD;">2010</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>notice<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> mod_webit: Loaded to kick ass<span style="color: #000000; font-weight: bold;color: #CCC;">!</span>
<span style="color: #000000; font-weight: bold;color: #CCC;">***</span> stack smashing detected <span style="color: #000000; font-weight: bold;color: #CCC;">***</span>: <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>sbin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>apache2 terminated
<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>Wed Mar 03 <span style="color: #000000;background-color: #000000; color: #DDD;">17</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">38</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">50</span> <span style="color: #000000;background-color: #000000; color: #DDD;">2010</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>notice<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> mod_webit: Loaded to kick ass<span style="color: #000000; font-weight: bold;color: #CCC;">!</span>
<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>Wed Mar 03 <span style="color: #000000;background-color: #000000; color: #DDD;">17</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">38</span>:<span style="color: #000000;background-color: #000000; color: #DDD;">50</span> <span style="color: #000000;background-color: #000000; color: #DDD;">2010</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span>notice<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#93;</span> mod_webit: Loaded to kick ass<span style="color: #000000; font-weight: bold;color: #CCC;">!</span></pre></div></div>

<p><strong>Lex and Yacc</strong><br />
Now to the meat of this article. </p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/03/yak-meat-012.jpg"><img src="http://airodig.com/wp-content/uploads/2010/03/yak-meat-012-300x200.jpg" alt="" title="yak-meat-012" width="300" height="200" class="aligncenter size-medium wp-image-301" /></a></center></p>
<p>Lex allows you to define all your tokens. Yacc will allow you to put your tokens into meaningful functions.</p>
<p>Here&#8217;s a simple lex file:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #339933;color: #CCC;">%</span><span style="color: #009900;color: #CCC;">&#123;</span>
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &quot;y.tab.h&quot;</span>
<span style="color: #339933;color: #CCC;">%</span><span style="color: #009900;color: #CCC;">&#125;</span>
<span style="color: #339933;color: #CCC;">%%</span>
&nbsp;
var                     <span style="color: #b1b100;color: #B83A24;">return</span> TOKVAR<span style="color: #339933;color: #CCC;">;</span>
puts                    <span style="color: #b1b100;color: #B83A24;">return</span> TOKPUTS<span style="color: #339933;color: #CCC;">;</span>
\<span style="color: #ff0000;color: #666666;">&quot;                      return QUOTES;
times                   return TIMES;
do                      return DO;
end                     return END;
'.'                     return PERIOD;
[-+()/*<span style="color: #000099; font-weight: bold;">\n</span>]              return *yytext;
[0-9]+                  yylval=atoi(yytext); return NUMBER;
[a-zA-Z]*               yylval=strdup(yytext); return WORD;
=                       return EQUALS;
[ <span style="color: #000099; font-weight: bold;">\t</span>]+                  /* ignore whitespace */;
%%</span></pre></div></div>

<p>Our yacc file is not so simple but it should be a bit more readable. Let&#8217;s take a look at some of it:</p>
<p>Our main:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">main<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #993333;color: #343832;">int</span> argc<span style="color: #339933;color: #CCC;">,</span> <span style="color: #993333;color: #343832;">char</span> <span style="color: #339933;color: #CCC;">*</span>argv<span style="color: #009900;color: #CCC;">&#91;</span><span style="color: #009900;color: #CCC;">&#93;</span><span style="color: #009900;color: #CCC;">&#41;</span>
<span style="color: #009900;color: #CCC;">&#123;</span>
  <span style="color: #b1b100;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span>argc <span style="color: #339933;color: #CCC;">&gt;</span> <span style="color: #0000dd;background-color: #000000; color: #DDD;">1</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
    parseFile<span style="color: #009900;color: #CCC;">&#40;</span>argv<span style="color: #009900;color: #CCC;">&#91;</span><span style="color: #0000dd;background-color: #000000; color: #DDD;">1</span><span style="color: #009900;color: #CCC;">&#93;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  <span style="color: #009900;color: #CCC;">&#125;</span> <span style="color: #b1b100;color: #B83A24;">else</span> <span style="color: #009900;color: #CCC;">&#123;</span>
    repl <span style="color: #339933;color: #CCC;">=</span> <span style="color: #0000dd;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span>
    <span style="color: #000066;color: #8FB394;">printf</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #ff0000;color: #666666;">&quot;Webit Version %s&quot;</span><span style="color: #339933;color: #CCC;">,</span> VERSION<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
    putPrompt<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
   <span style="color: #808080; font-style: italic;color: #CDC;">/* yyparse is what actually will start parsing your file */</span> 
   yyparse<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  <span style="color: #009900;color: #CCC;">&#125;</span>
<span style="color: #009900;color: #CCC;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;">/* ........ */</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;">/* here we see that we have various commands that we can do */</span>
commands<span style="color: #339933;color: #CCC;">:</span> <span style="color: #808080; font-style: italic;color: #CDC;">/* empty */</span>
        <span style="color: #339933;color: #CCC;">|</span> commands command
        <span style="color: #339933;color: #CCC;">;</span>
&nbsp;
command<span style="color: #339933;color: #CCC;">:</span>
        var_assign
        <span style="color: #339933;color: #CCC;">|</span>
        statement
        <span style="color: #339933;color: #CCC;">|</span>
        string_assign
        <span style="color: #339933;color: #CCC;">|</span>
        do_loop
        <span style="color: #339933;color: #CCC;">|</span>
        puts_var
        <span style="color: #339933;color: #CCC;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;">/* ..... */</span>
&nbsp;
<span style="color: #808080; font-style: italic;color: #CDC;">/* variable assignment */</span>
var_assign<span style="color: #339933;color: #CCC;">:</span>
        TOKVAR WORD EQUALS WORD <span style="color: #ff0000;color: #666666;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span>
        <span style="color: #009900;color: #CCC;">&#123;</span>
          <span style="color: #993333;color: #343832;">int</span> x <span style="color: #339933;color: #CCC;">=</span> firstEmpty<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
          <span style="color: #808080; font-style: italic;color: #CDC;">/* debug mode only
            printf(&quot;assigned %s to %s\n&quot;, $4, $3);
          */</span>
          <span style="color: #993333;color: #343832;">char</span> <span style="color: #339933;color: #CCC;">*</span>name <span style="color: #339933;color: #CCC;">=</span> strdup<span style="color: #009900;color: #CCC;">&#40;</span>$<span style="color: #0000dd;background-color: #000000; color: #DDD;">2</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
          <span style="color: #993333;color: #343832;">char</span> <span style="color: #339933;color: #CCC;">*</span>value <span style="color: #339933;color: #CCC;">=</span> strdup<span style="color: #009900;color: #CCC;">&#40;</span>$<span style="color: #0000dd;background-color: #000000; color: #DDD;">4</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
          putPrompt<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span>
        <span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>our Makefile</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">all<span style="color: #339933;color: #CCC;">:</span>
        lex webit.<span style="color: #202020;">l</span>
        yacc <span style="color: #339933;color: #CCC;">-</span>d webit.<span style="color: #202020;">y</span>
        cc lex.<span style="color: #202020;">yy</span>.<span style="color: #202020;">c</span> y.<span style="color: #202020;">tab</span>.<span style="color: #202020;">c</span> <span style="color: #339933;color: #CCC;">-</span>std<span style="color: #339933;color: #CCC;">=</span>c99 <span style="color: #339933;color: #CCC;">-</span>o blah
&nbsp;
clean<span style="color: #339933;color: #CCC;">:</span>
        rm <span style="color: #339933;color: #CCC;">-</span>rf y.<span style="color: #202020;">tab</span>.<span style="color: #202020;">h</span> blah lex.<span style="color: #202020;">yy</span>.<span style="color: #202020;">c</span> y.<span style="color: #202020;">tab</span>.<span style="color: #202020;">c</span></pre></div></div>

<p>Really making your own programming language the way you want to program and with performance is easy. Maybe you shouldn&#8217;t rush to use it on production servers but shit &#8212; it sure beats the hell out of putting up with crappy software in an age where programming is considered to be just including other people&#8217;s crappy software.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/03/05/hacking-it-up-with-lex-yacc-and-apache/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Quest for Greater Requests per Second</title>
		<link>http://airodig.com/2010/01/21/the-quest-for-greater-requestssecond/</link>
		<comments>http://airodig.com/2010/01/21/the-quest-for-greater-requestssecond/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 22:57:49 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[benchmarking]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=238</guid>
		<description><![CDATA[Was looking at an application the other day (that will rename nameless but any enterprising lad should be able to figure out what it is). It looked like we were clocking in at a whopping One point something requests/second. WHAT THE FUCK!? I immediately focused my attention with mytop trying to find slow queries. Found [...]]]></description>
			<content:encoded><![CDATA[<p>Was looking at an application the other day (that will rename nameless but any enterprising lad should be able to figure out what it is). It looked like we were clocking in at a whopping <em>One point something requests/second</em>. <strong>WHAT THE FUCK!?</strong></p>
<p>I immediately focused my attention with <a href="http://jeremy.zawodny.com/mysql/mytop/">mytop</a> trying to find slow queries. Found quite a few  and fixed them. I then started to cache out some of the problem areas and that is when I started to notice something very very unusual.</p>
<p>This particular application uses the <a href="http://www.merbivore.com/">merb framework</a> which is sadly fast becoming ghostware with no promise from the powers that be to continue to integrate it into the upcoming rails 3 which was due out a year ago. Apologies, that I don&#8217;t have time myself to dedicate to this framework &#8212; so I can&#8217;t be too harsh, after all it is free software.</p>
<p>You see, we use <a href="http://datamapper.org/">datamapper</a> as an ORM layer to our database and datamapper collections don&#8217;t fit well into memcached since they have procs that can&#8217;t be marshalled correctly &#8212; if I am wrong about this PLEASE LET ME KNOW.</p>
<p></p>
<h2>Caching</h2>
<p></p>
<p>So the typical way of caching your shit is to just call your finder from a helper in your view and cache the view. Simple enough I suppose &#8212; sounds like it should work. I then proceeeded to fragment cache everything I could.</p>
<p><img src="http://airodig.com/wp-content/uploads/2010/01/memcached.png" alt="memcached memory cache" /></p>
<p>When I was looking at items that would expire my cache (like a new blogpost upon a page that lists blog entries) I noticed that caching the entire page versus caching just a fragment or a partial of a page was noticeably faster. Now, we aren&#8217;t talking like &#8220;oh wow, that&#8217;s faster&#8221;&#8230; we are talking &#8220;HOLY FUCKING SHIT &#8212; that&#8217;s fucking faster than shit!&#8221;</p>
<p></p>
<h2>Templating Performance</h2>
<p></p>
<p>This drew me to the realization that makes the article&#8217;s purpose. <strong>Contrary to <a href="http://stackoverflow.com/questions/95821/should-i-use-haml-or-erb-or-erubis-for-potentially-high-traffic-site">popular</a> opinion &#8212; templating is a HUGE performance issue.</strong></p>
<p>By caching our sql we gained 5-10X speedups (1 r/s to 5-10 r/s). By caching the entire damn page we went to 20 requests/second &#8212; a 20X speedup! That&#8217;s double what our best sql/fragment caching could do.</p>
<p>I needed to confirm this because everyone has told me that sql is by far a worse performance killer than templating engines. Well, my benchmarks say otherwise.</p>
<p>Let&#8217;s look at some of those benchmarks real quick. These were extremely simple to do and I invite you to replicate them &#8212; it&#8217;ll take 2 minutes of your time to see for yourself.</p>
<p>I benched all the requests using <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">Apache Benchmark</a> and they look like this:<br />
<center><br />
<img src="http://airodig.com/wp-content/uploads/2010/01/apache_war_chief.gif" alt="Alchesay" /><br />
<em>Actually that is Alchesay, Apache was named cause back in the day when I had nothing to do but beat up on *nix boxen apache had more holes than the town whore.</em><br />
</center></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ ab <span style="color: #660033;">-c1</span> <span style="color: #660033;">-n100</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">4567</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>hi</pre></div></div>

<p>Everytime I used a haml template or put the equivalent HTML into the controller as a string it would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="haml" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">%h1
  Hello World
%ul
  %li
    Blah 1
  %li
    Blah 2
  %li
    Blah 3
  %li
    Blah 4</pre></div></div>

<p><strong>Note: I&#8217;m not trying to pick on haml &#8212; I really enjoy it &#8212; I just don&#8217;t want to be delluded that it&#8217;s all unicorns sprinting across rainbows shitting shooting stars when it comes to performance &#8212; because it is not &#8212; furthermore that kind of attitude in the community really aggravates me.</strong></p>
<p><center><br />
<img src="http://airodig.com/wp-content/uploads/2010/01/unicorn.jpg" alt="unicorn shitting under a rainbow" /><br />
</center></p>
<p><em>As a side note &#8212; anyone who uses the words like &#8216;tasty&#8217; to describe code needs to go back to their frontpage bullshit.</em></p>
<p><center></p>
<table style="background-color: #dedede;">
<tr>
<th>Framework</th>
<th>Conditions</th>
<th>Requests/Second</th>
</tr>
<tr>
<td colspan=3>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</td>
</tr>
<tr>
<td>sinatra</td>
<td>with &#8216;hello world!&#8217;</td>
<td> 838.19</td>
</tr>
<tr>
<td>sinatra</td>
<td>with haml</td>
<td> 610.57</td>
</tr>
<tr>
<td>merb</td>
<td>with &#8216;hello world!&#8217;</td>
<td> 341.63</td>
</tr>
<tr>
<td>merb</td>
<td>with haml</td>
<td> 271.13</td>
</tr>
<tr>
<td>sinatra</td>
<td>w/template in controller</td>
<td>1321.42</td>
</tr>
<tr>
<td>sinatra</td>
<td>w/template and haml</td>
<td> 320.77</td>
</tr>
<tr>
<td>merb</td>
<td>w/template in controller</td>
<td> 407.70</td>
</tr>
<tr>
<td>merb</td>
<td>w/template and haml</td>
<td> 227.39</td>
</tr>
</table>
<p></center></p>
<p>So what&#8217;s the conlusion to this testing? Tell markup languages to take a hike and only use css/html? Nope, we still use haml as I hate looking at html now because of it.<br />
What I ended up doing was caching everything I could up front and then combining multiple renders myself.</p>
<p></p>
<h2>Solution</h2>
<p></p>
<p>I basically decided to stub out portions of my views that I knew were not easily cacheable like the user layout found on hulu:<br />
<center><br />
<img src="http://airodig.com/wp-content/uploads/2010/01/headhulu.png" alt="hulu login area" /><br />
</center></p>
<p><strong>Some Code:</strong></p>
<p>You can see I stub out &#8220;{begin-login}&#8221; with whatever I&#8217;m going to replace it with later. This really is not necessary<br />
and I could prob. save a few cycles by not doing this but whatever.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">&nbsp;
    <span style="color:#008000; font-style:italic;color: #CDC;"># user specific non-cacheable</span>
    <span style="color:#008000; font-style:italic;color: #CDC;"># needs 2 renders</span>
    <span style="color:#9966CC; font-weight:bold;color: #B83A24;">if</span> session.<span style="color:#9900CC;">authenticated</span>? <span style="color:#9966CC; font-weight:bold;color: #B83A24;">then</span>
&nbsp;
      <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span> = MMCACHE.<span style="color:#9900CC;">clone</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">begin</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span> = <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;/welcome/homein&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">rescue</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@posts</span> = Blogpost.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:created_at</span>.<span style="color:#9900CC;">desc</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#006666;background-color: #000000; color: #DDD;">4</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
&nbsp;
        <span style="color:#008000; font-style:italic;color: #CDC;"># render our base layout without user-specific stuff</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span> = render <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#996600;color: #666666;">'cachein'</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;/welcome/homein&quot;</span>, <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span>, <span style="color:#006666;background-color: #000000; color: #DDD;">0</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
      <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">quit</span>
&nbsp;
      <span style="color:#008000; font-style:italic;color: #CDC;"># render user-specific stuff if logged in and tack it on</span>
      <span style="color:#0066ff; font-weight:bold;color: blue;">@loginshit</span> = render <span style="color:#ff3333; font-weight:bold;">:template</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#996600;color: #666666;">'layout/_logout'</span>, <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;color: #577A61;">false</span>
      <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span> = <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span>.<span style="color:#CC0066; font-weight:bold;color: #8FB394;">gsub</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;<span style="color:#000099;">\&quot;</span>{begin-login}<span style="color:#000099;">\&quot;</span>&quot;</span>, <span style="color:#0066ff; font-weight:bold;color: blue;">@loginshit</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
&nbsp;
    <span style="color:#008000; font-style:italic;color: #CDC;"># non-logged in user -- should only take 1 render</span>
    <span style="color:#008000; font-style:italic;color: #CDC;"># we have a special section for a logged in user that </span>
    <span style="color:#008000; font-style:italic;color: #CDC;"># shows their inbox and other things</span>
    <span style="color:#9966CC; font-weight:bold;color: #B83A24;">else</span>
&nbsp;
      <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span> = MMCACHE.<span style="color:#9900CC;">clone</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">begin</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span> = <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;/welcome/homeout&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">rescue</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@posts</span> = Blogpost.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:created_at</span>.<span style="color:#9900CC;">desc</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span>, <span style="color:#ff3333; font-weight:bold;">:limit</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#006666;background-color: #000000; color: #DDD;">4</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
&nbsp;
        <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span> = render <span style="color:#ff3333; font-weight:bold;">:layout</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#996600;color: #666666;">'cacheout'</span>
        <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;/welcome/homeout&quot;</span>, <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span>, <span style="color:#006666;background-color: #000000; color: #DDD;">0</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
      <span style="color:#0066ff; font-weight:bold;color: blue;">@cache</span>.<span style="color:#9900CC;">quit</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;color: #CDC;">#output final render</span>
    <span style="color:#0066ff; font-weight:bold;color: blue;">@welcomehome</span></pre></div></div>

<p>This could probably be cleaned up a bit more and be stuffed into a helper but you get the drift.</p>
<p>I did not include any fetch_partial (merb-cache helper methods) benchmarks here but to suffice to say I gained 20 requests/second by NOT using them &#8212; YMMV.</p>
<p>Today&#8217;s rant/diatribe brought to you by:</p>
<ul>
<li>Roxy Music &#8211; Take a Chance With Me </li>
<li>Kid Cudi &#8211; Pursuit of Happiness </li>
<li>Blue Scholars &#8211; 50K Deep </li>
</ul>
<p>So sorry, no crazy new utility to solve templating performance problems other than this hack but this does lay the foundation for more serious research in this category.</p>
<p><strong>Let me know how you solve your templating performance problems in the comments below.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/01/21/the-quest-for-greater-requestssecond/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tomcat and Merb with JRuby</title>
		<link>http://airodig.com/2009/12/18/tomcat-and-merb-with-jruby/</link>
		<comments>http://airodig.com/2009/12/18/tomcat-and-merb-with-jruby/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 22:31:09 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[merb]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=199</guid>
		<description><![CDATA[In case you didn&#8217;t know we parse poker hand histories on our website, Bluff.com. This parsing takes place in java. In the past we used to call out to our parser from ruby using something like this: ENV&#91;'LC_CTYPE'&#93; = 'en_US.UTF-8' IO.popen&#40;&#34;java -cp \&#34;#{classpath}\&#34; com.bluffware.BluffParse #{xtra}&#34; +handfile&#41; do &#124;f&#124; @xml = f.read end Of course once [...]]]></description>
			<content:encoded><![CDATA[<p>In case you didn&#8217;t know we parse poker hand histories on our website, <a href="http://bluff.com">Bluff.com</a>. This parsing takes place in java. In the past we used to call out to our parser from ruby using something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">  ENV<span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#996600;color: #666666;">'LC_CTYPE'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span> = <span style="color:#996600;color: #666666;">'en_US.UTF-8'</span>
  <span style="color:#CC00FF; font-weight:bold;color: #343832;">IO</span>.<span style="color:#9900CC;">popen</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;java -cp <span style="color:#000099;">\&quot;</span>#{classpath}<span style="color:#000099;">\&quot;</span> com.bluffware.BluffParse #{xtra}&quot;</span>
                <span style="color:#006600; font-weight:bold;color: #CCC;">+</span>handfile<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>f<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
    <span style="color:#0066ff; font-weight:bold;color: blue;">@xml</span> = f.<span style="color:#9900CC;">read</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span></pre></div></div>

<p>Of course once we started getting some users this quickly got retarded fast.<br />
So I went ahead and wrote my first servlet in tomcat to grab the hand history. Only problem is that I had no clue how the hell I was supposed to know who was accessing our webservice since <a href="http://tomcat.apache.org/">tomcat</a> lived on a different server from <a href="http://merbivore.com/">merb</a> and the cookies had a different domain. This turned out not to be a huge problem.</p>
<p><center><img src="http://airodig.com/wp-content/uploads/2009/12/cookiemonster_1.jpg" alt="cookie monster" /></center><br />
<br />
However, what was a huge problem was our cookie lived in a base64 encoded ruby object. How the hell was I supposed to get to it?</p>
<p><strong>JRUBY to the Rescue!</strong></p>
<p><a href="http://jruby.org">JRuby</a> has a sweet java<-->ruby bridge called <a href="http://kenai.com/projects/jruby/pages/RedBridge">RedBridge</a>. This allows us to execute ruby code in java which allows us to get to our beloved cookies.<br />
I wrote something like this to get our sessions going:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">    <span style="color: #666666; font-style: italic;color: #CDC;">// return merb session id from cookies</span>
    <span style="color: #000000; font-weight: bold;color: #B83A24;">public</span> <span style="color: #003399;color: #8FB394;">Integer</span> getSession<span style="color: #009900;color: #CCC;">&#40;</span>Cookie<span style="color: #009900;color: #CCC;">&#91;</span><span style="color: #009900;color: #CCC;">&#93;</span> cookies<span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
        <span style="color: #003399;color: #8FB394;">String</span> userid <span style="color: #339933;color: #CCC;">=</span> <span style="color: #0000ff;color: #666666;">&quot;0&quot;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span>cookies <span style="color: #339933;color: #CCC;">!=</span> <span style="color: #000066; font-weight: bold;color: #577A61;">null</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
          <span style="color: #000000; font-weight: bold;color: #B83A24;">for</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #000066; font-weight: bold;color: #343832;">int</span> i<span style="color: #339933;color: #CCC;">=</span><span style="color: #cc66cc;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span> i<span style="color: #339933;color: #CCC;">&lt;</span>cookies.<span style="color: #006633;">length</span><span style="color: #339933;color: #CCC;">;</span> i<span style="color: #339933;color: #CCC;">++</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
            Cookie cookie <span style="color: #339933;color: #CCC;">=</span> cookies<span style="color: #009900;color: #CCC;">&#91;</span>i<span style="color: #009900;color: #CCC;">&#93;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;color: #CDC;">// base64 decode, then un-marshall ruby style...</span>
            <span style="color: #666666; font-style: italic;color: #CDC;">// finally figure out what to do with our session secret key</span>
            <span style="color: #000000; font-weight: bold;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span>cookie.<span style="color: #006633;">getName</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;_session_id&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
              <span style="color: #000000; font-weight: bold;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #339933;color: #CCC;">!</span>cookie.<span style="color: #006633;">getValue</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
                ScriptingContainer container <span style="color: #339933;color: #CCC;">=</span> 
               <span style="color: #000000; font-weight: bold;color: #B83A24;">new</span> ScriptingContainer<span style="color: #009900;color: #CCC;">&#40;</span>LocalVariableBehavior.<span style="color: #006633;">PERSISTENT</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
                <span style="color: #666666; font-style: italic;color: #CDC;">//container.setWriter(out);</span>
                container.<span style="color: #006633;">runScriptlet</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;require 'base64'; &quot;</span> <span style="color: #339933;color: #CCC;">+</span>
                              <span style="color: #0000ff;color: #666666;">&quot;blah = Marshal.load(Base64.decode64(<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>
                              <span style="color: #339933;color: #CCC;">+</span> cookie.<span style="color: #006633;">getValue</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #339933;color: #CCC;">+</span> <span style="color: #0000ff;color: #666666;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>))[<span style="color: #000099; font-weight: bold;">\&quot;</span>user<span style="color: #000099; font-weight: bold;">\&quot;</span>];&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
                userid <span style="color: #339933;color: #CCC;">=</span> container.<span style="color: #006633;">get</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;blah&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
              <span style="color: #009900;color: #CCC;">&#125;</span>
            <span style="color: #009900;color: #CCC;">&#125;</span>
&nbsp;
          <span style="color: #009900;color: #CCC;">&#125;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;color: #B83A24;">return</span> <span style="color: #003399;color: #8FB394;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;color: #CCC;">&#40;</span>userid<span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
    <span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p>All was good in the land of poker analysis until one of my users messaged me one day saying some of my hands had ended up in his account. <strong>WTF!??!</strong> Then after accepting that he was not lying I indeed experienced seeing one of my own hands pop up as someone else&#8217;s.</p>
<p>I started putting trace statements all across the code trying to figure out what was going on where.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #003399;color: #8FB394;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;is it here?&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
<span style="color: #666666; font-style: italic;color: #CDC;">//.....</span>
<span style="color: #003399;color: #8FB394;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #0000ff;color: #666666;">&quot;it must be here...&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
<span style="color: #666666; font-style: italic;color: #CDC;">// etc...</span></pre></div></div>

<p>then watching it with one of my more favorite tools, tail.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>local<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>tomcat<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>logs<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>catalina.out</pre></div></div>

<p>after scanning it for a bit I could not find anything out of the ordinary; then I deployed<br />
some new servlet code without restarting tomcat</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">cp</span> <span style="color: #660033;">-R</span> myservlet<span style="color: #000000; font-weight: bold;color: #CCC;">/</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>local<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>tomcat<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>webapps<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>.</pre></div></div>

<p>and lo and behold, after posting a hand my cookie had changed! <strong><i>the key to figuring<br />
this and most problems like this out is to trigger the error</i></strong> and I had now found out<br />
by deploying the app without restarting I could do so.</p>
<p>it turned out that my cookie was changing somewhere INSIDE the ruby code.<br />
I popped onto the jruby website and noticed that my servlet was not<br />
<a href="http://kenai.com/projects/jruby/pages/RedBridge#ThreadSafe">thread safe</a>.<br />
I checked in with the friendly folks at #jruby on freenode and they confirmed that this was more than likely the problem since it was a local var in a multi-threaded app.</p>
<p>So I changed my offending line to this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ScriptingContainer container <span style="color: #339933;color: #CCC;">=</span> 
<span style="color: #000000; font-weight: bold;color: #B83A24;">new</span> ScriptingContainer<span style="color: #009900;color: #CCC;">&#40;</span>LocalContextScope.<span style="color: #006633;">THREADSAFE</span>, LocalVariableBehavior.<span style="color: #006633;">PERSISTENT</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>I started triggering the same event like mad and it works now! Yeh, JRuby! Yeh, for docs!</p>
<p><center><img src="http://airodig.com/wp-content/uploads/2009/12/HammerTime.jpg"></center></p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2009/12/18/tomcat-and-merb-with-jruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
