Actually there are three allocation types:
on demand - kind of "default" mode. You request an instance, if there is free capacity, you will get the instance. No long term commitment, but once you get an instance, it's yours. It may happen that you will get a message that there is no free capacity for the specific instance type and AZ (so far it happened to me only once with AWS).
reserved - AWS reserves the capacity for you. You have guarantee that you will get the instance type in the selected region or AZ.
spot instance - it's kind of auction / bidding of unused capacity. You ask for an instance, you provide your maximum price and if there is free capacity and your price is at the current price or higher, you will get an instance. The difference is - if the free capacity is exhausted, or the current price is higher than your maximum bid price, your spot instance is terminated . You can get a termination warning event upfront.
Actually there are three allocation types:
on demand - kind of "default" mode. You request an instance, if there is free capacity, you will get the instance. No long term commitment, but once you get an instance, it's yours. It may happen that you will get a message that there is no free capacity for the specific instance type and AZ (so far it happened to me only once with AWS).
reserved - AWS reserves the capacity for you. You have guarantee that you will get the instance type in the selected region or AZ.
spot instance - it's kind of auction / bidding of unused capacity. You ask for an instance, you provide your maximum price and if there is free capacity and your price is at the current price or higher, you will get an instance. The difference is - if the free capacity is exhausted, or the current price is higher than your maximum bid price, your spot instance is terminated . You can get a termination warning event upfront.
The resources for both are the same, spot instances utilise the spare compute capacity within the AWS availability zone (those that are not reserved or launched on-demand).
Depending on the demand for that instance class in the availability zone the spot price will increase or decrease (even surpassing the on-demand price).
When you use a spot instance you are taking a risk that if demand increases you will lose access to the spot instance (you are given a 2 minute warning before termination). For his reason it is common to use a mixture of on-demand/reserved instances and spot instances so that you can withstand instance terminations.
Commonly in EC2 applications you would use an autoscaling group with a configured proportion between on-demand/reserved nodes and spot instances.
For more information take a look at the Requesting Spot Instances for fault-tolerant and flexible applications documentation.
Can anybody explain to me why Spot Instances would have better capabilities in the event of failure?
Spot instance Vs On-Demand instance in AWS - General - Off topic - AWS Thinkbox Discussion Forums
Spot Instances vs On-Demand vs Spot Block Instances (calculator)
What happens if I set the spot bid at the on demand price?
Videos
Determining when it is best to use spot instances versus on-demand instances can be very complex when you have a large number of tasks that need to run for a decently long duration.
I need to factor in the potential for interruptions and retries on the overall estimated cost. Some of the tasks I run can save their progress and others can't and so I needed to figure those implications out as well.
Taking all of those requirements I've written a spot instance simulator that lets me compare metrics around simulated cost and estimated time to completion for a group of tasks.
https://observablehq.com/@rustyconover/aws-ec2-spot-instance-simulator
I hope some of you also find it helpful.
There is a paper by folks from Israel Institute of Technology which analyzes the spot market. Their conclusion is that spot prices are not bid driven but rather generated with AR(1) function. So in such case it wouldn't be due to other's bids, but due to algorithm used.
http://www.cs.technion.ac.il/~ladypine/spotprice-ieee.pdf
Though, I guess it could have changed if spot market really reached the level where they could get nice prices from demand/supply. As Matt suggest it become a common practice to drive costs down with spot instances and many overbid on-demand prices to avoid down time. In longer run it was still cost effective ... but is it still? The real problem is that apart of Amazon nobody really knows how the prices are created.
This is not a bug, this is an priority / availability issue because on-demand instances have priority over spot-instances regardless of spot-bids. This stems from Amazon EC2 statement that you "bid on spare Amazon EC2 instances".
So when the demand for on-demand instances increases there are less spares available, and the availability of spot-instances decreases driving spot pricing higher according to competing spot-bids.
Many spot-bidders have failed to understand the higher priority of on-demand instances and have bid above on-demand pricing in an attempt to gain priority over on-demand instance requests, but this fails because on-demand instances have higher priority regardless of spot biding prices.
In turn these above-the-on-demand pricing bids have been competing against each other driving the highest prices multiple times higher than on-demand pricing when spot-instances availability is low.
Although the following was not asked, my recommendations for lowest-cost spot instances management of long-term workloads is:
- Design your application for failures (continuous backup / replication), and rapid recovery
- Set spot-instance bid price to that of on-demand pricing
- When a spot instance is terminated, restart it as an on-demand instance or in another region/zone where spot pricing is lower.
- Monitor spot-pricing until it goes lower than on-demand pricing
- Stop on-demand instance and goto 2. above
TLDR: I saw the historical spot pricing and it is almost always ~1/3 of the on demand pricing. And it appears I can set the bid price to the on demand price?
So wouldn't it just be smarter to never use on demand and always use a spot instance with the bid price as the on demand price?
Thanks in advance!!
Edit------
What I am trying to get at is that instead of paying the on demand price, it is possible to use spot instance pricing instead and of on demand at ~1/3 of the price.
But if you put the bid price as the on demand price, wouldn't likelihood of your VM being shut down would be very low and therefore you're just running at 1/3 of the VM costs constantly?