Azure Cost Optimization Best Practices

By:   |   Comments (1)   |   Related: > Azure


Problem

More and more Azure VMs are being deployed every day, but one of the issues is the cost.  What can be done to reduce the costs of Azure VMs?

Solution

Azure only charges when VMs are up and running so the solution to reduce cost is to choose the right VM size, correct disks depending on the usage and to shut down the VM when it isn't in use. The shutdown solution is to be applied on DEV and TEST machines. DO NOT shut down PROD servers unless you know they won't be used for a period.

Creation of the Azure VM

The next steps will show you where you can save money during the creation of an Azure VM. It's important that you already have the know-how to create an Azure VM since I'll point only the steps where you can save money.

For this example, I'll use one of the many pre-existing SQL Server images.

Create a new VM from Azure portal and click on "Browse all public and private images" under the Image combo box and then type "sql server" in the search field (for DEV environment choose an image with SQL Server Developer Edition since it is free):

create azure vm

Azure VM Size Options

There are default VM sizes depending on the Image that you choose and the affected Region so be careful and check if the proposed one is really what you need. The majority of the times you can reduce the size to something that fits you better and at a lower cost. For that click on the "Change size" link in the Size field:

create azure vm

In the Change size screen, you can select from one of the many available options. It helps if you use filters so it presents only the options that you are interested in. In the below example I'm only interested in servers with 2 vCPU and 8GB RAM so I've added the necessary filters:

select vm size

NOTE: When grayed out, it means that option isn't currently available in the selected region (in the above example the 2 bottom lines are grayed out).

With that, I've choose the cheapest VM and one that I know it will serve my development purposes:

select vm size

NOTE: Azure VM price is also depending on the region where it will be created, but don't place an Azure VM in another Region with a lower price without confirming the following:

  • Data transfer between locations – Users located in a different region that need to move data between the resources will lose any potential savings by the additional cost of transferring data between those resources since inbound data transfers are free and outbound data transfer price is based on the Billing Zones.

Azure VM Windows Server License

Other point where you can save money is if you already have a Windows Server license (sorry Linux users - nothing for you to save here). On the bottom of the VM creation page you'll find the "Save money" section where you can use the Azure Hybrid Benefit:

tips to save money

