Trusted answers to developer questions

What is the weighted round-robin load balancing technique?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Overview

The purpose of load balancers is to improve the performance of applications and decrease the burden by "efficiently"Efficiency depends on server selection. distributing the incoming traffic across a group of servers. For user-facing applications, this will result in improved response times.

Note: Here, we will mainly talk about application load balancers.

Now, let’s jump right into the details of the weighted round-robin load balancing technique.

About the technique

This technique is similar to the round-robin load balancer. But in the weighted round-robin load balancer, the network administrator assigns a numeric weight to all of the servers behind the load balancer. The weights can be assigned based on factors such as the server’s processing power or total bandwidth.

  • A server, say ServerA, with the most processing power will be assigned the maximum weight. It will also receive the maximum proportion of incoming requests from the load balancer.

  • A server, say ServerB, with half the processing capacity compared to ServerA will be assigned a weight that is half of the actual weight of ServerA. Additionally, it will receive the proportion of incoming requests from the load balancer accordingly.

  • A server, say ServerC, with the lowest specifications will be assigned the lowest weight, and it will receive the minimum proportion of incoming requests from the load balancer.

Note: The weighted round-robin load balancer is a static load balancer, as it does not modify the state of the servers while distributing incoming traffic.

Example

Let’s understand this with the help of an example:

Suppose we have three servers —ServerA, ServerB, ServerC— with weights (5, 2, 1) that are waiting to serve incoming requests behind the load balancer.

The load balancer will forward the first five requests to ServerA, the next two requests to ServerB, and then one request to ServerC.

If any of the other incoming requests arrive, the load balancer will forward those requests back to ServerA again for the next five incoming requests, then ServerB will get its turn, and after that the requests will be forwarded to ServerC. The cycle will continue on this way.

This cycle is shown in the illustration below:

Weighted round-robin load balancing technique

Algorithmic explanation

  • i: This is the request number that is processed. It is initially set to zero.
  • Weights: This is an array that holds the weights for all the servers.
  • T: This is the total number of servers that are available.

Algorithm

  1. Begin.

  2. Assign a specific number of requests to i mod Tth server, according to its numeric weight Weights[i].

  3. Increment the value of i by value of 1.

  4. Repeat steps 2 and 3, until there are no more requests.

  5. End.

Advantages

  • This load balancing technique prevents a server from receiving a large number of incoming requests.

  • It utilizes fewer resources.

  • The request assignment is deterministic and it is easy to determine the assigned server.

  • The network administrator can set the numeric weight for the server. This is helpful for when we want some of our server’s resources to be available for other tasks.

Limitations

The weighted round-robin load balancing technique is not a suitable choice for when we have incoming requests with extensive service time or for when the service time of each request is different.

Real time load balancers

  • Nginx
  • Varnish
  • HAProxy
  • LVS

RELATED TAGS

scheduling
troubleshooting
load balancer

CONTRIBUTOR

Abubakkar Arshad
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?