This topic describes how to use the traffic distribution feature to control the percentage of client requests that are forwarded to endpoint groups in different regions.

Scenarios

A company deploys a service on servers in the China (Beijing) and China (Shanghai) regions. The TCP protocol is used and port 80 is open. The clients are located in the China (Beijing) region. The company specifies China (Beijing) as the acceleration region and creates an endpoint group in the China (Beijing) and China (Shanghai) regions in the Global Accelerator (GA) console. By default, GA forwards all requests from clients in the China (Beijing) region to the servers in the endpoint group that is deployed in the China (Beijing) region. The endpoint group in the China (Shanghai) region serves as the secondary endpoint group. If the endpoint group in the China (Beijing) region is abnormal, client requests are forwarded to the endpoint group in the China (Shanghai) region. Due to business development, the company wants to forward requests from clients in the China (Beijing) region to the servers in the endpoint group that is deployed in the China (Shanghai) region. The company also wants to ensure that clients can access the service as normal during the switchover process.

You can change the traffic distribution ratio for the endpoint group in the China (Beijing) region. For example, you can change the traffic distribution ratio from 100% to 50%. This way, 50% of requests from clients in the China (Beijing) region are forwarded to the servers in the endpoint group in the China (Shanghai) region. If clients can access the service as normal, change the traffic distribution ratio to 0%. This way, all requests from clients in the China (Beijing) region are forwarded to the servers in the endpoint group in the China (Shanghai) region. This ensures the seamless switchover of traffic from clients in the China (Beijing) region.

Scenarios

Prerequisites

A GA instance and a basic bandwidth plan are purchased. For more information, see Select and purchase GA resources.

Procedure

Procedure

Step 1: Deploy servers

The servers in this example run the Alibaba Cloud Linux 3.2104 64-bit operating system. The command that is used to run the test may vary based on the operating system. For more information, refer to the user guide of the operating system.

  1. Deploy servers in the China (Beijing) and China (Shanghai) regions, and specify the TCP protocol and open port 80 for the servers.
  2. Open the command prompt on a client in the China (Beijing) region and run the curl command to access the servers in the China (Beijing) region and the China (Shanghai) region.
    curl <Origin server IP address>
    The following figures show the region information that is returned.
    Figure 1. Access a server in the China (Beijing) region
    Access a server in the China (Beijing) region
    Figure 2. Access a server in the China (Shanghai) region
    Access a server in the China (Shanghai) region

Step 2: Add an acceleration region

  1. Log on to the Global Accelerator console.
  2. On the Instances page, find the GA instance that you created and click its ID.
  3. Click the Acceleration Areas tab and then click Add Region on the China North tab.
  4. In the Add Acceleration Area dialog box, set the following parameters and click OK.
    Parameter Description
    Region Select the region where the users that require the acceleration service are located.

    In this example, China (Beijing) is selected.

    Bandwidth Allocate bandwidth to the region.

    In this example, 2 Mbit/s of bandwidth is allocated.

    Internet Protocol Select the Internet protocol that is used by the users to connect to GA.

    In this example, IPv4 is selected.

    After you add the region, the system assigns an accelerated IP address to the region that is added to the GA instance. This accelerated IP address is used to accelerate data transfer from users in the specified region to the specified backend servers through GA. China (Beijing) acceleration region

