Load Balancing Algorithm
Static Algorithms
Round robin
Distribute requests evenly in each server
Pros
- Easy to do
- Make sure all the requests get routed properly
Cons - If one server is temporary unavailable and get back up again, caused inbalancing in distribution
- The routing is not necessary optimised for the connection
Sticky round robin
Same request goes to the same servers.
Pros:
- Server contains information for the relevant requests, hence make it more suitable to handle requests from the same server.
Cons:
- Could happen unbalance distribution where one users make more requests than the other users.
Weighted round robin
Each server has a weight of distribution and request can distribute there.
Pros:
- Have more control of the distribution
Cons: - Weighted attributes needs to be monitor and configure manually
IP/URL Hash
We route each request IP to the corresponding server.
Pros:
- Provide a control over which IP goes to which server
Cons: - Unbalance distribution
- Hash function is difficult to calculate
Dynamic algorithms
Least connections
Routes to the server that currently has the least connection
Pros:
- Properly distribute all the requests to server.
- Dynamically adjusted base on the need
Cons:
- Need to monitor the connections for each server which requires resources.
Least latency
Route to the nearest server based on the user latency.
Pros:
- Highly adaptive and reactive
Cons: - Introduce complexity
- Constant monitoring
- Doesnt monitor how many requests the server currently have.