Playing the AWS ec2 Spot Market
The ec2 spot market fluctuates based on the supply and demand for ec2 instances. You can save a lot of money by timing the market and using more computing resources when they’re cheap.
Here is how to save the most amount of money:
- Run calculations when the market price is cheap
- Use the cheapest zone
- Abort calculations if the market price unexpectedly rises
How the Spot Market Works
Amazon sells excess ec2 capacity on the spot market for any bids greater than the market price. If the market price rises above the spot bid price, then Amazon automatically shuts down the spot instance. “However, unlike traditional bidding, when your Spot instances start running, you pay the live Spot market price (not your bid amount).”
Spot Instances “allow you to bid on spare Amazon EC2 computing capacity for up to 90% off the On-Demand price” and can provide massive cost savings.
ec2 spot instances function the same as on demand or reserve instances — the only difference is the pricing model.
Spot Pricing History
This AWS guide explains how to view the spot market price for the past day, week, month, or three months. Let’s take a look at the pricing for r3.xlarge instances for the past day.
From 7PM until 6AM, the spot pricing was quite low. Starting at 8AM, the spot price increased dramatically and started fluctuating rapidly.
r3.xlarge on demand instances cost $0.33, so the overnight spot rate of $0.07 represents a 79% discount. Big savings!
The spot pricing for the past week shows that prices are low during the weekends.
On Saturday, November 5th and Sunday, November 6th, the prices stayed in the $0.05 range and were always below $0.10.
Running big calculations during the weekend is a great way to save money.
Key Takeaway
The spot price is high during peak working hours and low at night and during the weekends. Running computations at night or on the weekend is the main way to save money with ec2 spot instances!
How much money can you save?
Suppose you need to run a calculation on a 40 node cluster for 8 hours.
- 40 on demand clusters costs $105.60 (40 nodes * $0.33 * 8 hours)
- 40 spot nodes at $0.07 costs $22.40 (40 nodes * $0.07 * 8 hours)
Timing the spot market saves $83.20 for this computation. If you run this computation on a daily basis, you’ll save $2,500 a month.
Finding Cheap Prices
Running computations with spot nodes when the market price is low is the key to saving money. It’s all about delaying the computation until the market price is cheap and running the computations in the cheapest zone.
Pricing by Zone
Regions have many zones, each with their own market price. At 9:31PM on November 20th, the us-east-1c and us-east-1d zones were significantly cheaper than the us-east-1a and us-east-1e zones.
The us-east-1c zone was at $0.0512 compared to an on-demand price of $0.33 — a 84% discount. The us-east-1a zone was 455% more expensive than the us-east-1c zone. Choose the zone wisely!
Warning!
There are data transfer fees when moving data between zones! I run computations and write out results to S3, so I’m not transferring data between zones — make sure to factor this into your analysis.
Spot Bid Price
Remember the spot market will accept bids when the spot bid price is higher than the market price, but will only charge the market price — you don’t need to pay the bid price. If the market price is $0.06 and you make a bid of $0.15, you’ll pay $0.06 and will lose the instances if the market price rises above $0.15.
Setting the spot bid price is a great way to cap the amount you’ll spend on a calculation. If the market price unexpectedly rises, you might want to abort a computation and run it some other time.
Let’s look at the worse case overnight spot prices over the past week in the us-east-1c region:
- November 15th at 1:18AM: $0.18
- November 15th at 10:10PM: $0.10
- November 18th at 12:09AM: $0.20
- November 19th at 1:09AM: $0.17
The market quickly normalized after these price spikes, so it probably wouldn’t have been worth aborting overnight calculations this week. To play it safe, you can set the spot bid price at 100% of the on demand price in case of a highly irregular overnight price spike.
Advice from Amazon
Here’s a video by AWS on how to determine your spot bidding strategy.
Success Stories
Several AWS users have cut ec2 costs by using the spot market.
- Pintrest cut costs 63% by using spot instances and implementing other cost saving measures
- University of Melbourne saves 56% by using spot instances
- Vimeo saves about 50% by bidding 10% over the current spot price
- Amazon acquired an ec2 spot market savings startup
ec2 Spot Bid Advisor
The Spot Bid Advisor “analyzes Spot price history to help you determine a bid price that suits your needs.”
The web page presents: “Savings compared to On-Demand based on the selected bid price, and calculated over the last 30 days, excluding any time your instance would not be running because you would have been outbid.”
When the bid price is set to 100% of on demand, the r3.xlarge savings over on demand is 73%. The market price of spot instances is generally much lower than on demand instances and you’ll still save a lot with a high spot bid price because the market price is used for spot node billing.
The ec2 spot bid advisor is a great way to estimate the cost saving potential of playing the spot market, but it doesn’t provide the real-time, specific information that’s needed to implement the cost saving strategy. I’d be awesome if the advisor analyzed historical data and provided information on the optimal times and zones to run calculations for different clusters.
Should You Play the ec2 Spot Market?
The ec2 spot market is best for computations that can be run when the market price for ec2 instances is cheap. Companies can save thousands by running computations at night or during the weekend.
Simply using ec2 spot instances with a spot bid price of 100% the on demand price and falling back to on demand instances when the spot price is higher would also offer huge savings.
It’s fun to time the market and cut your ec2 bill in half.
Additional Reading
Databricks and recently released an awesome article on using the spot market with their platform.