Overview
While setting up an Azure VM, it is important to understand the pricing model and service offerings well in advance before setting up the environment. If not, we may end up paying exorbitant bills that could have been avoided if cost-optimization strategies had been followed. In this article, we discuss practical strategies and insights to help you avoid such situations and maintain better control over your costs. We’ll also discuss how much is too much and the role of premium features in Azure pricing.
Note that the article has images having sizing and configurations in Azure. These have been procured from the Azure portal from a certain region at the time of writing. They have been shown here purely for demonstration purposes and should not be considered to be indicative of current availability or configurations for your region. It is advisable to refer to the official Azure documentation (or your Azure Portal) for the most up-to-date and accurate information regarding costs and pricing.
Let’s get started.
Implement Scheduling mechanisms to start and stop your Azure VM
Azure VMs are billed based on resource usage, which includes CPU, memory, and storage consumption. It’s important to note that you will be charged for these resources, even if the VM is idle or not actively being used. In other words, you will get charged just for keeping the VM ‘ON’ whether or not there are processes/jobs running inside the VM at a certain point in time. Hence, workload optimization is necessary to prevent unnecessary expenses.
To effectively handle this, do the following:
- Identify the processes and jobs you intend to set up in the VM. This can be a process related to your application server, or even a job that runs within a database hosted on the VM.
- Determine dependencies between jobs i.e., Identify jobs that need to run in parallel and those that need to run concurrently. Also, make a note of jobs that are independent of other jobs.
- Attempt to schedule job runs within a consistent time frame. For example, if you have multiple concurrent jobs that process data from a database, aligning the job runs within the same time range makes sense.
- Once you have narrowed down the time range, you can schedule your VM to start and stop at a desired time frame. For example, if the jobs need to run between 9 PM and 12 AM every night in a certain time zone, you can schedule your VM to start at 8.45 PM.
Scheduling a VM to start and stop can be done using Powershell, CLI, or Console. The Azure Console provides users with the functionality and ease of managing their Virtual Machines using the Azure Portal.
The options to start, stop and deallocate your VM can be found by accessing your VM in the Azure Portal. Below is the automation template provided by Azure.
Here are the steps to access the automation templates –
Select your VM and access the Tasks(preview).
Click on ‘Add a task’
Select the template ‘Start Virtual Machine’
After authenticating yourself, you can configure the time you want to start the VM.
The same steps can be used to Power off and deallocate the VM as well.
The most important step that helps reduce costs effectively is to deallocate the VM. There is a major difference between stopping a VM and deallocating a VM. When you stop a VM, Azure Resource Management temporarily halts the VM but retains the allocated resources and preserves the VM’s state. However, when you deallocate the VM, Azure Resource Management releases the allocated resources back to the Azure Resource pool. The released resources become available for other resources or services to utilize. They may also be allocated to other applications or virtual machines based on demand. Thereby, you save on Compute Costs. Remember that you will still need to pay for the Storage Costs. Below is a visual that shows the components in an Azure Environment and its interaction with a Virtual Machine.
A good strategy to consider is to de-allocate your VMs during periods of inactivity. De-allocating non-production environments is also a good option that can help achieve significant cost savings. Ensure that deallocation aligns with your operational needs and doesn’t impact critical processes or services.
Change disk from Premium to Standard
It is natural to want advanced features like premium disk storage, managed disks, and automatic scaling for your environment. But it is often necessary to ask yourself if they are actually needed for your use case.
Azure supports a range of premium and standard disks. As you may have guessed, Premium Disks cost more than Standard Disks. If you have I/O intensive operations such as databases and big data processing, you will have to continue with premium disks. But if you have workloads that are not time-bound and not too intensive, then standard disks are a good option. Let’s see this with an example.
Let’s say that you have a script that pulls data from an external file system on a daily basis (once a day) and populates the data for a cloud-based reporting tool. This is a less intensive operation and can be easily handled using a standard disk.
Let’s assume that you have a SQL Database hosted on the VM that connects directly to a self-service report that users can query in an ad-hoc fashion. If that’s the case, it is better to stick to a premium disk. However, you can consider downgrading to a lower tier within a premium disk to get some cost savings.
Below is the process to change the disk via the Console. Click on the Azure VM and access the ‘Disks’ option in the side pane.
Click on the hyperlink in the Disk Name.
Click ‘Size + performance’ in the side pane that follows.
The current configuration being used is shown with a grey highlight. This is where users can change their disk from a premium to a standard disk type. You can select a different configuration by clicking on it. Note that any configuration that is not applicable to your environment will not be clickable.
Change the configuration of the VM
Azure offers VMs of different sizes, RAM, storage, and computing power. Each series and generation of Azure VM is designed to deliver specific performance characteristics, allowing users to choose the most suitable type based on their workload. The figure below shows the different generations offered by Azure VM.
Determine your workload and downgrade to a VM that best matches your workload requirements and also results in cost savings. Below are the steps to do the same –
- Click on the VM
- Click on the ‘Size’ in the side pane
The resulting pane shows the different VM generations and all associated details like the cost per hour, RAM, and workloads supported.
Note that this is just a sample image and is not intended to show all available configuration options.
Scroll all the way to the right to access the Cost/hour.
Note that these costs are at the time of writing the article. The current size and generation of the VM being used by your workloads are shown at the top. To change the VM configuration, click ‘Resize’.
Consider changing to regions with lesser pricing
The pricing of Azure can vary across different regions. Regions with lower demand may have slightly lower pricing than regions with higher demand and limited availability of resources. Compare pricing across different regions using the Azure Pricing calculator while planning your deployment. However, try to select a region that is close to you to avoid unnecessary network delays.
For example, you may find that a region that is based out of Eastern Europe is less expensive compared to regions that are on the East and West coasts of the US. Let’s assume that you have a few users who are in Europe who need access to the VMs that you set up. To improve performance, it may make sense to set up VMs in a region that is close to their location rather than setting up VMs in a US region. However, it is important to be aware that there might be data transfer regulations and restrictions to consider when determining the optimal region for your VM setup. Additionally, it is important to consider that as the region gets farther from your current location, the performance may be affected by increased network latency, resulting in slower response times.
Concluding Remarks
In this article, we discussed 4 strategies to reduce costs on Azure bills without compromising on the efficiency of existing/new workloads. All of these can be seamlessly implemented using the Azure portal without having to use a programmatic approach. Understanding your workload requirements and processing needs is key to managing a cost-effective environment. At the same time, it is crucial to balance cost savings with factors such as performance and data transfer regulations. By applying these techniques, you can streamline Azure VM performance while effectively managing costs, ensuring efficient utilization of resources, and achieving your desired outcomes.