Wednesday, December 22, 2021

How to use Azure Spot VMs?

 There are instances where you need high availability for regular workloads. But there are also instances where you do not need availability all the time. Imagine having a test environment,  things can wait. Late night batch processes might not need very high availability. On the other hand,  these batch processes can be compute expensive. If you are to have a separate instance allocated, that might cost considerably higher.  

What if we can use something 'leftover' in Azure to have a reduced cost mechanism? That is where Azure Spot VMs come in. 

Azure data centres leave some spaces for expansion. There are plenty of free capacity in these data centres that are not fully utilised, but may be needed at some point. These excess capacity is available for a cheaper price as Azure Spot VMs. These are not SLA backed so should not be used for workloads that require consistent availability. 

What happens is whenever Azure need the resources, it will evict your VM within 30 seconds of notice given via Azure Scheduled events. 

There are two types of evictions.  

  1. Capacity Only
  2. Price or Capacity

Let us do some maths. I am considering a Windows VM Instance of following specifications. 

  • Size: Standard D2 V2 - 7 GB Memory
  • Location: East US
  • Price: 106.58 USD/month ~ 0.148 USD/hr

At capacity or price only eviction type, you can set cost any above 0.058 USD/hr. That is the basic minimum hardware cost and also 39% of the standard price. If you select capacity only eviction type,  this price will be 0.146 USD/hr as shown in screenshot above but will be charged only to the time it is used.  

You can also compare the regions closer and opt into a lower rate or a lesser eviction rate. As you can see in the screenshot above, eviction rate has been around 0% to 5%. Some regions do have this even at a 15%. 

There are two eviction policies. 

  • Delete - VM will be deleted, you can deploy something totally new.
  • Stop/ Deallocate - You can schedule to allocate once deallocated, but there is no guarantee it will be,  which may require retries. 

So with all these fun on, why do not I schedule a VM to shut down and start up for an hour or two only when I needed? Well, that is a separate scenario for a different requirement and the price per hour you pay may remain high.

No comments:

Post a Comment