<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Enjoying Rails &#187; rails</title>
	<atom:link href="http://blog.erichsen.net/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.erichsen.net</link>
	<description>I really do...</description>
	<lastBuildDate>Sun, 08 May 2011 07:35:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.erichsen.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Enjoying Rails &#187; rails</title>
		<link>http://blog.erichsen.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.erichsen.net/osd.xml" title="Enjoying Rails" />
	<atom:link rel='hub' href='http://blog.erichsen.net/?pushpress=hub'/>
		<item>
		<title>Automatic Rails on Ubuntu 8.04 LTS</title>
		<link>http://blog.erichsen.net/2008/10/16/automatic-rails-on-ubuntu-804-lts/</link>
		<comments>http://blog.erichsen.net/2008/10/16/automatic-rails-on-ubuntu-804-lts/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 20:32:11 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://enjoyingrails.wordpress.com/?p=17</guid>
		<description><![CDATA[A couple of weeks ago there was a post on the FiveRuns blog about automatically installing the Rails stack on an Ubuntu 8.04 VPS. I prefer to use Passenger and Ruby Enterprise Edition when running my Rails app, so inspired by the FiveRuns script I wrote my own version &#8211; here is the gist on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=17&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago there was a <a href="http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost">post</a> on the FiveRuns blog about automatically installing the Rails stack on an Ubuntu 8.04 VPS.</p>
<p>I prefer to use Passenger and Ruby Enterprise Edition when running my Rails app, so inspired by the FiveRuns script I wrote my own version &#8211; here is the <a href="http://gist.github.com/16225">gist on github</a>.</p>
<p><code><br />
#!/bin/bash<br />
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost</p>
<p>apt-get update<br />
apt-get upgrade -y<br />
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev<br />
apt-get -y install mysql-server libmysqlclient15-dev mysql-client<br />
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8 </p>
<p>RUBYGEMS="rubygems-1.3.0"<br />
wget http://rubyforge.org/frs/download.php/43985/$RUBYGEMS.tgz<br />
tar xzf $RUBYGEMS.tgz<br />
cd $RUBYGEMS<br />
ruby setup.rb<br />
cd ..</p>
<p># Install Ruby Enterprise Edition<br />
wget http://rubyforge.org/frs/download.php/41040/ruby-enterprise-1.8.6-20080810.tar.gz<br />
tar xvzf ruby-enterprise-1.8.6-20080810.tar.gz<br />
yes '' | ./ruby-enterprise-1.8.6-20080810/installer</p>
<p># Install Passenger<br />
/usr/bin/gem1.8 install -v=2.0.3 passenger --no-rdoc --no-ri<br />
apt-get -y install apache2-mpm-prefork apache2-prefork-dev<br />
yes '' | passenger-install-apache2-module </p>
<p># Create sample Rails app<br />
/usr/bin/gem1.8 install rails --no-rdoc --no-ri<br />
cd /var/www<br />
rails -d mysql hello<br />
cd hello<br />
./script/generate controller welcome hello<br />
echo "Hello World" &gt; app/views/welcome/hello.html.erb<br />
rake db:create RAILS_ENV=production</p>
<p># Create the Apache2 Passenger module files<br />
cat &gt;&gt; /etc/apache2/mods-available/passenger.load &lt;&gt; /etc/apache2/mods-available/passenger.conf &lt;&lt;-EOF</p>
<p>  PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3<br />
  PassengerRuby /opt/ruby-enterprise-1.8.6-20080810/bin/ruby</p>
<p>EOF<br />
a2enmod passenger</p>
<p># Create a site file for the sample Rails app<br />
IP_ADDRESS=`ifconfig eth0 | sed -n 's/.*dr:\(.*\)  Bc.*/\1/p'`<br />
cat &gt;&gt; /etc/apache2/sites-available/hello &lt;&lt;-EOF</p>
<p>      ServerName www.yourhost.com<br />
      DocumentRoot /var/www/hello/public</p>
<p>EOF<br />
a2ensite hello</p>
<p># That's it!<br />
reboot<br />
</code></p>
<p>The script assumes that you have ssh access as root to a clean Ubuntu 8.04 install.</p>
<p>The script will install</p>
<ul>
<li>Ruby 1.8.6</li>
<li>RubyGems 1.3.0</li>
<li>Passenger 2.0.3</li>
<li>Ruby Enterprise Edition 20080810</li>
<li>Apache 2.2.8</li>
<li>MySQL 5.0.51a</li>
<li>A sample Rails app</li>
</ul>
<p>Note that the Passenger installer will install the latest Rails (2.1.1) and a bunch of other useful gems.</p>
<p>Assuming that your server IP address is 192.168.185.128 you can run it like this:<br />
<code><br />
ssh root@192.168.185.128 "wget -O - http://gist.github.com/raw/16225/a6a16b3a38cd3486679b96fa0f3446e58f3b8423 | sed -e s/$'\r'//g &gt; install.sh; /bin/bash install.sh; rm install.sh"<br />
</code><br />
Sit back and enjoy &#8211; in less than ten minutes you will have the full Rails stack and a sample Rails app running. Take a look at it on <a href="http://192.168.185.128/welcome/hello">http://192.168.185.128/welcome/hello</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=17&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2008/10/16/automatic-rails-on-ubuntu-804-lts/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
		<item>
		<title>My first Rails Contribution</title>
		<link>http://blog.erichsen.net/2007/12/28/my-first-rails-contribution/</link>
		<comments>http://blog.erichsen.net/2007/12/28/my-first-rails-contribution/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 19:00:30 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.erichsen.net/2007/12/28/my-first-rails-contribution/</guid>
		<description><![CDATA[Yeah! I am a Rails contributor! In an application at work we are using a Rails REST application for the backend of the application and another Rails application as the frontend. The frontend application does not use the database at all but only the REST api provided by the backend application. When sending lots of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=13&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yeah! I am a Rails contributor!</p>
<p>In an application at work we are using a Rails REST application for the backend of the application and another Rails application as the frontend. The frontend application does not use the database at all but only the REST api provided by the backend application.</p>
<p>When sending lots of data between the two applications serializing to and from XML turned out to be a performance bottleneck. We turned to JSON and this improved performance significantly.</p>
<p>The JSON support in ActiveResource was added recently and there are still some areas where XML is better supported than JSON. So I submitted a <a href="http://dev.rubyonrails.org/ticket/10635" title="patch">patch</a> to improve the JSON support. The patch got submitted to trunk in this <a href="http://dev.rubyonrails.org/changeset/8502" title="changeset">changeset.</a></p>
<p>It feels really good to contribute back to Rails when Rails have brought me so many hours of joy <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/enjoyingrails.wordpress.com/13/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/enjoyingrails.wordpress.com/13/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/13/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/13/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/13/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=13&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2007/12/28/my-first-rails-contribution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
		<item>
		<title>My favourite Rails stack</title>
		<link>http://blog.erichsen.net/2007/10/31/my-favourite-rails-stack/</link>
		<comments>http://blog.erichsen.net/2007/10/31/my-favourite-rails-stack/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 14:05:55 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Mongrel]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.erichsen.net/2007/10/31/my-favourite-rails-stack/</guid>
		<description><![CDATA[Operating System Boy, things have come a long way since I first installed SLS Linux on my pc using floppy discs back in 1994 These days I prefer Ubuntu 6.06 LTS server edition. It is supported until 2011 &#8211; nice that you don&#8217;t have to reinstall the server in a year or two. Furthermore, deprec [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=9&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>Operating System</h3>
<p>Boy, things have come a long way since I first installed SLS Linux on my pc using floppy discs back in 1994 <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
These days I prefer <a href="http://www.ubuntu.com/">Ubuntu 6.06 LTS server edition</a>. It is supported until 2011 &#8211; nice that you don&#8217;t have to reinstall the server in a year or two. Furthermore, <a href="http://www.deprec.org/">deprec</a> makes it extremely simple to setup a Rails stack on an Ubuntu server.</p>
<h3>Webserver</h3>
<p><a href="http://nginx.net/">nginx</a>. Nginx is fast, stable, lightweight and has easy configuration.</p>
<h3>Load balancer</h3>
<p>Usuyally I use the one built in to nginx.<br />
Alternatives: <a href="http://siag.nu/pen/">Pen</a> or <a href="http://haproxy.1wt.eu">HAProxy</a>.</p>
<h3>Rails-server</h3>
<p>Well, <a href="http://siag.nu/pen/">Mongrel</a> of course. In a cluster handled by <a href="http://mongrel.rubyforge.org/docs/mongrel_cluster.html">Mongrel cluster</a>.</p>
<h3>Database</h3>
<p>MySQL. It&#8217;s the database used by most Rails applications. Furthermore, it has some nice scaling support with master-slave setups. A couple of years ago I used and liked PostgreSQL a lot. I still prefer PostgreSQL&#8217;s query analyzer to MySQL&#8217;s.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/enjoyingrails.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/enjoyingrails.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=9&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2007/10/31/my-favourite-rails-stack/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
		<item>
		<title>tv2.dk on Rails on Amazon EC2</title>
		<link>http://blog.erichsen.net/2007/10/24/tv2dk-on-rails-on-amazon-ec2/</link>
		<comments>http://blog.erichsen.net/2007/10/24/tv2dk-on-rails-on-amazon-ec2/#comments</comments>
		<pubDate>Wed, 24 Oct 2007 18:53:06 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[Amazon EC2]]></category>

		<guid isPermaLink="false">http://blog.erichsen.net/2007/10/24/tv2dk-on-rails-on-amazon-ec2/</guid>
		<description><![CDATA[What if tv2.dk (one of the most popular Danish sites) was running Rails and ran on Amazon EC2? This posting is a followup to this posting Let&#8217;s assume that we on average during 24 hours have 50 requests/sec. The traffic during the 24 hours could for example be distributed like this Hours Traffic 00 &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=5&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>	What if tv2.dk (one of the most popular Danish sites) was running Rails and ran on Amazon EC2? This posting is a followup to <a href="http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/">this posting</a></p>
<p>Let&#8217;s assume that we on average during 24 hours have 50 requests/sec. The traffic during the 24 hours could for example be distributed like this</p>
<table border="0" cellspacing="4">
<tr>
<th>Hours</th>
<th>Traffic</th>
</tr>
<tr>
<td>00 &#8211; 08</td>
<td>5 requests/sec</td>
</tr>
<tr>
<td>08 &#8211; 11</td>
<td>30 requests/sec</td>
</tr>
<tr>
<td>11 &#8211; 12</td>
<td>150 requests/sec</td>
</tr>
<tr>
<td>12 &#8211; 14</td>
<td>250 requests/sec</td>
</tr>
<tr>
<td>14 &#8211; 15</td>
<td>150 requests/sec</td>
</tr>
<tr>
<td>15 &#8211; 24</td>
<td>30 requests/sec</td>
</tr>
</table>
<p>This works out to be 50 requests/sec on average. As we saw in the <a href="http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/">tv2.dk on Rails</a> blog posting each quad core server will get you 80 requests/sec. Unfortunately we have to have servers that have enough power to satisfy the <em>peak number</em> of requests and not the <em>average number</em> of requests. In this example we need four quad core servers in order to be able to serve the 250 requests/sec needed from 12-14 (actually they are able to serve 320 requests/sec). So on average we need one server but in the peak hours we need four servers.</p>
<p>What if we were able to adjust the number of servers dynamically to satisfy the current load on the website?</p>
<p>Amazon EC2 to the rescue! <a href="http://www.amazon.com/gp/browse.html?node=201590011">Amazon EC2</a> is a service that allows you to run one or many virtual servers and you pay by the hour for each virtual server. So we can start and stop a number of virtual machines depending on the load on the website. Each EC2 instance has one (virtual) cpu core so with 10 mongrels doing 2 requests/sec it should be able to handle 20 requests/sec.<br />
So how many servers do we need to run?</p>
<table border="0" cellspacing="4">
<tr>
<th>Hours</th>
<th>Traffic</th>
<th># of servers</th>
</tr>
<tr>
<td>00 &#8211; 08</td>
<td>5 requests/sec</td>
<td>1</td>
</tr>
<tr>
<td>08 &#8211; 11</td>
<td>30 requests/sec</td>
<td>2</td>
</tr>
<tr>
<td>11 &#8211; 12</td>
<td>150 requests/sec</td>
<td>8</td>
</tr>
<tr>
<td>12 &#8211; 14</td>
<td>250 requests/sec</td>
<td>13</td>
</tr>
<tr>
<td>14 &#8211; 15</td>
<td>150 requests/sec</td>
<td>8</td>
</tr>
<tr>
<td>15 &#8211; 24</td>
<td>30 requests/sec</td>
<td>2</td>
</tr>
</table>
<p>If we calculate the number of &#8220;server hours&#8221; it is 74. How much is this going to cost? Using the <a href="http://calculator.s3.amazonaws.com/calc5.html">AWS Simple Monthly Calculator</a> it turns out to cost 222$ for a 30 day month. Not too bad! Of course we have to add a server for static content (or use Amazon S3) as well as a couple of DB servers. With a small instance server for static content and two large instances (virtual quad cores with 7.5 GB ram) the monthly bill goes up to 811$ &#8211; still not too bad.</p>
<p>But you also have to pay for traffic. I will cover that in another blog posting.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/enjoyingrails.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/enjoyingrails.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=5&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2007/10/24/tv2dk-on-rails-on-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
		<item>
		<title>tv2.dk on Rails</title>
		<link>http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/</link>
		<comments>http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/#comments</comments>
		<pubDate>Mon, 22 Oct 2007 20:02:01 +0000</pubDate>
		<dc:creator>enjoyingrails</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[Amazon EC2]]></category>

		<guid isPermaLink="false">http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/</guid>
		<description><![CDATA[Recently I started wondering: What kind of server setup would it take to run one of the most popular sites in Denmark if it was running Rails? According to FDIM (the association of Danish Internet media) tv2.dk was the thirdmost visited site in Denmark during August 2007: Number of users 1.435.208 Number of visits 15.233.358 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=4&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>	Recently I started wondering: What kind of server setup would it take to run one of the most popular sites in Denmark if it was running Rails?</p>
<p>According to <a href="http://www.fdim.dk/toplist/get_list.asp?show_default=true">FDIM</a> (the association of Danish Internet media) tv2.dk was the thirdmost visited site in Denmark during August 2007:</p>
<table border="0" cellspacing="4">
<tr>
<td>Number of users</td>
<td align="right">1.435.208</td>
</tr>
<tr>
<td>Number of visits</td>
<td align="right">15.233.358</td>
</tr>
<tr>
<td>Number of page views</td>
<td align="right">142.132.680</td>
</tr>
</table>
<p>142 million page views! That&#8217;s a lot! But how much data is this?</p>
<p>According to <a href="http://www.alexa.com/data/details/traffic_details?url=tv2.dk">Alexa</a> the three most popular subdomains of tv2.dk are galleri.tv2.dk, nyhederne.tv2.dk, and vip.tv2.dk.<br />
Using <a href="http://developer.yahoo.com/yslow/">YSlow</a> we get a picture of the total page size and the number of http requests for the main page of each subdomain:</p>
<table border="0" cellspacing="4">
<tr>
<td>galleri.tv2.dk</td>
<td>Total size 140.1K</td>
<td>HTTP requests 19</td>
</tr>
<tr>
<td>nyhederne.tv2.dk</td>
<td>Total size 580.2K</td>
<td>HTTP requests 85</td>
</tr>
<tr>
<td>vip.tv2.dk</td>
<td>Total size 464.4K</td>
<td>HTTP requests 58</td>
</tr>
</table>
<p>The average page size is 395K and the average number of requests per page is 54.</p>
<p>The number of page views for August is 142.132.680. This translates to an average of 53 page views/sec. Given the average page size and number of requests this translates to an average bandwith usage of 20.5 MB/sec and an average of 2866 request/sec.</p>
<p>What kind of server setup do you need to handle this amount of traffic?</p>
<p>First of all, by far most traffic comes from static content (images, javascript files, stylesheets). Any decent web server (Apache, nginx and in tv2.dk&#8217;s case lighttpd) &#8211; this <a href="http://www.litespeedtech.com/web-server-performance-comparison-litespeed-2.1-vs.html">page</a> shows that without too much hassle it is possible to achieve 10000+ requests/sec on a decent server with enough network bandwidth.</p>
<p>But what about the Rails part? If we assume that each page view corresponds to one Rails request we have to handle 53 Rails requests/sec. If we assume that the average request time is 500 ms, each Mongrel can handle 2 requests/sec. So we have to have 27 Mongrels to be able to handle 53 queries/sec. As noted in the excellent article <a href="http://www.caboo.se/articles/2007/7/29/scale-rails-from-one-box-to-three-four-and-five">Scale rails from one box to three, four and five</a> by Courtenay a rule of thumb is that each cpu core can handle 10 Mongrels. So with a quad core machine we should be able to handle 2*10*4 = 80 Rails requests/sec. Each Mongrel uses in the range of 60-100 MB, so the machine has to have 4*10*80 = 3200 MB ram. Rails applications can be built to scale quite well, so adding additional quad core machines with 4 gigs of ram should get you another 80 requests/sec. With 4 of these machines you should be able to handle 320 requests/sec.</p>
<p>There must some database servers to handle all the data. There a several ways to setup these servers. Take a look at Courtenay&#8217;s article for an explanation of these.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/enjoyingrails.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/enjoyingrails.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/enjoyingrails.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/enjoyingrails.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/enjoyingrails.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.erichsen.net&amp;blog=1936559&amp;post=4&amp;subd=enjoyingrails&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.erichsen.net/2007/10/22/tv2dk-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2047f0076ea63c7d1a35373bac6f9841?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">enjoyingrails</media:title>
		</media:content>
	</item>
	</channel>
</rss>