AAfter that review the actual estimated cost of your VM (in my example I'm saving near to 54%):

size cost

Azure VM Disks Options

Click on Next to go for Disk options. Here it will give the Premium SSD option by default. For non-production environments and for production servers that don't need high performance SSD, change to a disk with a lower cost. I recommend Standard HDD for Development purposes:

create a virtual machine

You can learn more about the disks pricing here.

Azure VM Management Section

There's nothing in the Networking section that can help us save, so complete that section with your requirements and move on to Management. At the bottom of Management section let's enable the auto-shutdown for the non-PROD VM and provide the desired shutdown time and specify an email address for the notification (this is good for people that are still working at that time so they can react before the shutdown):

auto shutdown azure vm

NOTE: When an Azure VM is stopped you won't be charged for the resource usage (CPU, RAM and Dynamic IP) during the period the server is down, but you'll be charged for the Azure Storage account since the disk file image can't be released.  This is a very small price to pay compared to the rest of the resources.

Remember that when using a Dynamic IP address when the server starts it might have a different IP address assigned. If you need to keep the same IP address then use a Static IP address instead, but this will increase your costs. Learn about Azure IP address pricing.

Azure VM SQL Server Storage Settings

There are no costs in the Advanced section and we can move on to SQL Server settings. The first section where we can save money is by choosing the best storage option for our needs:

azure vm storage

Click on "Change configuration" link and if you don't need any Storage optimization choose General instead of Transactional processing or Data warehousing options. In the Disk Type select the minimum possible that fits your needs. Sharing Log and TempDB storage with Data storage is also a good idea for non-PROD servers where the performance isn't a must, so you don't need to pay for more storage:

azure vm storage

Keep in mind that the disk performance depends on the VM size you've selected before. A warning like the one below is what you'll receive when you choose a disk that might not be fully supported by your selected VM size so this is already an alert that you might being paying more for something that you won't be able to take full advantage of:

azure vm storage

Azure VM SQL Server Licensing

In the SQL Server License section, you can use an existing SQL Server License that you already owns (only available for Windows VMs and for SQL Server Standard and Enterprise Editions since Developer Edition is free):

azure vm sql server license

Azure VM Review and Create

You can proceed now to the creation of the VM. In the Review you'll get the price per hour for the new VM:

azure vm create review

To calculate the price per month: $0.0750 * 730h = $54.75.

BBut that value is only if we let the server run 24x7, so imagine the possible savings if we only have it running during regular office hours. Let's say 10h/day, 5 days/week and 22 days/month: $0.0750 * 220 (22days*10hrs) = $16.50 per month, per server. Use this exercise to obtain an estimate of how much savings you'll have for your development environment.

Existing Azure VM

FFor existing Azure VMs you can start by review if they are correctly sized. Oversized VMs are excellent candidates to be resized to use less resources so you can save money. To know to which size you should downgrade a VM, just monitor the respective resource usage.

Resize Existing Azure VM

In the Azure Portal, select the desired VM to be resized and click on the Size option. You'll get the available new sizes that you can use. Don't forget to use the filters to reduce the list to present only the desired new sizes. This operation will restart your Azure VM.

resize vm

Auto-shutdown Azure VM

For the Azure VMs that you don't have an automatic shutdown configured you can now configure the respective auto-shutdown in the virtual machine menu.  Go to the Operations section where you'll find the Auto-shutdown option:

auto shutdown vm

NNOTE: This option is highly recommended for non-production servers. Some production servers may also have an auto-shutdown configured if they don't need to be online after regular working hours.  Be very careful with these kinds of decisions and triple check if you want to configure an auto-shutdown time for production servers.

Azure VM Manual Shutdown

Use the manual shutdown for exceptional cases or when you don't want to schedule an auto-shutdown.

You can see from the Azure VM Status when it is up and running:

manual shutdown vm

UUse the Stop option to manually shutdown an Azure VM (if you connect to the Azure VM and shut it down from there not all resources will be deallocated). If the VM is using a dynamic IP, a message will appear informing you that IP address will be lost, meaning that next time the VM starts it will have another IP address.

manual shutdown vm

You can now see that the new VM Status is Stopped (deallocated) and there's no Public IP address since this resource has been also deallocated, meaning that no use, no pay.

manual shutdown vm

Costs of VM after 24 hours

II'm providing the cost report for the VM I've created for this article so you can see an example on how the costs are reported (prices are in CHF because I'm in Switzerland). The big part of the costs is the VM and that's why we should shut it down when not in use. Disks can't be shut down or deallocated, but costs of disks are irrelevant compared with the rest of the VM:

azure vm costs chart

Summary

TThe auto-shutdown is good to be configured for days that you forget to shutdown servers, but if you see that you don't need the server you can shut it down manually to save even more.

Of course if a server has no more use, delete it immediately so you don't incur more unnecessary costs.

Next Steps
  • Review all your VM resources usage to understand which ones you can downgrade to save costs
  • Implement scheduled auto-shutdowns for non-PROD machines
  • In case you have Microsoft licenses check this page: Azure Hybrid Benefit Savings Calculator


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Vitor Montalvao Vitor Montalvão is a SQL Server engineer with 20 years of experience in SQL Server, specializing in performance & tuning, data modelling, migration and security.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article




Saturday, March 21, 2020 - 6:46:31 AM - Eitan Blumin Back To Top (85154)

It would've been a good idea to mention the option of reserved instances for virtual machines.

Most of the tips here are relevant for development machines rather than production machines.

But reserved instances for virtual machines can be extremely beneficial for production machines.

You can save up to 70% of the costs which is amazing, and it comes with a surprisingly minimal risk, if at all.















get free sql tips
agree to terms