Skip to main content

Load Balancing



What is Load-Balancing ?
Distributing network traffic across multiple servers  effectively  is called Load-Balancing.To meet high volumes,it is generally requires adding more servers. Load-Balancer route the client requests to the servers in an optimized way and takes care that no server is overworked. If new server is added to the group, It will start sending requests to this new server.

Load-Balancing Algorithms:
Why algorithms came into the picture ? Actually Load-Balancer selects the server based on two factors :
a) periodically pinging server to check its availability.
b)  defined algorithms - based on which load-balancer selects the server.

Algo 1: Least Connection (Default algorithm)
Least connection is the default algorithm to select server. Serve which has least number of active transactions is picked by Load-Balancer to handle request.Load-Balancer maintains records of transactions for each server.
For example: 
See the below figure, Load-Balancer will select server 2.

XL
 Now discuss this in detail: Lets say all the servers has same capacity and still some of the servers are overloaded as there may be the situation that the client stayed in those servers for longer duration and connected to other severs for shorter duration.Active connections on the server where client stayed longer will pile up and hence based on Least connection algorithm Load Balancer will route the request in the server with least active connections,

Algo 2: Weighted Least Connections :
Now lets consider above Least Connection algorithm with different server capacities (CPU/RAM etc.). You would definitely want to allocate more requests to the higher capacity server than the lower capacity servers. Weighted Least Connection is the solution. 
Let's say there are 2 servers, server 1 and server 2 and server 2 has high configuration.With this algorithm Load balancer will allocate more requests to server 2 to utilize it better.Like Least Connection this also allocate request to the server with least number of active connections but the higher configuration server will handle more requests based on the wight proportion defined during the Load Balancer setup. Weight proportion is calculated by the server capacity. Server 1 : Capacity X, Server 2 : Capacity : 10X the weight for each server would be 1:10 .
 There might be the scenario if you don't want to overload any of the server for some reason, you may use this algorithm to give extra weight to another servers.


Algo 3: Round Robin
Round Robin is vastly used and simple algorithm. Load-Balancer distributes requests in the cyclic order irrespective of server inefficiencies.

L

 Both the Servers are ready to take request, suppose request comes and load-balancer routes to Server 1 then if 2nd request comes it will be routed to Server 2. 3rd and 4th will be routed to Server 1 and 2 respectively in a cyclic order. Even if one of the server has stronger configuration i.e. RAM, CPU etc. As per Round Robin algorithm Load-Balancer will follow the cyclic order. 

Algo 4: Weighted Round Robin:
Like Round Robin this is also cyclic but the higher configuration server will handle more requests.Rest it is same as Weighted Least connection algorithm i.e. weight would be defined during Load Balancer setup and high weight server will handle more requests.
i.e. if weight proportion to server 1 and server to is 1:10. first 10 requests will go to server and 11th request will go to server 1 and next 10 request will go to server 2 and so on.

Algo 5: IP Hash:

 This algorithm generates a hash key using client and server IP addresses which means this key would be assigned to client for subsequent requests which assure that the client is routed to the same server that it was using earlier.This algorithm can be used to achieve Session Persistence or Sticky Session.

Session Persistence:
In the multiple server environment a user might experience in loosing cart items during navigation. Persistence session or sticky session is the culprit. As you know Http is a stateless protocol which means in subsequent request it doesn't maintain any information about the user so to identify server uses client's ip or cookie to track users session. Sticky session is to make sure all the requests goes to the same server which has its user's session tracking information.

Layer 4 & Layer 7 Load Balancing:
In Layer 4 Load Balancing , Load balancer Decides the server on which it will redirect the requests on  the basis of the IP addresses of the origin and destination servers (Network Layer : Layer 3) and the TCP port number of the applications (Transport Layer : Layer 4).
On the other hand Layer 7 Load Balancing decides routing on the basis of  OSI Layers 5, 6, and 7 which together makes Http.


To get overview of  OSI Model, Please read my post .

Find it here also C-Sharp-Corner







Comments

Popular posts from this blog

Abstract Factory Design Pattern

Abstract Factory : return families of related or dependent objects without specifying their concrete classes. AbstractFactory- IVehicle ConcreteFactory - Maruti, Honda AbstractProduct- IDiesel, IPetrol Product- DezirePetrol, ZenDiesel, AmazeDiesel, CityPetrol Client- This is a class which uses AbstractFactory and AbstractProduct interfaces to create a family of related objects Implementation is pretty much straight forward: Since now you have good understanding of Factory, there is nothing much to explain. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AbstractFactory {     class Program     {         static void Main(string[] args)         {             IVehicle marutiVehicle = new Maruti();             CarClient marutiClient = new CarClient(marutiVehicle); ...

About Us

Ashish Joshi C# TestDome Certificate Hi, Welcome to my blog on various topics on .Net Stack basically. My name is Ashish Joshi and I’m a software developer. I majorly work with .NET. I recently started writing  blogs about .NET but since now .Net Stack is huge and crossing it's boundaries, it's  compatible with other technology stacks, you’ll see posts from other technologies as well. I hope you’ll find a lot of interesting topics here that you can use in your own assignments. You can find me on LinkedIn I am.planning to write in coming days (2017-2018) on: Popular Interview Questions For Experienced .Net resources  MongoDb in .NET Various Design Patterns Machine Learning - will try to demonstrate how it can be done in .net and in other technology Artificial Intelligence - same as machine learning I'll demonstrate using some running examples Feel free to provide your feedback and suggestions.

Privacy Policy

This blog does not share personal information with third parties nor do we store any information about your visit to this blog other than to analyze and optimize your content and reading experience through the use of cookies.  You can turn off the use of cookies at anytime by changing your specific browser settings.  We are not responsible for republished content from this blog on other blogs or websites without our permission.  This privacy policy is subject to change without notice and was last updated on Month, Day, Year. If you have any questions feel free to contact me through comment section of this blog.