Step 3: Add a listener and an endpoint group

  1. On the instance details page, click the Listeners tab and then click Add Listener.
  2. On the Configure Listener & Protocol wizard page, specify the following listener information and click Next.
    Listener
    Parameter Description
    Listener Name Enter a name for the listener.

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

    Protocol Select the protocol of the listener.

    In this example, TCP is selected.

    Port Number Specify a listener port. The port is used to receive and forward requests to endpoints. Valid values: 1 to 65499.

    In this example, the value is set to 80.

    Client Affinity Specify whether to enable client affinity. If client affinity is enabled, requests from the same client are forwarded to the same endpoint when the client connects to a stateful application.

    In this example, Disable is selected.

  3. On the Configure Endpoint Group wizard page, set the following parameters for the endpoint group that is deployed in the China (Beijing) region.
    Endpoint group in the China (Beijing) region
    Parameter Description
    Endpoint Group Name Enter a name for the endpoint group.
    Region Select the region where you want to create the endpoint group. The server that the clients want to access must be deployed in the specified region.

    In this example, China (Beijing) is selected.

    Traffic Distribution Ratio Set the traffic distribution ratio for the endpoint group. Unit: %. Valid values: 0 to 100.

    In this example, the default value 100 is used.

    Note You can set Traffic Distribution Ratio only if you create an endpoint group for a TCP or UDP listener.
    Backend Service Specify whether the backend service is deployed on Alibaba Cloud.

    In this example, Off Alibaba Cloud is selected.

    Preserve Client IP Specify whether to preserve client IP addresses. After you enable this feature, backend servers can retrieve client IP addresses.

    In this example, client IP address preservation is disabled.

    Endpoint Endpoints are destinations of client requests. To add an endpoint, specify the following parameters:
    • Backend Service Type: In this example, Custom IP Address is selected.
    • Backend Service: Enter the public IP address of the backend server.
    • Weight: Enter the weight of the endpoint. Valid values: 0 to 255. GA distributes network traffic to endpoints based on their weights.
    Notice If the weight of an endpoint is set to 0, GA stops distributing network traffic to the endpoint. Proceed with caution.
    Health Check Specify whether to enable or disable the health check feature.

    After you enable this feature, you can use health checks to check the status of endpoints. For more information about how to configure health checks, see Enable and manage health checks.

    In this example, the health check feature is enabled.

  4. Click + Add Endpoint Group to add another endpoint group in the China (Shanghai) region, configure the endpoint group based on the parameter description in Substep 3, and then click Next.
    Endpoint group in the China (Shanghai) region
  5. On the Confirm wizard page, confirm the configurations of the listener and endpoint, and then click Submit.

Step 4: Test the traffic distribution result

In this example, the following command is used to simulate client requests to test the traffic distribution result.
echo > curl.txt; for ((i=0;i<<Number of requests>;i++)); do curl -s <Accelerated IP address> >> curl.txt; done; beijing_count=`grep Beijing curl.txt | wc -l`;echo "Beijing count: ${beijing_count}";shanghai_count=`grep Shanghai curl.txt | wc -l`;echo "shanghai count: ${shanghai_count}";
Parameter description:
  • Number of requests: The number of client requests that are simulated. For example, if you set Number of requests to 100, 100 requests are sent from the client.
  • Accelerated IP address: The accelerated IP address assigned by GA.
  • Beijing count: The number of requests processed by the servers in the China (Beijing) region.
  • Shanghai count: The number of requests processed by the servers in the China (Shanghai) region.
  1. Check how client requests are scheduled when you set the traffic distribution ratio to 100% for the endpoint group that is assigned a higher priority in the China (Beijing) region.
    Open the command prompt on a client in the China (Beijing) region and send 100 requests. Then, check the number of requests that are processed by the servers in the China (Beijing) region and the number of requests that are processed by the servers in the China (Shanghai) region. Set traffic distribution ratio to 100%

    The result indicates that all requests from the client in the China (Beijing) region are forwarded to the endpoint group in the China (Beijing) region.

  2. Check how client requests are scheduled when you set the traffic distribution ratio to 50% for the endpoint group that is assigned a higher priority in the China (Beijing) region.
    1. Change the traffic distribution ratio to 50% for the endpoint group in the China (Beijing) region. For more information, see Set the traffic distribution ratio for an endpoint group.
    2. Send 100 requests from a client in the China (Beijing) region and check the number of requests that are processed by the servers in the China (Beijing) region and the number of requests that are processed by the servers in the China (Shanghai) region.
      Set traffic distribution ratio to 50%

      The result indicates that each endpoint group in the China (Beijing) region and the China (Shanghai) region processes 50 requests.

  3. Check how client requests are scheduled when you set the traffic distribution ratio to 0% for the endpoint group that is assigned a higher priority in the China (Beijing) region.
    1. Change the traffic distribution ratio to 0% for the endpoint group in the China (Beijing) region. For more information, see Set the traffic distribution ratio for an endpoint group.
    2. Send 100 requests from a client in the China (Beijing) region and check the number of requests that are processed by the servers in the China (Beijing) region and the number of requests that are processed by the servers in the China (Shanghai) region.
      Set traffic distribution ratio to 0%

      The result indicates that all requests from the client in the China (Beijing) region are forwarded to and processed by the servers in the China (Shanghai) region.