Auto-scale ECI instances with the ALB QPS per server metric

Updated at:
Copy as MD

Auto Scaling can use the ALB QPS per Backend Server metric from an Application Load Balancer (ALB) server group to trigger scaling activities that automatically add or remove ECS or ECI instances.

Key concepts

  • Application Load Balancer (ALB): An application-layer load balancing service for HTTP, HTTPS, and QUIC traffic with high elasticity and large-scale processing capacity. What is Application Load Balancer?.

  • Query per Second (QPS): The number of HTTP/HTTPS requests an ALB instance processes per second (Layer 7 listeners only). QPS per backend server = total ALB QPS / number of backend instances in the server group.

Use cases

When your ALB distributes client traffic to backend ECS or ECI instances, a sudden QPS surge requires rapid scale-out to maintain performance and stability.

Configure an event-triggered task based on the QPS per backend server metric to automatically trigger scaling activities:

  • When QPS per backend server exceeds the threshold, scale-out adds instances to reduce per-instance load and improve response time.

  • When QPS per backend server falls below the threshold, scale-in removes instances to reduce costs.

Prerequisites

Step 1: Configure an Application Load Balancer

  1. Create an Application Load Balancer (ALB) instance.

    Create and manage ALB instances.

    Key parameters:

    Parameter

    Description

    Example

    Instance Name

    Enter a name for the instance.

    alb-qps-instance

    VPC

    Select the VPC for the instance.

    vpc-test****-001

    Zone

    Select a zone and a vSwitch.

    Note

    ALB supports multi-zone deployment. Select at least two zones for high availability when available.

    • Zone: Hangzhou Zone G and Hangzhou Zone H

    • vSwitch: vsw-test003 and vsw-test002

  2. Create an ALB server group.

    Create and manage server groups.

    Key parameters:

    Parameter

    Description

    Example

    Server Group Type

    Select a server group type. Select Server to add ECI instances as backend servers.

    Server

    Server Group Name

    Enter a name for the server group.

    alb-qps-servergroup

    VPC

    Select a VPC. Only servers in this VPC can join the server group.

    Important

    Select the same VPC that you used for the ALB instance in Step 1.

    vpc-test****-001

  3. Configure a listener.

    1. In the left navigation bar, select Application Load Balancer (ALB) > Instance.

    2. On the Instance page, find the ALB instance (alb-qps-instance) and click Create Listener in the Actions column.

    3. In the Configure Listener wizard, set Listener Port to 80, keep the default settings for other parameters, and then click Next.

      Note

      This example sets Listener Port to 80. Use a different port if needed.

    4. In the Select Server Group wizard, select the server group that you created in Substep 2 (alb-qps-servergroup) from the Server Group list, and then click Next.

    5. In the Configuration Review wizard, confirm the settings and click OK. Then, click OK.

  4. After you complete the configuration, click the Instance Details tab to obtain the Elastic IP Address (EIP) of the ALB instance. On the Basic Information tab, you can view that the IP Mode is Fixed IP and an Elastic IP Address is assigned to each zone. For example, Hangzhou Zone G and Hangzhou Zone H each have a unique EIP.

Step 2: Create a scaling group and associate an ALB server group

This example uses an ECI scaling group. The procedure for ECS scaling groups is similar.

  1. Create a scaling group.

    Create a scaling group. Key parameters (configure others as needed):

    Parameter

    Description

    Example

    Scaling Group Name

    Enter a name for the scaling group.

    alb-qps-scalinggroup

    Type

    The instance type for computing power in the scaling group.

    ECI

    Instance Configuration Source

    The configuration used to create instances.

    Create from Scratch

    Minimum Number of Instances

    Auto Scaling adds instances when the count falls below this value.

    1

    Maximum Number of Instances

    Auto Scaling removes instances when the count exceeds this value.

    5

    VPC

    Select the same VPC as the ALB instance.

    vpc-test****-001

    vSwitch

    Select the same vSwitches as the ALB instance.

    vsw-test003 and vsw-test002

    Associate ALB and NLB Server Groups

    Select the ALB server group that you created in Step 1. Set Port to 80.

    • Server group: sgp-****/alb-qps-servergroup

    • Port: 80

  2. Create and enable a scaling configuration.

    Create a scaling configuration for ECI instances. Key parameters (configure others as needed):

    Parameter

    Description

    Example

    Container Group Configuration

    Select vCPU and memory specifications for the container group.

    • CPU: 2 vCPU

    • Memory: 4 GiB

    Container Configuration

    Select a container image and image version.

    • Container Image: registry-vpc.cn-hangzhou.aliyuncs.com/eci_open/nginx

    • Image Version: latest

  3. Enable the scaling group.

    Enable or disable a scaling group.

    Note

    Enabling the scaling group triggers a scale-out that creates one ECI instance (minimum is set to 1).

  4. Verify that the ECI instance and its container are running in the scaling group.

  5. Access the EIP of the ALB instance from Step 1 to confirm that the nginx service is accessible. The default nginx welcome page (Welcome to nginx!) indicates successful deployment.

Step 3: Configure a QPS-based event-triggered task

  1. Log on to the Auto Scaling console.

  2. Create scaling rules.

    Create two simple scaling rules: Add1 (adds one instance) and Reduce1 (removes one instance). Manage scaling rules.

  3. Create event-triggered tasks.

    1. On the Scaling Groups page, find the scaling group (alb-qps-scalinggroup) and click View Details in the Actions column.

    2. Select Scaling Rules and Event-triggered Tasks > Event-triggered Tasks > Event-triggered Tasks (System), and click Create Event-Triggered Task.

      Create two event-triggered tasks: Alarm1 (associated with Add1) and Alarm2 (associated with Reduce1). Manage event-triggered tasks.

      • Event-triggered task (Alarm1): For Metric Name, select (ALB) QPS per Backend Server. Set the condition to Average >= 100 times/s.

        Note

        QPS per backend server = Total QPS / Number of backend servers

        For other parameters, set Monitoring Type to System Monitoring and Statistical Period to 1 minute. Set the task to trigger an alarm after 3 consecutive occurrences. For Effective Period, select Not Set. For Scaling Rule, select Add1.

      • Event-triggered task (Alarm2): For Metric Name, select (ALB) QPS per Backend Server. Set the condition to Average < 50 times/s, set Statistical Period to 1 minute, and set the task to trigger an alarm after 3 consecutive occurrences. For Scaling Rule, select Reduce1.

Verify the QPS monitoring

Use a stress testing tool (Apache JMeter, ApacheBench, or wrk) to send 500 QPS to the ALB instance EIP from Step 1. Observe the results on the Monitoring page in the Auto Scaling console:

When QPS exceeds the alarm threshold, the event-triggered task triggers scale-out. Auto Scaling adds ECI instances one at a time, reducing per-instance load until QPS per backend server falls.