The real cost of VM's and how can we reduce it
Updated: Jan 25, 2022
If you read my previous articles on cloud computing, you should be familiar with the fact almost every resource created in the cloud has its costs. Let's take virtual machines as an example, what most people may think that the payment is only for the creation and use of the VM, but the actual cost is also calculated on the VM (has it represented in the azure costs calculator), the storage of the virtual machine (you also have costa base on where the image of the virtual machine is stored) and even on the use of public IP that is exposed by the virtual machine.
Here is a typical setup for a virtual machine and its costs:
Total Costs: ~175$ (per month) and not 150$ as displayed in the Azure calculator.
So how can we reduce the costs of a virtual machine?
There are four simple techniques to reduce the actual costs of a virtual machine; using them wisely can reduce tens, hundreds, and even thousands of dollars per month:
The use of reserved instances provides the benefit of getting a substantial discount that may be up to 60% by using an upfront payment. This approach is very efficient if you know that you have VM's that need to run continuously (e.g., production environment) and for at least one year (this pricing model is offered for 1 or 3 years).
The total reservation cost can be divided into monthly payments.
Once a reservation is made, it cannot be refunded.
For more information about the Azure pricing models:
Make sure to select the correct disk for the machine and not the default suggested disk (usually, it's a premium SSD which is the most expensive option). So if you need to work with a VM that is non-IO-intensive, use a lower budget disk, like Standard SSD, which is a lite bit slower but still provides the SLA and performance for this VM.
As simple as it sounds...automatically shouting down your VM can and will save you money as in the cloud, you pay only for what you are using (although you still pay for Public IP and Storage ). So, if the VM is not used at specific hours of the day, make sure to shut it down. This is relevant mainly for Dev/Test machines that shouldn't be running 24/7, and we only use them during working hours.
If you embrace this simple solution, you will most likely save almost 50% of VM costs. And the good thing is that it can be done automatically by using a simple setup in the Azure portal when creating the virtual machine or modifying it after creation.
Spot instances are machines that run on unused capacity in Azure. So, Azure has massive data centers, and not all servers in the data center are used 100% of the time, which is an important thing to know as it provide you with the opportunity to use the new servers to reduce the price. But wait, there is one significant catch here... these servers can be evicted at any moment when needed by Azure, so if there is a new request for creating a VM, Azure can decide that your currently used machine is the one to dispose of (you will only get a concise notification for this eviction).
More Cost Saving Techniques
I prefer Linux over Windows because Linux VMs are much cheaper (there are no further payments on window licensing).
Check the same VM configuration offered in nearby regions as prices vary between different areas.
CPU - Remember that you pay for it regardless of its utilization, which means that the CPU shouldn't rest. You pay for it:).