Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

understanding load balancing in asp.net

Tags:

I'm writing a website that is going to start using a load balancer and I'm trying to wrap my head around it.

  1. Does IIS just do all the balancing for you?
  2. Do you have a separate web layer that sits on the distributed server that does some work before sending to the sub server, like auth or other work?

It seems like a lot of the articles I keep reading don't really give me a straight answer, or I'm just not understanding them correctly, I'd like to get my head around how true load balancing works from a techincal side, and if anyone has any code to share that would also be nice.

I understand caching is gonna be a problem but that's a different topic, session as well.

like image 867
dbarnes Avatar asked Nov 20 '13 15:11

dbarnes


People also ask

What is load balancing explain in detail?

Load balancing is a core networking solution used to distribute traffic across multiple servers in a server farm. Load balancers improve application availability and responsiveness and prevent server overload.

What is load balancing in C#?

What is Load Balancing ? Distributing network traffic across multiple servers effectively is called Load Balancing.To meet high volumes, it generally requires adding more servers. Load Balancer routes the client requests to the servers in an optimized way and takes care that no server is overworked.

What are the three types of load balancers?

Elastic Load Balancing supports the following types of load balancers: Application Load Balancers, Network Load Balancers, and Classic Load Balancers.

What are the different methods of load balancing?

Some of the common load balancing methods are as follows: Round robin -- In this method, an incoming request is routed to each available server in a sequential manner. Weighted round robin -- Here, a static weight is preassigned to each server and is used with the round robin method to route an incoming request.


2 Answers

IIS do not have a load balancer by default but you can use at least two Microsoft technologies:

  • Application Request Routing that integrates with IIS, there you should ideally have a separate web layer to do routing work,
  • Network Load Balancing that is integrated with Microsoft Windows Server, there you can join existing servers into NLB cluster.

Both of those technologies do not require any code per se, it a matter of the infrastructure. But you must of course remember about load balanced environment during development. For example, to make a web sites truly balanced, they should be stateless. Otherwise you will have to provide so called stickiness between client and the server, so the same client will be connecting always to the same server.

To make service stateless, do not persist any state (Session, for example, in case of ASP.NET website) on the server but on external server shared between all servers in the farm. So it is common for example to use external ASP.NET Session server (StateServer or SQLServer modes) for all sites in the cluster.

EDIT:

Just to clarify a few things, a few words about both mentioned technologies:

  • NLB works on network level (as a networking driver in fact), so without any knowledge about applications used. You create so called clusters consisting of a few machines/servers and expose them as a single IP address. Then another machine can use this IP as any other IP, but connections will be routed to the one of the cluster's machines automatically. A cluster is configured on each server, there is no external, additional routing machine. Depending on the clusters settings, as we have already mentioned, a stickiness can be enabled or disabled (called here a Single or None Affinity). There is also a Load weight parameter, so you can set weighed load distribution, sending more connections to the fastest machine for example. But this parameter is static, it can't be dynamically based on network, CPU or any other usage. In fact NLB does not care if target application is even running, it just route network traffic to the selected machine. But it notices servers went offline, so there will be no routing there. The advantages of NLB is that it is quite lightweight and requires no additional machines.
  • ARR is much more sophisticated, it is built as a module on top of IIS and is designed to make the routing decisions at application level. Network load balancing is only one of its features as it is a more complete, routing solution. It has "rule-based routing, client and host name affinity, load balancing of HTTP server requests, and distributed disk caching" as Microsoft states. You create there Server Farms with many options like load balance algorithm, load distribution and client stickiness. You can define health tests and routing rules to forward request to other servers. Disadvantage of all of it is that there should be a dedicated machine where ARR is installed, so it takes more resources (and costs).
  • NLB & ARR - as using a single ARR machine can be the single point of failure, Microsoft states that it is worth consideration to create a NLB cluster of ARR machines.
like image 95
Konrad Kokosa Avatar answered Oct 07 '22 15:10

Konrad Kokosa


Does IIS just do all the balancing for you?

Yes,if you configure Application Request Routing:

ARR in IIS

Do you have a separate web layer that sits on the distributed server

Yes.

that does some work before sending to the sub server, like auth or other work?

No, ARR is pretty 'dumb':

IIS ARR doesn't provide any pre-authentication. If pre-auth is a requirement then you can look at Web Application Proxy (WAP) which is available in Windows Server 2012 R2.

It just acts as a transparent proxy that accepts and forwards requests, while adding some caching when configured.

For authentication you can look at Windows Server 2012's Web Application Proxy.

like image 42
CodeCaster Avatar answered Oct 07 '22 15:10

CodeCaster