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’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 – 08 | 5 requests/sec |
| 08 – 11 | 30 requests/sec |
| 11 – 12 | 150 requests/sec |
| 12 – 14 | 250 requests/sec |
| 14 – 15 | 150 requests/sec |
| 15 – 24 | 30 requests/sec |
This works out to be 50 requests/sec on average. As we saw in the tv2.dk on Rails 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 peak number of requests and not the average number 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.
What if we were able to adjust the number of servers dynamically to satisfy the current load on the website?
Amazon EC2 to the rescue! Amazon EC2 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.
So how many servers do we need to run?
| Hours | Traffic | # of servers |
|---|---|---|
| 00 – 08 | 5 requests/sec | 1 |
| 08 – 11 | 30 requests/sec | 2 |
| 11 – 12 | 150 requests/sec | 8 |
| 12 – 14 | 250 requests/sec | 13 |
| 14 – 15 | 150 requests/sec | 8 |
| 15 – 24 | 30 requests/sec | 2 |
If we calculate the number of “server hours” it is 74. How much is this going to cost? Using the AWS Simple Monthly Calculator 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$ – still not too bad.
But you also have to pay for traffic. I will cover that in another blog posting.