Netreo is now BMC. Read theBlog

Auto-scaling Azure Cloud Services and WebApps based on queue lengths

By: Netreo
April 6, 2017

If you’re running applications in the cloud, you have the ability to use and pay only for resources that are needed to process the current workload with auto-scaling.

In many cases, to optimize the usage of compute resources such as Azure Cloud Services (worker roles), Azure WebApps running WebJobs, or Azure Virtual Machine Scale Sets (VMSS), it is beneficial to adjust the number of instances according to demand.

In this article, we’ll show you how to automatically scale Azure compute resources based on queue-based workload using Netreo. If you are not familiar with Netreo, it is a cloud monitoring service that provides a set of sophisticated automation and monitoring capabilities for the Azure platform.

A popular way to distribute workloads among multiple compute instances is by using Azure Service Bus queues or topics. Coincidentally, observing the number of messages in the queues/topics provides useful signals for auto-scaling of compute resources.

When the number of messages in queues/topics exceeds a certain threshold, it is a good indication that services processing those messages are having trouble keeping up. Consistently, a few messages in queues/topics indicates that the number of compute instances can be scaled down to reduce costs.

To auto-scale compute resources such as Azure Cloud Services, WebApps running WebJobs or VM Scale Sets, based on the number of messages in Azure Service Bus (ASB) queues/topics or Azure Storage queues, you need to follow these four simple steps:

1. Run Netreo Setup Wizard to start monitoring ASB/Storage and Azure Compute resources

If you aren’t using Netreo yet, request a demo, and our team can help run you through the process.

2. Define a queue length metric

Once ASB/ASQ resource has been brought into Netreo, define a new metric that tracks the length of a particular queue or topic:

  • Open configuration dialog for the ASB/Storage resource
  • In the Metrics tab, add a new metric that will track messages in a given queue or topic.
    • For ASB queue, choose “AzureServiceBusActiveMessageCount” metric category
    • For ASB topic, choose “AzureServiceBusActiveMessageCountBatch” metric category
    • For Storage queue, choose “AzureStorageQueueLength” metric category
  • Specify a name and save

3. Link the queue length metric into the Compute resource

To define auto-scaling rules for compute resource (VMSSs, WebApps, or Cloud Roles), you need to have those resources “see” the newly defined queue length metric:

  • Open configuration dialog for Compute resource
  • In the Metrics tab, add a new metric of type LinkedMetric and point it to the metric previously defined in the queue resource
  • Specify a name and save

4. Define auto-scaling rules
Compute resource will need to have two rules to increase and decrease the number of workers based on the metric value. It is also a good idea to define limits to ensure the number of instances doesn’t exceed expected values:

  • Open configuration dialog for Compute resource
  • In the Scale Adjustments tab define “Scale up” rule that will add two instances when the queue length is higher than some threshold, e.g. 100 (screenshot below)
  • In the Scale Adjustments tab define “Scale down” rule that will remove an instance when the queue length is below some other threshold,e.g. 10 (screenshot below)
  • Scale expressions can be quite sophisticated, taking many metrics and time of day into account
  • In the Scale Ranges define a rule limiting the number of instances to 2 up to 10 (screenshot below)

Netreo supports many sophisticated auto-scaling scenarios. Request a Demo and Learn more here.

The same approach can be used to auto-scale other Azure resources, such as Cloud Services or VM Scale Sets. Netreo can auto-scale resources based on any metric captured anywhere in your Azure environment, or according to a schedule.

Find Out how Netreo can help with all Azure monitoring needs. Request a Demo Today

Ready to get started?

Get in touch or schedule a demo

Get Started Learn More