Updated on 2023-12-01 GMT+08:00

Configuring Weighted Routing

Scenarios

A large website is generally deployed on multiple servers. To balance the load of each server, you can use weights to control the proportion of requests to each server.

The DNS service allows you to set weights to record sets to route the requests to different servers based on the specified weights.

When your website has multiple servers and each server has an independent IP address, consider weighted routing to distribute requests to different servers proportionally.

For example, you have a website deployed on three servers. The domain name of your website is example.com, and the IP addresses of the three servers are 192.168.1.1, 192.168.1.2, and 192.168.1.3.

  • If you add an A record set and set its value to the three IP addresses, with no weights set to the IP addresses, requests are randomly routed to an IP address.

    For details, see How Is a Domain Name Resolved When a Record Set Has Multiple Values?

  • You add three A record sets, with each having an IP address as its value.

    In this case, you can set different weights for the three record sets. In this way, requests are routed to each server based on the specified weight.

Weighted routing can better distribute requests and balance server load. You can perform the operations provided in this section to set the weights.

Constraints

You can configure weights for up to 20 record sets of the same domain name and line.

Preparations

There are three web servers. Three A record sets are required, with the value of each set to the IP address of a web server. You can set different weights to control the proportion of requests to each server.

Table 1 Weight setting plans

Plan

Domain Name

Record Set Type

Line Type

Value

Weight

Description

1

example.com

A

Default

192.168.1.1

1

Requests are evenly distributed to three servers (the proportion of requests is 1:1:1).

192.168.1.2

1

192.168.1.3

1

2

example.com

A

Default

192.168.1.1

2

Requests are distributed to three servers in a proportion of 2:3:1.

For example, if there are six requests, two are routed to the server whose IP address is 192.168.1.1, three are routed to the server whose IP address is 192.168.1.2, and one is routed to the server whose IP address is 192.168.1.3.

192.168.1.2

3

192.168.1.3

1

Prerequisites

The domain name of the website has been hosted on the DNS service.

Procedure

The following describes how to add three A record sets to domain name example.com, and the weight ratio of the three record sets is 1:1:1.

  1. Go to the Public Zones page.
  2. On the Public Zones page, click the domain name (example.com) of the public zone.

    The Record Sets page is displayed.

  3. Click Add Record Set.
    Figure 1 Setting weights
  4. Configure the parameters as follows:
    • Name: Leave this parameter blank. The DNS service automatically considers example.com as the name, and requests are routed to example.com.
    • Type: Set it to A – Map domains to IPv4 addresses.
    • Line Type: Select Default.
    • Value: Set it to 192.168.1.1, the IP address of a web server.
    • Weight: Set it to 1.
  5. Click OK.
  6. Repeat 3 to 5 to add the second and third record sets.

    Set the record set value to 192.168.1.2 and 192.168.1.3, respectively.

    Requests will be evenly distributed to the three servers.