The simple algorithm here is not so complicated.
Let's say you have a list of servers with the following weights:
A 10 B 20 C 30
If higher weight means that it can handle more traffic.
Just divide the amount of traffic sent to each server by weight and sort the smallest value with the largest. The server that exits from above receives the user.
for example, let's say that each server starts with 10 users, then the order will be as follows:
C - 10 / 30 = 0.33 B - 10 / 20 = 0.50 A - 10 / 10 = 1.00
This means that the next 5 requests will be sent to server C. The 6th request will go either to C or to B. The 7th will go to the fact that the 6th is not processed.
To complicate the situation, you may want the balancer to be more intelligent. In this case, he needs to monitor how many requests are currently being served by each of the servers, and reduce them when the request is fully completed.
Further complications include the addition of stickiness to the sessions. This means that the balancer must check each request for a session identifier and keep track of where they were last.
In general, if you can just buy a product from a company that is already doing this.
source share