Application Request Routing and URL Rewrite – PART 1(Server Farms)

In my previous blogs I had mentioned how we can use URL rewrite without ARR in picture. In the next series of upcoming blogs I will be discussing how we can leverage ARR and URL rewrite with ARR.

ARR is an out of band module available for IIS 7.x and onwards.

ARR can be used for below purposes.

1) As a load balancer when you want to load balance requests between multiple servers.

2) As a reverse proxy where your web servers are hidden from the internet world.

3) It can also be used for platform provisioning and application provisioning(by this I mean keeping configuration and features installed on top of IIS in sync between multiple servers) with the help of web deploy(which is famously know as web farm framework WFF). WFF is not tested completely from IIS 8 and onwards.

In this series we will discuss 1) and 2). First we will concentrate on how we can use ARR as a load balancer.

ARR as a load balancer

Before going ahead and using ARR as a load balancer. Let’s get familiarized with the options present in the ARR server farms UI which will help us during our discussion.

clip_image001

Below are the important options which we need to familiarize ourselves with when we want to use server farms or ARR as a load balancer.

1) Caching

2) Health Test

3) Load Balance

4) Monitoring and Management

5) Proxy

6) Routing rules

7) Server Affinity

Caching:

clip_image003

This is similar to your IIS caching where you have the above mentioned options. This option will help you in caching content received from the backend server when the content has not been changed.

Element Name

Description

Memory cache duration (seconds)

Enter the length of time, in seconds, that you want cached content to be stored. The default value is 60 seconds.

Enable disk cache

Select this check box to use your configured disk cache locations. By default, ARR caches content to the primary disk cache after it is configured.

Enable request consolidation

Select this check box to configure the request consolidation feature. Enabling request consolidation reduces the number of requests when streaming live content. By default, this feature is disabled.

Query string support

Select how you want to handle query string values from the following options:

  • Ignore Query String
  • Do Not Cache
  • Include Query String

https://technet.microsoft.com/en-us/library/ee731895(WS.10).aspx

Load Balance:

clip_image005

Over here you can specify the algorithm you want to use to perform load balancing and based on what criteria the incoming requests should be split between your web servers. The options present are all standard algorithms and you can find info about these algorithms over internet about how they work. Below are the available algorithm options about load balancing and a brief introduction about them.

  • Weighted round robin – Distributes traffic based on the number of incoming requests and their normalized weight. Each server can receive the same distribution of requests or a custom distribution.
  • Weighted total traffic – Distributes traffic based on the size of the requests and responses in bytes. Requests are routed so that the amount of data is load balanced. In an even distribution, the server with the least amount of data will receive the next request.
  • Least current request – Distributes traffic based on the current number of HTTP requests between ARR and each of the application servers. Requests are routed to the server with the least number of current HTTP requests.
  • Least response time – Distributes traffic based on the fastest response time from the servers, which enables the server to respond most quickly.
  • Server variable hash – Distributes traffic based on a hashed value of a server variable.
  • Query string hash – Distributes traffic based on the hashed value of the query string value. When more than one query string name is specified, the concatenated string of the corresponding query string value is used for the hash.

· Request hash – Distributes traffic based on the hashed value of the configured server variable or URL. For example, if the server variable is QUERY_STRING, the hashed value is based on the names in the request query string.

Proxy:

image

I forgot to include explanation for Reverse rewrite host in response headers in the image while creating it.

Reverse rewrite host in response headers: This option might not be of much value over here but its a very important setting while having reverse proxy. Imagine the internet exposed url is https://contoso.com and you have the backend servers contoso1 and contoso2. consider an example where you have a redirect status set and in the response location tag is set to https://contoso1/redirectedpage.aspx in web server in respect to the request forwarded from ARR server and this has to be notified to the end client. the client doesn't know who contoso1 is. so before sending the complete response to the client, the ARR server rewrites the host name in the location tag as https://contoso.com/redirectedpage.aspx

Routing Rules:

clip_image009

This is pretty much self-explanatory and you will select “Use URL Rewrite to inspect incoming requests” option to use URL rewrite rules to evaluate requests that come through your server.

