<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Rubynaut: Scaling a Rails app (Part 3 of 3)</title>
    <link>http://www.rubynaut.net/articles/2008/02/19/railsconf-scaling-a-rails-app-part-3-of-3</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Scaling a Rails app (Part 3 of 3)</title>
      <description>&lt;p&gt;This the third and last part for a summary about solutions to help better computing of your rails app&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://www.rubynaut.net/articles/2007/10/10/scaling-a-rails-app-part-1-of-3"&gt;1st part&lt;/a&gt;.&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://www.rubynaut.net/articles/2007/10/14/railsconf-scaling-a-rails-app-part-2-of-3"&gt;2nd part&lt;/a&gt;.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;Some home made benchmarks&lt;/h4&gt;


	&lt;p&gt;&lt;em&gt;NB: Following benchmarks have been made to a quick look study and not for a proof of concept.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;The test machine (dedibox, ubuntu 6.10) is 1 core cpu @2Ghz &amp;#8211; 1024 Mo memory. In each case the http server uses 10 processes on a real world application (not just &amp;#8216;hello world!&amp;#8217;). Sending 500 rq with 1 or 10 concurrency req:&lt;/p&gt;


	&lt;table style="border:1px solid black; ;"&gt;
		&lt;tr&gt;
			&lt;th&gt;conc. req. &lt;/th&gt;
			&lt;th&gt;1 &lt;/th&gt;
			&lt;th&gt;10 &lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; apache &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; mongrel &lt;/td&gt;
			&lt;td&gt; 39.4s &amp;#8211; 12.7 r/s &lt;/td&gt;
			&lt;td&gt; 21.9s &amp;#8211; 22.8 r/s &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; thin &lt;/td&gt;
			&lt;td&gt; 37.6s &amp;#8211; 13.3 r/s &lt;/td&gt;
			&lt;td&gt; 17.7s &amp;#8211; 28,15 r/s &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;

		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; nginx &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; mongrel &lt;/td&gt;
			&lt;td&gt; 39.2s &amp;#8211; 12.8 r/s &lt;/td&gt;
			&lt;td&gt; 22.2s &amp;#8211; 22.5 r/s &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; thin 0.5.4 &lt;/td&gt;
			&lt;td&gt; 39.8s &amp;#8211; 12.6 r/s &lt;/td&gt;
			&lt;td&gt; 17.7s &amp;#8211; 28.15 r/s &lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt; thin 0.6.1 socket x2 &lt;/td&gt;
			&lt;td&gt; 37.6s &amp;#8211; 13.3 r/s &lt;/td&gt;
			&lt;td&gt;  17.8s &amp;#8211; 28.1 r/s &lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;




	&lt;p&gt;&lt;br/&gt;&lt;/p&gt;


	&lt;p&gt;Since last time, Rails world has a new nice app server: thin. Replacement of mongrel, based on rack interface, it&amp;#8217;s also recently added a unix socket connector where usually we use IP connector. For better performance, avoid longest stuff as scripts (google analytics). Other scripts/images/css are keys in http performances also, usage of &lt;a href="http://weblog.rubyonrails.org/2007/9/30/rails-2-0-0-preview-release"&gt;assets&lt;/a&gt; in recommended.&lt;/p&gt;


	&lt;p&gt;As we can see in equivalent configuration there is no major difference for http server. Thin seems to be definitly faster than mongrel when you need to server more than 1 request at a time. And of course on a 1 core cpu, having more than one app server doesnt make the content served really faster.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Memory usage&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Mongrel (48 Mo) -&amp;gt; Thin (40 Mo) less 15%&lt;/p&gt;


	&lt;p&gt;Apache (10 Mo) -&amp;gt; Nginx (1.4 Mo) less 85%&lt;/p&gt;


	&lt;p&gt;Finally I decided to move to a nginx / thin on socket configuration because of the memory usage and the fair performances. I even moved my &lt;span class="caps"&gt;PHP&lt;/span&gt; stuff with an fcgi connector.&lt;/p&gt;


	&lt;p&gt;Other ideas of tests: Varnish, Nginx and memcached. Maybe next time :)&lt;/p&gt;


	&lt;p&gt;[update]&lt;/p&gt;


	&lt;p&gt;Please find a good benchmark about nginx vs apache on &lt;a href="http://www.joeandmotorboat.com/2008/02/28/apache-vs-nginx-web-server-performance-deathmatch/"&gt;Joe&amp;#8217;s blog&lt;/a&gt;&lt;/p&gt;


	&lt;h4&gt;Overall conclusion&lt;/h4&gt;


	&lt;p&gt;I think when we need to compare two framework, about which one is faster, we should keep in mind all these levels of optimisation to scale an application, and then the raw performance is a secondary issue.&lt;/p&gt;</description>
      <pubDate>Tue, 19 Feb 2008 18:05:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:f887137e-4a4d-474d-be4f-d7ed93f7dd42</guid>
      <author>stephane</author>
      <link>http://www.rubynaut.net/articles/2008/02/19/railsconf-scaling-a-rails-app-part-3-of-3</link>
    </item>
  </channel>
</rss>
