All Products
Search
Document Center

Auto Scaling:Configure a scheduled task

Last Updated:Oct 24, 2024

If your business experiences predictable changes in volume, you can configure scheduled tasks to ensure that enough computing resources are available before peak hours, and then release unused computing resources after peak hours. This helps ensure stable service delivery and maximize cost efficiency.

Design a scheduled scaling solution

Before you create a scheduled task, you must design a scheduled scaling solution.

Solution 1: Trigger scaling at a specific point in time

  • Scenario

    If you can anticipate a sudden spike or drop in resource needs that will occur at a specific point in time, you can schedule automatic scaling to trigger at that point in time.

  • Implementation method

    Create a scheduled task, specify the task trigger time, and then specify the scale-out or scale-in action. For more information, see Create a scheduled task.

  • Example

    If your company hosts promotional events on Double 11, you can increase your computing resources on that day to meet your increased resource needs and ensure smooth operations. This will help maintain the stability of your business during this high-traffic period.

Solution 2: Trigger scaling based on a specific time period

  • Scenario

    If your business experiences predictable fluctuations or if the resource utilization in your cluster fluctuates regularly over time, you can enable automatic scaling to adjust resources accordingly.

  • Implementation method

    When resource utilization in the cluster increases, execute a scheduled task to trigger a scale-out event. When resource utilization in the cluster decreases, execute a scheduled task to trigger a scale-in event. For more information, see Create a scheduled task.

  • Example

    For example, your cluster experiences an increase in traffic every evening at 19:00 and a decrease every morning at 01:00. To handle these fluctuations in business demand, you can create the following scheduled tasks:

    • Increased traffic: Enable a scheduled task to increase the number of service replicas every evening at 19:00. This improves the capability of the cluster to handle the increased traffic.

    • Decreased traffic: Enable a scheduled task to decrease the number of service replicas every morning at 01:00. This improves resource utilization and maximizes cost efficiency.

Go to the Scheduled Tasks page

You can manage scheduled tasks only on the Scheduled Tasks page. To go to the Scheduled Tasks page, perform the following steps:

Go to the Scheduled Tasks page

  1. Log on to the Auto Scaling console.

  2. In the left-side navigation pane, click Scaling Groups.

  3. In the top navigation bar, select a region.

  4. On the Scaling Groups page, find the scaling group that you want to use and click its name to go to the scaling group details page.

  5. Choose Scaling Rules and Event-triggered Tasks > Scheduled Tasks.

    image

Create a scheduled task

After you design a scheduled scaling solution, you can proceed to create a scheduled task that implements the solution. To create a scheduled task, perform the following steps:

Important

