<?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 2 of 3)</title>
    <link>http://www.rubynaut.net/articles/2007/10/14/railsconf-scaling-a-rails-app-part-2-of-3</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Scaling a Rails app (Part 2 of 3)</title>
      <description>&lt;p&gt;This the second part for a summary about solutions to help better computing of your rails app (&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;/p&gt;


	&lt;h4&gt;Application&lt;/h4&gt;


	&lt;p&gt;To help your application to focus on replying fast to user, you can use a &lt;strong&gt;distributed queueing&lt;/strong&gt; to give the job to other processes:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://daemons.rubyforge.org/"&gt;Daemons&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://backgroundrb.rubyforge.org/"&gt;Backgroundrb&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;And second thing, you can &lt;strong&gt;cache&lt;/strong&gt; things you don&amp;#8217;t need to compute for each request, this can incredibly increase the response of your server, but need to modify your code and it s recommend for very big sites:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://seattlerb.org/memcache-client"&gt;Memcache client&lt;/a&gt;, &lt;a href="http://www.danga.com/memcached/"&gt;memcached server&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://errtheblog.com/post/27"&gt;acts_as_cached&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;Back end&lt;/h4&gt;


	&lt;h5&gt;DB&lt;/h5&gt;


	&lt;p&gt;For your database you can find some &lt;strong&gt;sql proxy&lt;/strong&gt;, but I haven&amp;#8217;t tried it yet. You have also the way to &lt;strong&gt;replicate&lt;/strong&gt; your databse and serve data from several servers.&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;&lt;a href="http://sqlrelay.sourceforge.net/"&gt;sql relay&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;use jruby with a jdbc pool connection and caching&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Important things you have to check about your databse is if you have the right indexed fields. You should find some tools on mysql helping you to find where &lt;strong&gt;indexes&lt;/strong&gt; missing. Check about &lt;strong&gt;cache&lt;/strong&gt; too.&lt;/p&gt;


	&lt;p&gt;A last way is to &lt;strong&gt;serialize&lt;/strong&gt; some of your data in a single object.&lt;/p&gt;


	&lt;h5&gt;Mysql&lt;/h5&gt;


	&lt;p&gt;Otherwise you can configure your mysql with some optimized &lt;strong&gt;configuration&lt;/strong&gt; (mysql.ini):&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;skip-name-resolve&lt;/li&gt;
		&lt;li&gt;query_cache_size = 52428800;&lt;/li&gt;
		&lt;li&gt;query_cache_type = 1&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;And in your ActiveRecord object you can use the &lt;strong cite="include"&gt;* parameter.&lt;/p&gt;


	&lt;h5&gt;Filesystem&lt;/h5&gt;


	&lt;p&gt;Optimizing the filesystem, in other sense than choose a good OS, can been done with not overloading the management of files by using some *rules&lt;/strong&gt;:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;max 10K files / subdir&lt;/li&gt;
		&lt;li&gt;16 top level / 256 sub / 10K per sub dir&lt;/li&gt;
		&lt;li&gt;use a hasher to manage files&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;OS&lt;/h4&gt;


	&lt;p&gt;As we have seen, file and memory management are keys of good performances. And these are managed by OS. The two best OSs mentionned are&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Sunsolaris&lt;/li&gt;
		&lt;li&gt;FreeBSD (can be use for a all in one stack), avoid the version 5&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;em&gt;And upcoming, last part of this article, some home made benchmarks for my own purpose.&lt;/em&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 14 Oct 2007 14:18:00 +0200</pubDate>
      <guid isPermaLink="false">urn:uuid:20434bd3-6305-49bc-b677-1b5e76d84a77</guid>
      <author>stephane</author>
      <link>http://www.rubynaut.net/articles/2007/10/14/railsconf-scaling-a-rails-app-part-2-of-3</link>
    </item>
  </channel>
</rss>
