Jaa


Defining Constraint Rules

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:
Specifying Timetables - Common Features of All Timetables, The Daily Recurrence Pattern, The Weekly Recurrence Pattern, The Monthly Recurrence Pattern, The Relative Monthly Recurrence Pattern, The Yearly Recurrence Pattern, The Relative Yearly Recurrence Pattern

Constraint rules enable you to set minimum and maximum values for the number of instances of a role or set of roles based on a timetable. You should use the minimum value as a way to ensure that your application can meet its SLAs when you can predict changes in your application's workload. You should use the maximum value as a way to control the costs of running your application in Microsoft Azure.

The following table shows some example constraint rules.

Rule

Timetable

Target

Range

Rank

Rule #1

Every Friday

Web role A

Minimum = 2

Maximum = 3

2

Rule #2

Every last Friday of the month

Web role A

Minimum = 3

Maximum = 8

1

Rule #3

Every Sunday between 21:00 and 23:59

Worker role A

Minimum = 3

Maximum = 8

3

In the examples shown in the previous table, rules #1 and #2 will overlap on the last Friday of the month. In the situation where two or more rules overlap, the Autoscaling Application Block uses the rank of the rules to determine which rule takes precedence. In this example, rule #2 takes precedence over rule #1 if it is the last Friday of the month.

You should always have at least one constraint rule with a rank of one for every target that you plan to scale using the Autoscaling Application Block. This ensures that there are always minimum and maximum values in force so that a reactive rule cannot remove all your instances or keep adding more and more instances.

Note

If there is no constraint rule active for a role when the rule evaluation process runs, and a reactive rule tries to change the number of role instances, then the blog will log a message that it cannot perform any scaling actions on the role (Event ID 1019). The block will not change the current number of role instances.

You can set the minimum and maximum range values in a rule to the same number if you want to fix the number of role instances.

The Autoscaling Application Block loads constraint rules from an XML file stored in the location specified by the block's configuration. See the topic "Entering Configuration Information" for more details.

Specifying Timetables

A constraint rule can include a timetable that specifies when the rule is active. You specify the timetable using recurrence patterns. The following sections describe the different types of recurrence patterns you can use to specify timetables in the Autoscaling Application Block.

The https://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules namespace defines the rule and timetable elements. See the topic "Rules Schema Description" for more information.

Note

If you have installed the Autoscaling Application Block in your Visual Studio project by using NuGet, you can find the AutoscalingRules.xsd schema file in the root folder of the project. You can use this schema file with many XML editors to provide IntelliSense and automatic validation.

Common Features of All Timetables

All timetable definitions include the following information:

  • Start time. The time of day when the rule becomes active.
  • Duration. The period of time that the rule remains active after the start time.
  • UTC offset. The number of hours that the start time is offset from UTC.
  • Start date. An optional setting. The date when the rule first becomes active.
  • End date. An optional setting. The date when the rule ceases to be active.

The Autoscaling Application Block does not take into account any seasonal time changes such as daylight saving time. It simply adjusts the start time by the number of hours specified by the UTC offset. You may want to modify your rules if, in your time zone, you change to or from daylight saving time.

The optional values, start date and end date, enable you to specify a range of dates for your rule to remain active. If you specify just a start date, then your rule will be active at the times you specify, from that date forward. If you specify just an end date, then your rule will be active at the times you specify up to and including that date. If you specify both a start date and an end date, then your rule will be active between those dates.

The Daily Recurrence Pattern

The following snippet shows an example of a rule with a daily recurrence pattern.

<rule name="Daily Rule" description="Example daily rule" rank="10" enabled="true">
  <timetable startTime="09:00:00" duration="02:00:00" startDate="2011-11-15">
    <daily/>
  </timetable>
</rule>

The startTime attribute specifies the time when the rule becomes active and the duration attribute specifies how long the rule remains active. The empty daily element indicates that this rule uses a daily recurrence pattern.

The example above shows a rule that is active every day between 09:00 and 11:00 starting on November 15, 2011.

The Weekly Recurrence Pattern

The following snippet shows an example of a rule with a weekly recurrence pattern.

<rule name="Weekly Rule" description="Example weekly rule" rank="10" 
  enabled="true">
  <timetable startTime="06:00:00" duration="12:00:00" endDate="2011-12-15" 
    utcOffset="-08:00">
    <weekly days="Saturday Sunday" />
  </timetable>
</rule>

The weekly element indicates that this rule uses a weekly recurrence pattern. The days attribute identifies the days of the week that the rule is active.

The example above shows a rule that is active on Saturdays and Sundays between 06:00 and 18:00 in a time zone offset by minus eight hours from UTC. The rule is active until December 15, 2011.

The Monthly Recurrence Pattern

The following snippet shows an example of a rule with a monthly recurrence pattern.

<rule name="Monthly Rule" description="Example monthly rule" rank="10" 
  enabled="true">
  <timetable startTime="02:00:00" duration="03:00:00"
    startDate="2011-11-15" endDate="2011-12-15">
    <monthly dayOfMonth="2"/>
  </timetable>
</rule>

The monthly element indicates that this rule uses a fixed-day monthly recurrence pattern. The dayOfMonth attribute identifies the fixed day of the month that the rule is active.

Note

Be careful if you use a day that is greater than 28 because the rule will not fire every month. Use a relative monthly recurrence rule if you want a rule to be active on the last day of the month.

The example above shows a rule that is active on the second day of every month between 02:00 and 05:00. The rule is active between November 15, 2011 and December 15, 2011.

The Relative Monthly Recurrence Pattern

The following snippet shows an example of a rule with a relative-day monthly recurrence pattern.

<rule name="Relative Monthly Rule" description="Example relative monthly rule" 
  rank="10" enabled="true">
  <timetable startTime="22:00:00" duration="03:00:00">
    <relativeMonthly dayOfWeek="Friday" position="Last"/>
  </timetable>
</rule>

The relativeMonthly element indicates that this rule uses a relative-day monthly recurrence pattern. The dayOfWeek attribute identifies the name of the day that the rule is active. The position attribute specifies the occurrence of the day. Possible values are: First, Second, Third, Fourth, and Last.

The example above shows a rule that is active on the last Friday of every month between 22:00 and 01:00 on the following day.

The Yearly Recurrence Pattern

The following snippet shows an example of a rule with a yearly recurrence pattern.

<rule name="Yearly Rule" description="Example yearly rule" rank="10" 
  enabled="true">
  <timetable startTime="00:00:00" duration="12:00:00">
    <yearly dayOfMonth="15" month="3" />
  </timetable>
</rule>

The yearly element indicates that this rule uses a yearly recurrence pattern. The dayOfMonth attribute identifies the day of the month that the rule is active and the month attribute identifies the month that the rule is active.

The example above shows a rule that is active on March 15 every year between 00:00 and 12:00.

The Relative Yearly Recurrence Pattern

The following snippet shows an example of a rule with a yearly recurrence pattern.

<rule name="Relative Yearly Rule" description="Example relative yearly rule" 
  rank="10" enabled="true">
  <timetable startTime="21:00:00" duration="12:00:00">
    <relativeYearly dayOfWeek="Monday" month="1" position="Second"/>
  </timetable>
</rule>

The relativeYearly element indicates that this rule uses a relative yearly recurrence pattern. The dayOfWeek attribute identifies the day of the week that the rule is active, the month attribute identifies the month that the rule is active, and the position attribute indicates the occurrence of the day that the rule is active.

The example above shows a rule that is active on the second Monday in January every year between 21:00 and 09:00 the following day.

Next Topic | Previous Topic | Home

Last built: June 7, 2012