What Does the Autoscaling Application Block Do?

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

On this page:
Constraint Autoscaling Rules | Reactive Autoscaling Rules | Example Rules

The Autoscaling Application Block can automatically scale your Microsoft Azure application based on rules that you define specifically for your application. You can use these rules to help your Azure application maintain its throughput in response to changes in its workload, while at the same time control the costs associated with hosting your application in Azure. Scaling operations typically alter the number of role instances in your application, but the block also enables you to use other scaling actions such as throttling certain functionality within your application.

Note

Typically, you will host the Autoscaling Application Block in its own worker role in the cloud, or in an on-premises application, from where it can monitor and scale your Azure application.

In the following diagram, the green line shows a plot of the number of running instances of an Azure role over two days. The number of instances changes over time in response to a set of autoscaling rules.

Follow link to expand image

Autoscaling behavior in an Azure application

Constraint Autoscaling Rules

To set upper and lower bounds on the number of instances, for example, let's say that between 8:00 and 10:00 every morning you want a minimum of four and a maximum of six instances, then you use a constraint rule. In the diagram, the red and blue lines represent constraints rules. For example, at point A in the diagram, the minimum number of role instances rises from two to four, in order to accommodate the anticipated increase in the application's workload at this time. At point B in the diagram, the number of role instances is prevented from climbing above five in order to control the running costs of the application.

Reactive Autoscaling Rules

To enable the number of role instances to change in response to unpredictable changes in demand, you use reactive rules. At point C in the diagram, the block automatically reduces the number of role instances, from four to three, in response to a reduction in workload. At point D, the block detects an increase in workload and automatically increases the number of running role instances from three to four.

The reactive rules that dynamically change the number of role instances can use a variety of techniques to monitor and control your application's workload. In addition to using performance counters and Azure queue lengths as indicators of workload, the block allows you to define your own custom metrics, such as the number of unprocessed documents in the application.

Note

A reactive rule cannot make a change to the number of role instances unless there is a constraint rule that applies at the same time. It is easy to create a default constraint rule that always applies.

For more information about how the block resolves conflicts when multiple rules apply at the same time, see the topic "Understanding Rule Ranks and Reconciliation."

Example Rules

The following snippet shows the set of example rules that were active during the two days shown in the diagram above. There are two constraint rules: one rule is always active, the other overrides the default rule at peak times. There are two reactive rules: one rule tries to increase the role instance count by one if average CPU usage for the last 45 minutes is over 80%, the other rule tries to decrease the role instance count by one if average CPU usage for the last 45 minutes is less than 20%.

<rules 
  xmlns=https://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules
  enabled="true">
  <constraintRules>
    <rule name="Default" description="Always active" 
          enabled="true" rank="1">
      <actions>
        <range min="2" max="5" target="RoleA"/>
      </actions>
    </rule>
    
    <rule name="Peak" description="Active at peak times"
          enabled="true" rank="100">
      <actions>
        <range min="4" max="6" target="RoleA"/>
      </actions>
      <timetable startTime="08:00:00" duration="02:00:00">
        <daily/>
      </timetable>
    </rule>
  </constraintRules>
  
  <reactiveRules>
    <rule name="ScaleUp" description="Increases instance count" 
          enabled="true" rank="10">
      <when>
        <greater operand="Avg_CPU_RoleA" than="80"/>
      </when>
      <actions>
        <scale target="RoleA" by="1"/>
      </actions>
    </rule>
    <rule name="ScaleDown" description="Decreases instance count" 
          enabled="true" rank="10">
      <when>
        <less operand="Avg_CPU_RoleA" than="20"/>
      </when>
      <actions>
        <scale target="RoleA" by="-1"/>
      </actions>
    </rule>
  </reactiveRules>

  <operands>
    <performanceCounter alias="Avg_CPU_RoleA" 
      performanceCounterName="\Processor(_Total)\% Processor Time" 
      aggregate="Average" source="RoleA" timespan="00:45:00"/>  
  </operands>
</rules>

The block automatically logs details of all the rules that it executes and the results of the all the scaling actions that it performs.

Next Topic | Previous Topic | Home

Last built: June 7, 2012