AppScale lets you deploy to On-Demand Instances in Amazon EC2, and AppScale 1.6.9 expands this support to also include Spot Instances. Spot Instances cost dramatically less than their On-Demand counterparts (although they often take much longer to acquire), and thus can save you money when deploying AppScale in AWS. This post details how to use this new Spot Instance support within AppScale.
Before continuing, you should be familiar with how to deploy AppScale with On-Demand Instances in EC2.
Spot Instance Support With Automatic Billing
Spot Instances in EC2 require the user to specify what the maximum price they’re willing to pay for the machines is. Choosing a price is a bit of a black art as this YouTube video from AWS describes. Using our “Automatic Bidding” support, the AppScale Tools query the current bid price and adds 10% (to improve your chance of acquiring the machines you need for your AppScale cloud). To use this option, update these two variables in the AppScalefile that is automatically generated for you via the
appscale init command.
We recommend using c1.xlarge, m1.xlarge, or m1.large for AppScale instances. The following is example output from an AppScale deployment using these options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
You can see that the average price for a
c1.xlarge instance when I ran this was $0.08, and that we got our instance with a max bid price of $0.09 – both of these are quite a bit better than the On-Demand price of $0.24! You’ll also note that these instances take quite a bit longer to get than their On-Demand equivalent – 321 seconds for the Spot Instance here versus about 30 seconds for an On-Demand Instance.
Spot Instance Support With Manual Bidding
You can also use manual bidding for spot instances by adding an additional variable to your AppScalefile.
1 2 3
You’ll still pay the market price for your instances, but if that increases, you won’t lose your machines (instead, you’ll just pay the increased price). The AWS video details this as being useful if you just need extra compute capacity and aren’t overly concerned with the price (vs AppScale’s Automatic Bidding).
One thing to know about Spot Instances is that when you put in a bid for instances, you’re putting in a request for an instance and you aren’t guaranteed to get it! If you bid significantly lower than the market price, you likely won’t get an instance (until the market price drops down to your bid price, which could be never). Also, if you bid a reasonable price but Amazon doesn’t have the spare capacity available, you won’t get your instances. In AppScale, we wait for a maximum of 30 minutes for your Spot Instances to come up and then abort if they do not. Here’s what it looks like when you run AppScale and we can’t get you Spot Instances:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
In this case, we log into the AWS Console, click on “EC2”, and then click on “Spot Instances”. That shows the reason why we couldn’t get Spot Instances – in the example above, it was “Capacity not available”. We cancel our Spot Instance Request by clicking “Cancel” so that we don’t get the instance (and thus get billed for it).
We overviewed how you can use AppScale to obtain Spot Instances instead of On-Demand Instances in Amazon EC2. Since AppScale is open source, you can also change how the Automatic Billing scheme works, if you find that bidding 10% more than average doesn’t suit your use case (or you’d like something more complex but still automated). For the adventurous, check out
appscale-tools/lib/agents/ec2_agent.py and look at
get_optimal_spot_price. In there, you can make it do anything you like, as long as it returns a float (the price to use).