Another important option over here is Enable SSL offloading- if you select this option even though the requests from client to ARR server will be over https but while forwarding the requests to backend servers this will happen over http.

Requests with the following extensions are not forwarded: This is a very rarely used but a very good feature which helps you in improving performance. if you specify *.jpg, then it means that any request for .jpg image file will not be sent to the backend server. you can keep the static content like images on ARR server itself. This will add a condition in your rule. you can add this condition manually in your inbound rule as well. the condition will look like below.

image

Requests with the following patterns are not forwarded: This one is similar to the one mentioned above. when you have contents like templates, images or static content which wont change often then you can keep the copy of it in ARR server itself and then choose not to forward these request and process these request locally on ARR server. I can choose to ignore all the requests containing images in the path from being forwarded. you can manually add such a condition in your inbound rule as well and it will look like below.

image

Server Affinity:

image

Client affinity: People might be familiar with the name “sticky sessions” available in most of the hardware load balancers. This option provides the same feature in IIS. When you want the requests to be load balanced to the same server where the first request from the client was routed to for the whole session, you can use the client affinity feature over here.

This feature is advantageous where in your session state is ‘in-proc’ and not available outside the worker process.

Host Name affinity: imagine you have multiple hostnames for a site. based on the hostname used you can decide the affinity. Also if you have 4 servers for load balancing you can control the number of servers the requests can be routed if it comes with a specific hostname.

image

Monitoring and Management:

clip_image013

This will be your load balancer dashboard where you can monitor the health status and the request statistics, also how the load balancing is happening.

Creating sample to demonstrate load balancing by creating server farm in ARR

Scenario: Let’s consider the scenario where in we have two backend web servers’ contoso1.chiranth.com and contoso2.chiranth.com and one ARR server where we want to load balance the requests for the site “contoso.com” between the two servers.

To achieve the above requirement we have two follow two simple steps.

1) Creating a server farm which will be a container for these two servers

2) Creating URL rewrite rules to monitor the incoming requests and route it accordingly

Creating a server farm:

Creating a server farm is a two-step simple procedure as below.

1) Right click on server farms-> Create new server farm

clip_image014

2) Enter a friendly farm name

clip_image015

3) Add the server which you want to include for load balancing. Over here in our scenario we have 2 servers contoso1 and contoso2

clip_image016

Creating URL rewrite rules for your farm:

After creating the farm 50% of the task is done. Now we will have to configure URL rewrite rules to monitor the requests and route it accordingly. When you create a server farm ARR will prompt you asking if it should create a URL rewrite rule for you. Let’s click on No for that. I will take you through the manual steps for creating the rule.

1) Make sure under routing rules at the server farm level you have the “USE URL REWRITE to inspect incoming requests” option checked.

clip_image017

2) When you are using ARR for either Load balancing or as reverse proxy the URL rewrite rules should be created at the server level. Go to URL Rewrite at the server level.

clip_image019

3) Add rule-> Inbound rules ->Blank rule.

clip_image020

4) I have already explained about the sections in inbound rules and regular expressions in my previous blog. So over here pattern would be ‘ .* ’ i.e, anything and a condition stating that this rule should be executed only when the hostname or HTTP_HOST is contoso.com, action would be “Route to server farm” and under action properties select the appropriate server farm and specify the REQUEST_URI which we have stored as {R:0} from the pattern section in the URL.

The rule will look like below.

clip_image021

clip_image022

5) Click on Apply and you are good to go for testing.

Hope this helps. In next part of my upcoming blog I will discuss how we can use ARR as reverse proxy and how we can go through the troubleshooting if we are facing any issues and the tools that we can make use of.

References:

https://technet.microsoft.com/en-us/library/ee731895(WS.10).aspx

https://technet.microsoft.com/en-us/library/dd443524.aspx

https://technet.microsoft.com/en-us/library/dd443526.aspx

https://technet.microsoft.com/en-us/library/dd443532.aspx

https://technet.microsoft.com/en-us/library/dd443543.aspx

Technorati Tags: ARR,application request routing,urlrewrite,server farms,reverse proxy,caching,load balance,iis,proxy