Getty Images/iStockphoto

How to optimize Azure VMs for performance and cost savings

Learn how to reduce the monthly cloud bill from Microsoft while, in some cases, also improving Azure workloads performance by using a storage pooling technique.

In these modern times, Microsoft admins must keep an eye on costs while maximizing performance from workloads. Trying to find that balance can be a challenge.

Sometimes a VM in Azure is the only way to meet a business need. A virtualized workload in the cloud can spin up quickly and scale up, which makes it ideal for many enterprises. As with most cloud resources that use a consumption model, it's important to keep costs as low as possible. There are many ways to optimize Azure VMs, but the general rule is that small and consistent tweaks bring the best results.

How to reduce VM resource consumption in Azure

It seems obvious, but the cheapest VM resources are the ones we don't consume. Deallocating Azure VMs when not needed can save a significant amount of money.

For example, automating the deallocation of development servers at the end of the day, especially on a Friday before the weekend, saves about 64 hours of resources per week. This deallocation can bring substantial savings if you use one of the more costly VM SKUs.

Fortunately, you can automate this work. Microsoft hosts a video about this method. You can further automate this procedure via Azure Functions. This is why it's useful to properly tag VMs. For example, you can use a script to process any VMs tagged with Development. You can use these tags to automatically start or deallocate the VMs on a schedule.

Understanding the Azure terminology is important because deallocating a VM is not the same as powering it off. Putting a VM in a deallocated state releases the compute resources and stops those charges. Microsoft will continue to charge for the reserved compute resource for a powered-off VM even if it is not currently running.

Pay attention to the Azure Advisor recommendations

I know many people who ignore the Azure Advisor, which among other things, suggests ways to reduce the costs of your Azure resources. It is an extremely useful tool when used correctly. Over time, Azure Advisor evaluates the VMs against a set of criteria and makes suggestions. You don't have to heed its advice, but you should check its suggestions and determine whether they are valid.

It's important to select the right VM SKU because some are better suited for certain workloads. For example, a D-series VM is typically fine for general workload but other SKUs, such as the M-series, have been designed for database or data analytics workloads.

How to use Azure Spot VMs properly for better cost savings  

When you know how to wield them appropriately, Azure Spot VMs, sometimes called spot instances, are great alternatives for non-production hosts. Spot instances are Microsoft's way to help organizations manage resource capacity in Azure. The price can be up to 90% cheaper than other Azure VMs, but Microsoft reserves the right to evict the spot instance with little notice.

Many administrators feel using this type of VM is a gamble, but you can reduce the risk of eviction by using the maximum price setting of -1 for the Azure Spot VM. This is an automated way to avoid eviction by paying more for the spot instance up to but not beyond a standard VM cost. By adjusting the pricing configuration, you reduce the chance Microsoft will evict your VM by selecting another organization's spot instance without this maximum price setting.

Using Azure Spot VMs in production is not a good idea, but you can optimize development and quality assurance servers with this method.

Get better Azure disk performance for less money.

Disks attached to the Azure VM are another area to review carefully. What are you trying to achieve with the VM? Do you need raw storage space, high performance or portability?

Admins can maximize storage flexibility while reducing costs in several ways. For a few extra dollars and time spent configuring the VM disk, you can improve the disk performance by creating a storage pool consolidating multiple disks into a single virtual disk.

Many administrators make the mistake of attaching one large disk to the Azure VM as the data disk, but this might not be the best option. Administrators can get more IOPS and throughput by joining several smaller disks into one logical disk using either Storage Spaces in Windows or Logical Volume Manager (LVM) in Linux.

Say an administrator wants to build an Azure VM with 1 TB of disk space with performant I/O. They start by selecting an E4-2as Windows Server instance in the East US 2 region. If the administrator selects a 1 TB S30 mechanical HDD disk, they will get 500 IOPS and a throughput of 60 MB/s. This configuration would cost $359 per month.

However, with two S20 mechanical HDD 512 GB disks, you get 1,000 IOPS with a throughput of 120 MB/s for $361 per month.

Alternatively, the administrator could use four S15 HDD 256 GB disks to get 2,000 IOPS and a throughput of 240 MB/s for $363 per month.

In the last scenario, the cost is approximately $4 more a month but you get quadruple the performance compared to the one large disk setup. That's enough speed to run many workloads, including SQL Server.

For comparison, a standard SSD 1 TB disk costs $395 per month. By using several smaller disks, the organization saves $384 per year per server. With this configuration multiplied across a fleet of VMs, the yearly savings could easily surpass thousands of dollars for a large enterprise.

Prepare to set up the storage pool properly

This HDD disk configuration makes a big difference in price with the added benefit of meeting performance requirements instead of using more expensive SSD disks. For high availability purposes, Azure uses locally redundant storage (LRS) for a VM to store three copies of the data in the primary region.

When using Storage Spaces, the same rules apply as any RAID configuration. You must add disks of the same size in the storage pool and keep the column count specified by the storage pool settings.

Using smaller disks allows you to scale more incrementally at a better price. For example, if you had two 2 TB disks and wanted an extra 100 GB, you would have to add two more 2 TB disks. By using smaller disks, you keep costs lower.

While smaller might be better, Storage Spaces can only handle a finite number of disks per VM. I do not recommend using more than five or six disks per VM. Each SKU is different, so check with Microsoft documentation.

Because the disks added have redundancy from LRS, it is acceptable to create a single boot disk to hold the OS files.

How to set up the storage pool

The following process creates a storage pool consisting of the four disks in a Windows Server 2019 VM and presents it as the F:\ drive.

Start by creating the VM in Azure with the OS disk and four S15 HDD disks of 256 GB each.

Once the VM is running, open the Storage Pools section in Server Manager and select Rescan Storage to show the newly added disks.

Next, combine the disks into a storage pool. Windows storage refers to these unassigned disks as primordial disks, which you use to create a storage pool. From the Storage Pools section, select the primordial area, then click on Tasks and select New Storage Pool. The wizard will start; enter a name and description for the storage pool.

Create a storage pool
Select the New Storage Pool option after selecting the disk types in Azure.

Next, add the disks and leave the default settings. Click Next to go to the confirmation screen and click the Create button.

How to create the virtual disk

After you create the storage pool, the next step is to create the virtual disk. Go to the main Storage Pools view, select the new storage pool and, under Virtual Disks tasks menu, click New Virtual Disk.

Azure virtual disk
After building the storage pool, go to the next step to create a new virtual disk.

Follow the wizard to configure the virtual disk by setting the name, storage layout and size while using the defaults for the other sections. For storage layout, select Simple, which spans all disks with no redundancy setting. This is the RAID 0, or disk striping, configuration for maximum performance. For the size, select Maximum size, go to Confirmation, and then click Create to build the virtual disk to complete the process.

How to create the new volume

The next step is to right-click on the virtual disk and select New Volume. This starts the wizard in which you assign the drive letter to F: and format the volume with a file system, usually NTFS. This completes the process and produces highly performant storage for a workload without incurring a significant cost.

Consider the following best practices to make sure this Azure disk setup meets your expectations:

  • While this storage pool configuration might be ideal for many workloads, it might not be suitable for ones that require low latency. Consider using Azure Monitor to check that disk performance continues to meet the workload requirements.
  • Verify storage costs with Azure Cost Management to avoid surprise charges.

Stuart Burns is an enterprise Linux administrator at a leading company specializing in catastrophe and disaster modeling.

Dig Deeper on Microsoft cloud computing and hybrid services