<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <author>Simon Schoeters</author>
    <content>&lt;p&gt;Ever wondered why none of the Ruby on Rails websites run on Apache?&lt;/p&gt;

&lt;p&gt;If you start with Perl, PHP or whatever programming language you are used to you never wonder about the web server, you run Apache, just like everyone else does. If you start playing with Ruby on Rails you get the WEBrick development server built in so that's what you start using, right? When my development work was finished I looked for a way to get a production server running with Apache but it seemed hard to find any documentation. What? No one is using Apache for &lt;abbr title="Ruby on Rails"&gt;RoR&lt;/abbr&gt; production environments?!&lt;/p&gt;

&lt;p&gt;Names like WEBrick, &lt;a href="http://www.lighttpd.net/" title="LightTPD a web server optimized for high RoR performance environments" class="ext"&gt;LightTPD&lt;/a&gt;, &lt;a href="http://mongrel.rubyforge.org/" title="Mongrel, a fast HTTP library and server for Ruby" class="ext"&gt;Mongrel&lt;/a&gt; and &lt;a href="http://nginx.net/" title="A HTTP server and mail proxy server" class="ext"&gt;nginx&lt;/a&gt; keep popping up in the search results but no, no one mentions Apache. So I choose to give Apache a try, stubborn as I am. Well, I finally understand why Apache is a dead end for RoR: it's way to slow (and yes, I had FastCGI enabled). It took Apache a few seconds to build and render a simple page, even with caching enabled, unacceptable.&lt;/p&gt;

&lt;h3&gt;LightTPD&lt;/h3&gt;

&lt;p&gt;Maybe it's time to start believing everyone else who isn't using Apache? Let's try LightTPD (pronounced as lighty) instead. For the record: I only compared LightTPD and Apache, there may be better solutions but as &lt;a href="http://joyent.com/" title="Joyent, a Ruby on Rails hosting provider" class="ext"&gt;Joyent&lt;/a&gt; (a rather large Rails hosting provider) uses LightTPD, it has a decent documentation tree and the newest release was brand new it seemed a good candidate.&lt;/p&gt;

&lt;p&gt;After installing LightTPD I ran a few performance tests (request the first page of my website) with Apache on one port and LightTPD on another port. The table shows the completion time in seconds on the server for each request:&lt;/p&gt;

&lt;table summary="Completion time in seconds for each request" class="post"&gt;
&lt;thead&gt;
&lt;tr&gt;
	&lt;th&gt;Apache&lt;/th&gt;
	&lt;th&gt;LightTPD&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
	&lt;td&gt;0.55353&lt;/td&gt;
	&lt;td&gt;0.172610&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.53983&lt;/td&gt;
	&lt;td&gt;0.312950&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.55328&lt;/td&gt;
	&lt;td&gt;0.174420&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.57171&lt;/td&gt;
	&lt;td&gt;0.173330&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.55858&lt;/td&gt;
	&lt;td&gt;0.210530&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.55082&lt;/td&gt;
	&lt;td&gt;0.173850&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.55589&lt;/td&gt;
	&lt;td&gt;0.309210&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.56931&lt;/td&gt;
	&lt;td&gt;0.178770&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;1.07452&lt;/td&gt;
	&lt;td&gt;0.173580&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.56005&lt;/td&gt;
	&lt;td&gt;0.180660&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.56576&lt;/td&gt;
	&lt;td&gt;0.265820&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.57710&lt;/td&gt;
	&lt;td&gt;0.326370&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.55825&lt;/td&gt;
	&lt;td&gt;0.253460&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
	&lt;td&gt;0.57263&lt;/td&gt;
	&lt;td&gt;0.315560&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;

&lt;tfoot&gt;
&lt;tr&gt;
	&lt;th&gt;0.597233&lt;/th&gt;
	&lt;th&gt;0.230080&lt;/th&gt;
&lt;/tr&gt;
&lt;/tfoot&gt;

&lt;/table&gt;

&lt;p&gt;Or in a graphical way:&lt;/p&gt;

