<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <author>Simon Schoeters</author>
    <content>&lt;p&gt;It took me a while to figure out the differences between the AddHandler and AddType directives in an Apache configuration. Both directives seem to define how the contents of a file with a given extension should be threatened but when do you need the first one and when the second?&lt;/p&gt;

&lt;p&gt;Turned out it isn't too hard... the AddType handler specifies how the &lt;strong&gt;client&lt;/strong&gt; (think about a browser) has to deal with a particular data stream (e.g. download a binary or show an image or HTML page). The AddHandler on the other hand maps a handler to the file extension telling the &lt;strong&gt;server&lt;/strong&gt; what to do with it. So if you are defining a Ruby on Rails or PHP content type you will need the AddHandler, telling the server it should parse the file. If you define a JavaScript or HTML file you will need the AddType one to tell the browser what content type to expect.&lt;/p&gt;

&lt;h3&gt;Strict versus quirks mode&lt;/h3&gt;

&lt;p&gt;Something slightly related is how browsers actually deal with the content type you set in your AddType directive. Gecko based browsers (like Firefox) follow the standard closely so they will handle a file according to the content type in your Apache configuration. This means your image will show up as text if you wrongly assigned the text/plain content type. Internet Explorer is more flexible and tries to guess the mime type for misconfigured web servers showing a wrongly defined images as, well, an image.&lt;/p&gt;

&lt;h3&gt;More resources&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://httpd.apache.org/docs/2.0/mod/mod_mime.html" title="Apache Module mod_mime documentation" class="ext"&gt;Apache's Module mod_mime documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Properly_Configuring_Server_MIME_Types" title="Properly Configuring Server MIME Types at the Mozilla Developer Center" class="ext"&gt;Properly Configuring Server MIME Types&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://developer.mozilla.org/en/docs/Properly_Configuring_Server_MIME_Types" title="A sample .htaccess file at the Mozilla Developer Center" class="ext"&gt;A sample .htaccess file with common MIME types&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content>
    <created-at type="datetime">2007-09-05T15:10:08+02:00</created-at>
    <id type="integer">2</id>
    <location-id type="integer">3</location-id>
    <permalink>addhandler-addtype-directives</permalink>
    <title>Apache AddHandler or AddType directive?</title>
    <updated-at type="datetime">2007-10-07T01:59:19+02:00</updated-at>
  </post>
  <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>
</posts>
