How load balancing works

Tram Ho

The load balancer receives traffic coming from the client and routes requests to its registered targets (such as EC2 instances) in one or more Availability Zones. The load balancer also monitors the health of registered targets and ensures that it only routes requests to healthy targets. When the Load balancer detects an unhealthy target, it will stop routing traffic to that target. Then it continues to route to that target when it detects that target is healthy again.

You configure your load balancer to accept incoming traffic by specifying one or more listeners. A listener is a process that checks for connection requests. It is configured with a protocol and port number for client-to-load balancer connections. Similarly, it is configured with a protocol and port number for connections from load balancer to target.

AWS Elastic Load Balancing supports three types of Load balancer:

  • Application Load Balancers
  • Network Load Balancers
  • Classic Load Balancers

There is an obvious difference between the load balancer types that are set up. With Application load balancer and Network load balancer, you register targets within the target group and route traffic to the target groups. With Classic Load Balancer, you register instances with load balancers.

Availability Zones and Load Balancer Nodes

When you enable the Availability Zone for your Load Balancer, Elastic Load Balancing creates a load balancer node inside the Availability Zone. If you register targets within an Availability Zone but do not enable that Availability zone, those registered targets will not receive traffic. Your load balancer will be most effective when you ensure that each Availability zone has at least one registered target.

AWS encourages activation of multiple Availability zones (with Application Load Balancer, activation of multiple Availability Zones is required). This setting helps ensure that the Load Balancer can continue to route traffic. If an Availability Zone becomes unavailable or has no healthy targets, the Load Balancer can route traffic to other healthy targets in another Availability Zone.

After you disable the Availability zone, targets in that Availability zone are still registered with the Load Balancer. However, despite being registered, the Load Balancer still doesn’t route traffic there.

Cross-Zone Load Balancing

Your Load balancer nodes deliver requests from the client to the registered targets. When cross-zone load balancing is enabled, each Load balancer node will distribute traffic through registered targets in all enabled Availability Zones. When the Cross-Zone Load Balancing is disabled, each Load balancer node only distributes traffic on the targets registered in its Availability Zone.

The following diagram shows the effectiveness of Cross-Zone Load Balancing. There are two Availability Zone enabled, with two targets in Availability Zone A and eight targets in Availability Zone B. Customer submits a request and Amazon Route 53 responds to each request with the IP address of one of the Load balancer nodes . This distributes the traffic so that each Load balancer node receives 50% of the traffic from the clients. Each Load balancer node distributes its traffic on registered targets within its scope.

If Cross-Zone Load Balancing is enabled, each of the 10 targets will receive 10% of the traffic. This is because each load balancing node can route 50% of its client traffic to all 10 targets.

If load balancing is enabled between regions, each of the 10 targets will receive 10% of the traffic. This is because each load balancing node can route 50% of its traffic to all 10 targets.

If cross-zone load balancing is disabled:

  • Each of the two targets in Availability Zone A receives 25% of the traffic.
  • Whereas each of the eight targets of Availability Zone B received only 6.25% of the traffic.

The reason for this is because each Load balancer node can route 50% of client traffic only to targets within its Availability Zone.

With Application Load Balancers, cross-zone load balancing is always enabled.

For Network Load Balancer, cross-zone load balancing is disabled by default. After you create a Network Load Balancer, you can enable or disable ohas cross-zone load balancing at any time.

When you create a Classic Load Balancer, the default for cross-zone load balancing depends on how you create the load balancer. With API or CLI, default cross-zone load balancing is disabled. With the AWS Management Console, the option to enable cross-zone load balancing is selected by default. After you create a Classic Load Balancer, you can enable or disable cross-zone load balancing at any time.

Request Routing

Before the customer sends a request to your load balancer, it resolves the load balancer’s domain name using a Domain Name System (DNS) server. The DNS entry is controlled by Amazon, because your load balancer is in the domain. Amazon DNS servers return one or more IP addresses to clients. These are the IP addresses of the load balancers for your load balancer. With Network Load Balancer, Elastic Load Balancer creates a network interface for each of the Available Areas that you turn on. Each load balancing node in the Availability Zone uses this network interface to obtain a static IP address. You can optionally associate an elastic IP address with each network interface when you create a load balancer.

As traffic to your app changes over time, Elastic Load Balancing will balance your load balancing rate and update your DNS entry. The DNS entry also specifies a lifetime (TTL) of 60 seconds. This helps to ensure that IP addresses can be quickly remapped in response to traffic changes.

The client determines which IP address to use to send requests to the load balancer. The load balancing node that receives the request will choose a healthy registered target and send the request to the target using its own IP address.

Routing Algorithm

With the Application load balancer, the load balancing button receives requests using the following procedure:

  1. Evaluate listener rules in order of priority to determine which rule will apply.
  2. Select a target from the target group for the rule action, using the routing algorithm configured for the target group. The default routing algorithm is circles. Routing is done independently for each target group, even if the target is registered with multiple target groups.

For Network Load Balancer , the load balancer receives the connection using the following procedure:

  1. Select a target from the target group for the default rule using a hashing algorithm. It is based on an algorithm:
    • Protocol
    • Source IP address and source port
    • Destination IP address and destination port
    • TCP serial number
  2. Routes each individual TCP connection to a unique target for the life of the connection. TCP connections from clients have different source ports and sequence numbers and can be routed to different targets.

With the classical load balancer , the load balancing node that receives the request will select a registered instance as follows:

Uses circular routing algorithm for TCP listeners

Use the least desirable routing algorithm for HTTP and HTTPS listeners

Chia sẻ bài viết ngay

Nguồn bài viết : Viblo