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 |
| Number of page views | 142.132.680 |
142 million page views! That’s a lot! But how much data is this?
According to Alexa the three most popular subdomains of tv2.dk are galleri.tv2.dk, nyhederne.tv2.dk, and vip.tv2.dk.
Using YSlow we get a picture of the total page size and the number of http requests for the main page of each subdomain:
| galleri.tv2.dk | Total size 140.1K | HTTP requests 19 |
| nyhederne.tv2.dk | Total size 580.2K | HTTP requests 85 |
| vip.tv2.dk | Total size 464.4K | HTTP requests 58 |
The average page size is 395K and the average number of requests per page is 54.
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.
What kind of server setup do you need to handle this amount of traffic?
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’s case lighttpd) - this page shows that without too much hassle it is possible to achieve 10000+ requests/sec on a decent server with enough network bandwidth.
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 Scale rails from one box to three, four and five 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.
There must some database servers to handle all the data. There a several ways to setup these servers. Take a look at Courtenay’s article for an explanation of these.
2 Responses to “tv2.dk on Rails”
Leave a Reply