&lt;p class="center"&gt;&lt;img src="/images/apache-lighttpd-deviations.png" alt="Apache &amp;amp; LightTPD performance deviation chart" longdesc="The line graph shows the results from the table above visualizing the deviations in the result data set." /&gt;&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;The test clearly shows the performance differences between Apache and LightTPD. It takes Apache 61.5% longer to render the same page showing that LightTPD is indeed a lot faster for my website. There may be even better solutions out there as I only evaluated LightTPD but I think I'll stick with lighty for now!&lt;/p&gt;

&lt;p class="center"&gt;&lt;img src="/images/apache-lighttpd-performance.png" alt="Apache vs LightTPD performance chart" longdesc="The bar chart shows the difference in performance for the Apache and LightTPD web servers. It takes Apache 61% longer to render the same page showing that LightTPD is indeed faster for my website." /&gt;&lt;/p&gt;</content>
    <created-at type="datetime">2007-10-01T19:04:33+02:00</created-at>
    <id type="integer">5</id>
    <location-id type="integer">1</location-id>
    <permalink>apache-vs-lighttpd</permalink>
    <title>Apache versus LightTPD</title>
    <updated-at type="datetime">2008-05-20T10:08:17+02:00</updated-at>
  </post>
  <post>
    <author>Simon Schoeters</author>
    <content>&lt;p&gt;After upgrading Ruby to 1.8.6 and Rails to 2.0.2 I ran intro problems with my installed gems. My application couldn't find any of the installed gems anymore! The &lt;samp&gt;gem list&lt;/samp&gt; command returned the installed gems like you would expect and even the &lt;samp&gt;./script/console&lt;/samp&gt; environment in my Rails application found the gems I needed but requiring a gem in one of my controllers like:&lt;/p&gt;

&lt;p&gt;&lt;samp&gt;require 'somegem'&lt;/samp&gt;&lt;/p&gt;

&lt;p&gt;returned the following error:&lt;/p&gt;

&lt;p&gt;&lt;samp&gt;MissingSourceFile (no such file to load -- somegem)&lt;/samp&gt;&lt;/p&gt;

&lt;p&gt;It took ages to find out what the problem was. My &lt;a href="http://www.rubygems.org/read/chapter/3#page83" title="Installing RubyGems in a User Directory" class="ext"&gt;GEM_PATH&lt;/a&gt; variable - this is where RubyGems looks for the installed gems - was set. I could find the gem from everywhere, except from within the controllers in my application. However, it did work fine when I ran the WEBrick server but when using my LightTPD production server everything went fubar.&lt;/p&gt;

&lt;p&gt;Turned out I forgot to tell LightTPD to use the new GEM_PATH, other than the default one. You can do this in the LightTPD configuration file. Maybe I changed the gem installation directory as I build RubyGems from source without knowing? Add the following to your LightTPD configuration file (change the paths where needed) and reload the server.&lt;/p&gt;

&lt;p&gt;&lt;samp&gt;fastcgi.server =&lt;br /&gt;
(&lt;br /&gt;
&amp;nbsp;".fcgi" =&amp;gt;&lt;br /&gt;
&amp;nbsp;(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;"localhost" =&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;"min-procs" =&amp;gt; 1,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;"max-procs" =&amp;gt; 1,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;"socket" =&amp;gt; "&amp;lt;app&amp;gt;/tmp/sockets/fcgi.socket",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;"bin-path" =&amp;gt; "&amp;lt;app&amp;gt;/public/dispatch.fcgi",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;"bin-environment" =&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"RAILS_ENV" =&gt; "production",&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;"GEM_PATH" =&gt; "/usr/local/lib/ruby/gems/1.8/"&lt;/strong&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;)&lt;br /&gt;
&amp;nbsp;)&lt;br /&gt;
)&lt;/samp&gt;&lt;/p&gt;

&lt;p&gt;That's it, Suffix is now happily running the latest Ruby on Rails version.&lt;/p&gt;</content>
    <created-at type="datetime">2008-02-29T10:07:22+01:00</created-at>
    <id type="integer">20</id>
    <location-id type="integer">3</location-id>
    <permalink>missing-gems-in-lighttpd</permalink>
    <title>Missing gems in LightTPD</title>
    <updated-at type="datetime">2008-03-03T00:11:49+01:00</updated-at>
  </post>
</posts>