You can create only a limited number of scheduled tasks within an Alibaba Cloud account in a region. To view the quota of scheduled tasks that you can create in a region, go to Quota Center.

  1. On the Scheduled Tasks page, click Create Scheduled Task. In the Create Scheduled Task dialog box, configure the parameters as prompted. The following tables describe the parameters.

    1. Configure the basic information of the scheduled task.

      Parameter

      Description

      Task Name

      The name of the scheduled task that you want to create.

      The name must be 2 to 64 characters in length and can contain letters, digits, periods (.), underscores (_), and hyphens (-). The name must start with a letter or a digit.

      Description

      The description of the scheduled task that you want to create. This parameter is optional.

      The description must be 2 to 200 characters in length. You can use the description to explain the purpose of the task.

    2. Configure the trigger time of the scheduled task.

      Parameter

      Description

      Executed At

      The point in time at which you want to execute the scheduled task.

      • If no value is specified for the Recurrence parameter, the scheduled task is executed only once at the time point specified by the Executed At parameter.

      • If a value is specified for the Recurrence parameter, the scheduled task is executed once at the time point specified by the Executed At parameter and is repeatedly executed based on the cycle specified by the Recurrence parameter.

      Important

      Make sure that the execution time specified for a scheduled task is within 90 days from the date the scheduled task is created or modified. Otherwise, the scheduled task cannot take effect.

      Retry Interval (Seconds)

      The period of time during which Auto Scaling retries the scheduled task upon failures. This parameter is optional. Valid values: 0 to 1800. Unit: Seconds.

      Recurrence

      The cycle during which you want to repeatedly execute the scheduled task. This parameter is optional. Valid values: Not Set, By Day, By Week, By Month, and Cron Expression.

      Expired At

      The end time of the cycle during which you want to repeatedly execute the scheduled task. This parameter is available if you set the Recurrence parameter to By Day, By Week, By Month, or Cron Expression. The first point of time at which the scheduled task is executed must be earlier than the end time of the cycle.

      Cron expressions

      When you create a scheduled task in the Auto Scaling console, you can set the Recurrence parameter to Cron Expression.

      A cron expression is a string that represents a schedule. The string consists of multiple fields that are separated by spaces and describe individual details of the schedule. Auto Scaling supports cron expressions that consist of five fields in the X X X X X format. X is a placeholder for a field. The fields in the cron expression represent minutes, hours, day of month, month, and day of week in sequence. Each field can be a definite value or a special character that has a logical meaning.

      When you configure a cron expression for a scheduled task, take note of the following items:

      • Cron expressions are in UTC+0. When you configure a cron expression, you must convert the local time to UTC+0. For example, the time zone in China is in UTC+8. If you are in China and you want to execute your scheduled task at 20:00:00 local time every day, you must subtract 8 hours from 20:00:00. In this case, you must set the cron expression to 0 12 * * ?.

      • A scheduled task that has a specified cron expression can be executed only once every five minutes.

      • The first point in time at which a scheduled task that has a specified cron is executed must be earlier than the end time of the cycle specified by the Recurrence parameter for the scheduled task. Otherwise, an error is reported.

      Table 1. Fields

      Field

      Required

      Value range

      Special character

      Minute

      Yes

      0 to 59

      , - / *

      Hour

      Yes

      0 to 23

      , - / *

      Day

      Yes

      1 to 31

      , - / * ? L W

      Month

      Yes

      1 to 12

      , - / *

      Day of week

      Yes

      1 to 7. The value for Sunday is 7.

      , - * ? / L #

      Table 2 Special characters

      Special character

      Description

      Cron expression

      *

      All valid field values

      In the Month field, an asterisk (*) indicates every month. In the Day of week field, an asterisk (*) indicates every day of the week.

      ,

      Enumerated values

      In the Minute field, 5,20 indicates the 5th and 20th minutes.

      -

      Range values

      In the Minute field, 5-20 indicates the range from the 5th to 20th minutes.

      /

      Increments

      In the Minute field, 0/15 indicates every 15 minutes starting from the 0 minute. 3/20 indicates every 20 minutes from the 3rd minute.

      ?

      Unspecified. Only the Day and Day of week fields support this character.

      Note

      To prevent calculation conflicts after you specify the Day field or Day of week field, you must specify a question mark (?) in the unspecified field.

      In the Day field, ? indicates that no specific day of the month is specified. In the Day of week field, ? indicates that no specific day of the week is specified. For example, 15 10 15 * ? in UTC+0 indicates that the scheduled task is executed at 10:15:00 on the 15th day of each month, regardless of the day of the week.

      L

      L, the first letter of Last, indicates the last day of a specific period. Only the Day and Day of week fields support this character.

      Note

      To prevent logic errors, do not specify a list or range when you use the L character.

      • In the Day field, L indicates the last day of a month. In the Day of week field, L indicates the last day of a week.

      • L can be preceded by a value. For example, 6L in the Day of week field indicates the last Saturday of the month.

      W

      The weekday that is nearest to the specified day of the month. The weekday that the W character indicates is always in the same month as the specified day of the month. LW indicates the last weekday of the specified month.

      If 5W is specified in the Day field and the 5th day of the month is a Saturday, the task is triggered on the nearest weekday which is Friday, the 4th day of the month. If the 5th day of the month is a Sunday, the scheduled task is triggered on the nearest weekday which is Monday, the 6th day of the month. If the 5th day of the month is a weekday, the scheduled task is triggered on the 5th day of the month.

      #

      A specific day of a specific week every month. Only the Day of week field supports this character. Valid values: 1 to 5.

      In the Day of week field, 4#2 indicates the 2nd Thursday of a month.

      Table 4 Examples

      The following table provides examples of cron expressions in UTC+0. These cron expressions have different meanings. When you configure a cron expression, you must convert the local time to UTC+0.

      Cron expression

      Description

      15 10 ? * *

      Executes the scheduled task at 10:15:00 every day.

      15 9 * * *

      Executes the scheduled task at 9:15:00 every day.

      0 12 * * ?

      Executes the scheduled task at 12:00:00 every day.

      0 10,14,16 * * ?

      Executes the scheduled task at 10:00:00, 14:00:00, and 16:00:00 every day.

      15 10 15 * ?

      Executes the scheduled task at 10:15:00 on the 15th day of every month.

      15 10 L * ?

      Executes the scheduled task at 10:15:00 on the last day of every month.

      15 10 ? * 6L

      Executes the scheduled task at 10:15:00 on the last Saturday of every month.

      15 10 ? * 6#3

      Executes the scheduled task at 10:15:00 on the 3rd Saturday of every month.

    3. Configure the scaling method of the scheduled task.

      Note

      Auto Scaling allows you to configure the following scaling methods in scheduled tasks:

      • Select Existing Scaling Rule: This method allows the scheduled task to add or remove N instances, add or remove N% instances, or adjust the total number of instances to N in the scaling group.

      • Configure Number of Instances in Scaling Group: This method allows the scheduled task to adjust the lower or upper limit of the scaling group capacity. If you enabled the Expected Number of Instances feature for the scaling group, this method also allows the scheduled task to adjust the expected number of instances in the scaling group.

      Select Existing Scaling Rule

      Parameter

      Description

      Scaling Method

      If you set the Scaling Method parameter to Select Existing Scaling Rule, you must select an existing simple scaling rule.

      Simple Scaling Rule

      This parameter is available only if you set the Scaling Method parameter to Select Existing Scaling Rule. Select an existing simple scaling rule. For more information, see Manage scaling rules or CreateScalingRule.

      Configure Number of Instances in Scaling Group

      Parameter

      Description

      Scaling Method

      If you set the Scaling Method parameter to Configure Number of Instances in Scaling Group, you must specify a new maximum number, minimum number, or expected number of instances.

      Maximum Instances

      The upper limit of the scaling group capacity.

      Minimum Instances

      The lower limit of the scaling group capacity.

      Expected Instances

      The expected size of the scaling group capacity. Auto Scaling adjusts the actual number of instances in the scaling group to maintain the expected size of the scaling group capacity.

  2. Click OK.

Disable a scheduled task

After you create a scheduled task, the scheduled task is enabled by default. If a scheduled task is no longer required, you can disable it. You can disable only scheduled tasks that are enabled.

Procedure

On the Scheduled Tasks tab, find the scheduled task that you want to disable and click Disable in the Actions column.

image

Enable a scheduled task

You can enable a scheduled task that is disabled. After you enable the task, the task can be executed at the specified point in time. You can enable only scheduled tasks that are disabled.

Procedure

On the Scheduled Tasks tab, find the scheduled task that you want to enable and click Enable in the Actions column.

p843898

Modify a scheduled task

If a scheduled task no longer meets your business requirements, you can modify the scheduled task.

Procedure

On the Scheduled Tasks page, find the scheduled task that you want to modify and click Edit in the Actions column. Then, follow the on-screen instructions to modify the scheduled task.

image

For more information, see Create a scheduled task.

Delete a scheduled task

If you no longer require a scheduled task, you can delete the scheduled task.

Procedure

On the Scheduled Tasks page, find the scheduled task that you want to delete and click Delete in the Actions column. Then, follow the on-screen instructions to delete the scheduled task.

image

References