Load Balancing
With the Arvancloud CDN load balancing settings, you can evenly distribute traffic among several servers that contain the same resources and data. This way, requests for these resources can be answered by several servers instead of one, which increases redundancy and reliability.
The new generation of Arvancloud load balancing, with geographic traffic steering and Active Health Check, sends requests to healthy, responsive pools associated with each country, improving website performance and the end-user experience.
This guide explains how to enable and configure load balancing.
Basic Concepts
This section covers the basic concepts of the Arvancloud CDN load balancing feature.
-
Pool
A pool is a set of host servers, each identified by its IP or hostname. If you are familiar with DNS concepts, think of a pool as a record set, except that Arvancloud load balancing only returns addresses that are considered healthy. For each pool, you can define rules for health checks and checking the health of the pool's servers.
-
Monitoring
At regular, configurable intervals (called the check interval), each monitor evaluates the pool's health by looking for specific status codes or response bodies, and when a pool becomes unhealthy, the load balancer automatically takes that pool out of rotation. Monitoring settings let you get notified by email and take the server out of service until the error is fixed. These conditions can be set based on protocol, sent headers, and geographic region.
-
Load Balancer
Each load balancer distributes traffic among origin pools based on pool health and its traffic steering. Load balancing can be configured in two modes: active-active and active-passive. In active-active mode, traffic is distributed evenly among all healthy pools based on geographic location, and no traffic is sent to an unhealthy pool. In active-passive mode, traffic is sent to only one healthy pool based on the specified priority, and the other healthy pools are considered fallback destinations; when the first pool doesn't respond, traffic is sent to the next pool. If no healthy pool is available, traffic is sent to the default pool.
-
Traffic Steering
When requests reach your load balancer, it distributes them among your servers and pools based on three parameters:
- Pool health: Traffic steering starts by checking the health of pools and servers.
- Traffic steering: The policy set for sending traffic to the available pools.
- Server steering: The policy set in each pool for distributing traffic among that pool's servers.
Geographic steering directs each country's traffic to the associated pool, and when a pool or server becomes unhealthy, the load balancer and pools redistribute traffic based on these policies. This is very important when you want visitors to reach the nearest host server to improve website performance.
-
Unhealthy Pool or Server
The advantage of this dynamic generation of load balancing is that traffic is distributed among servers that are able to respond to requests. This is determined and checked by a set of monitors, pools, and health checks.
The goal of each health check is to compare the resources' status with their previous status; it fails when the following conditions hold:
- The server's response time exceeds the response timeout set in the monitoring settings.
- The server doesn't return the expected status code or response body specified in the monitoring settings.
Each pool has one of three statuses: healthy, warning, or unhealthy. When all servers respond and meet the monitoring conditions, the pool's status is healthy; when the number of failing servers is greater than or equal to the specified failure threshold, the pool's status becomes error, and traffic is sent to the default pool. If the number of failing servers is below the threshold, the pool's status changes to warning.
Configuring Load Balancing
When you decide to start using load balancing, you need to do the following steps:
- Manage the load balancer
- Manage pools
- Steer traffic
- Manage monitoring
Step 1: Manage the Load Balancer
You can group several servers into a pool of origin servers, and group several pools into a new load balancer. In the load balancer settings, you can specify which geographic regions' traffic is sent to which pool, and continuously keep track of each pool's status with monitoring.
To create a new load balancer, go to CDN > Load Balancing, and on the new page click New Load Balancer.
On the page that opens, you can specify the name, description, and load balancing method.
In the active-active method, incoming traffic is distributed randomly among all healthy pools based on the configured geographic location. If one of the pools is detected as failing based on the monitoring settings, traffic is distributed among the other healthy pools.
The active-passive method sends incoming traffic to the first healthy pool in the list of origin server pools. If monitoring detects that pool as failing, traffic is sent to the next healthy pool.
If no healthy pool is available, traffic is sent to the default pool.
Step 2: Manage Origin Server Pools
After creating a new load balancer and confirming the load balancing method, you need to create origin server pools. You can create a cluster or pool by grouping your origin server addresses and clicking Create Pool.
On the page that opens, specify the name and description of your pool, then specify the traffic management method and whether origin server error handling is enabled.
The load balancing methods for balancing server traffic load are Round Robin and Client IP Hash. In Round Robin, user requests are distributed in turn among the different servers, according to their weights; in Client IP Hash, based on the user's IP, their requests are sent to the server they connected to on their first request.
With the Origin Server Error Handling feature, if your subdomain is connected to more than one server, requests that result in errors such as Connection Refused or Connection Error are automatically sent to the next server. In this case, the origin server's error is not shown to the user.
Using Add New Server, you can add the pool's servers to the list of servers. The server address is specified by IP, and you can set each server's weight and port. Also, when your website or application needs custom routing (CNAME Setup, or custom hosts such as S3 and a Cloud Container domain), you can choose the Host header for each server.
The protocol for connecting to the origin server can be HTTP or HTTPS. If you choose Default, the panel's default setting (which can be changed in HTTPS Settings) applies. If you choose Automatic, the protocol used to connect to the origin server for each request matches the protocol the visitor used to connect to the CDN.
After adding the new servers and confirming the list of servers, you can save the origin pool settings. With several pools, you can set the pools' priorities and enable or disable pools when needed. When a pool is disabled, no traffic is sent to it.
Note that the default pool cannot be disabled.
Step 3: Traffic Steering
In this step, by selecting one or more geographic regions for each pool, you can send those regions' traffic to the related server pool. If no pool is selected for a geographic region, its traffic is sent to the default pool.
Step 4: Monitoring
In the last step, you can check the pools' status and click Edit Monitoring to edit each pool's monitoring conditions on a new page. With the Active Health Check feature of the Arvancloud CDN, you can automatically and in real time measure the health of the website's origin servers and their ability to respond to user requests. This way, when a problem occurs on any origin server in the load balancing clusters, you can find out about it and take the necessary actions to fix it.
By monitoring the origin servers in a cluster in real time, this feature detects any change in their status and performs predefined actions for them. Also, when a problem occurs on the servers, Active Health Check can, depending on its settings, notify you by email or remove that server from the load balancer's list of origin servers, and use it again in load balancing once the server's status improves.
In this section, you can monitor servers based on protocol, domain path, request method and type, port, expected response or status code, and sent headers and their values. You can also take Active Health Check monitoring to the highest level of customization by setting checks from geographic regions and specifying the monitoring level, response timeout, and check interval.
Each pool's status is determined by its monitoring. If the number of failing servers in a pool is greater than or equal to the failure threshold, the pool's status is shown as Error, and no traffic is sent to it. If the number of failing servers is below the threshold, the pool's status is shown as Warning.
At the Off monitoring level, Arvancloud CDN edge servers send no requests to check the origin server's health. In Notify mode, the origin servers' health is checked and any problem is reported to you by email; at the Notify and Remove from List level, after the email notification, the problematic server is removed from the load balancer's list of servers, and after the problem is fixed, the server can return to the list.
Active Health Check actively probes the servers. By default, this process runs at an interval of at least 30 seconds, with three retries to make sure of the detection. The time from detecting the server's status to applying the change in the settings is on average between 1 and 5 minutes.
When both servers are in the same pool, you can use Passive Health Check. In this method, when an error occurs on the current server, all requests are moved to the other server in the pool, assuming the second server is healthy and ready.
So, if you need failover without delay and want the switch to happen immediately after an error is detected, it is recommended to use Passive Health Check. In this case, monitoring doesn't use Active Health Check, which has a delay, and the workload moves quickly to the other server.
Checking from Geographic Regions
In the Check from Geographic Region section, you can specify a different monitoring level for each geographic region. This way, if a problem is found after Arvancloud CDN edge servers in that region check the health of the website's origin server, the action appropriate to the specified monitoring level is taken.
Note that HTTP requests are sent with the following User Agent:
User Agent: "Arvancloud-AHC/0.1"
Also remember that the source IPs sending origin server monitoring requests are the same Arvancloud CDN edge server IPs, which you need to whitelist in your server's firewall.