EC2 reserved vs on-demand costs (and R graphs!)
Posted Tue, 05 Apr 2011
I was helping with some capacity planning and run-rate math today at work and found that ec2 reserved instances are much cheaper compared to on-demand - If this is obvious to you, chill out, I have historically never really used EC2 nor have I ever been close to budgeting. ;)
I proved this conclusion with some math, but frankly I like visualizations better, so I decided to learn R. I wrote an R script that will graph an on-demand vs reserved pricing for one m1.large instance (code at end of the post).
The result is this graph:
The graph says it all, and definitely tells me that we need to be reserving all of our instances at Loggly - and it gives me a rule-of-thumb:
- If we're going to use one instance unit for at least 9 months, reserve for 3 years.
- If we're going to use one instance unit for at least 6 months, reserve for 1 year.
- Otherwise, stick with on-demand.
This also means that our random "debug something" deployments that are shutdown much of the time are probably best off being reserved instances as well- at least for a 1-year thing - since we are likely to use those deployments for more than half of a year.
A 3-year on-demand price for m1.large is just shy of $9000, which is twice as expensive as the 3-year reserve. Capaticy plan and maybe start buying reserved instances. Make your CFO happy.
And in case you were going to ask, I ran the same plot with data from EC2 "quaduple extra large" instances and the savings and break-even points were the same. I bet the rest of the prices flow similarly.
The R script is follows, run it with 'R --save < yourscript.r':
# Values taken from http://aws.amazon.com/ec2/pricing/ # for an m1.large ("Large") instance on_demand_hourly = 0.34 reserve_hourly = 0.12 reserve_1year = 910 reserve_3year = 1400 # quadruple extra large instances #on_demand_hourly = 1.60 #reserve_hourly = 0.56 #reserve_1year = 4290 #reserve_3year = 6590 on_demand_daily = on_demand_hourly * 24 reserve_daily = reserve_hourly * 24 x <- c(0, 365) y <- on_demand_daily * x # Calculate day of break-even point reserve vs on-demand rates break_1year_x = reserve_1year / (on_demand_daily - reserve_daily) break_3year_x = reserve_3year / (on_demand_daily - reserve_daily) png(filename = "ec2_m1large_cost.png", width = 500, height=375) plot(x,y, type="l", col='red', xlab="", ylab="cost ($USD)") title("EC2 cost analysis for m1.large", sprintf("(days)\n1-year is cheaper than on-demand after %.0f days of usage,\n 3-year is cheaper after %.0f days", break_1year_x, break_3year_x)) text(60, 0, sprintf("on-demand=$%.2f/hour", on_demand_hourly), pos=3) abline(reserve_1year, reserve_daily, col='green') text(60, reserve_1year, sprintf("1-year=$%.0f+$%.2f/hour", reserve_1year, reserve_hourly), pos=3) abline(reserve_3year, reserve_daily, col='blue') text(60, reserve_3year, sprintf("3-year=$%.0f+$%.2f/hour", reserve_3year, reserve_hourly), pos=3) point_y = reserve_1year + reserve_daily * break_1year_x points(break_1year_x, point_y) text(break_1year_x, point_y, labels = sprintf("%.0f days", break_1year_x), pos=1) point_y = reserve_3year + reserve_daily * break_3year_x points(break_3year_x, point_y) text(break_3year_x, point_y, labels = sprintf("%.0f days", break_3year_x), pos=1) dev.off() quit()