<?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; scaling</title>
	<atom:link href="http://blog.erichsen.net/tag/scaling/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; scaling</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>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>
