Nov 18, 2014

How to setup a Load Balancer via Application Request Routing (ARR) extension on IIS

This is the walk through on how to set up an Load Balancer on IIS 7.5 using Application Request Routing extension.

Requirements

Steps to create Load Balancer

1. Create a dummy web application to receive incoming requests.
image[12]
Note:
this web app is just a dummy web on port 80, which will acts as request router to our back-end web farm.

2. Configure the dummy web app
In the Create Web Site dialog, use port 80 and the host name as of your domain.
image[17]

The website physical path can just contains a very simple web.config as following:

    <?xml version="1.0" encoding="utf-8" ?>
    <
    configuration
    >
    <
    system.web
    >
    </
    system.web
    >
    </
    configuration>

3. Create the actual web application that serve your request:
In my example, I used port 8080.

Important notes: this port will be the server port while creating server farm.


image

4.Create the server farm
Next step is to create the server farms which will handle the request load balancing. You can choose any name for your server farm.
image


4. Adding servers to server farm
While adding servers to the farm, take note of the httpPort – this MUST be your web application port which you chose in step 3)
image
Once you add the server farm, IIS will ask you to add rules. If you have existing rules, it may popup this message. Just go ahead and click Yes to create the rules. We’ll configure it later.


image


5. Configure the Request Routing rules
Highlight your server farm, then choose Routing Rules
image


Select URL Rewrite under Advance Routing


image


6. Configure Inbound Rule Routing Request:
- Logical Grouping
: Match All


- Conditions:



  • {HTTP_POST} : Matches The Pattern : *localhost* (or your domain name in step 2)
    AND
  • {SERVER_PORT}: Does Not Match The Pattern: *8080* (or your chosen port in step 3)

- Action Type: Route to Server Farm (choose the server farms where you added the web servers in step 4)


image


7. Configure your Load Balance algorithm
Similar to step 5, highlight your server farm and choose Load Balance


image

You will have a list of Load Balance Algorithm to choose from. Depends on your need, you can pick the corresponding algorithm


image



 


Use the list to select the algorithm to use to load balance your server. The available options are: (From MSDN):


  • 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.

8. Test your server farms to confirm it works
If your configurations are right, you should start to see your web applications running. You can also explore more on configure distributed disk-cache, changing server affinity (how server associate with user sessions) and so on.


Conclusion


The key concept is to create a dummy web application, then use ARR and Load Balance to route request to your server farms (based on the Inbound Rules).

ARR is a very good features which make IIS more useable and become more ready for production sites. Try it yourself and have fun Smile !

2 comments:

  1. Thank you very much for your post!
    Could you please help me with my problem - when I setup ARR, my apps are loading or not loading randomly, and missing some elements in the interface. What can cause that?

    ReplyDelete
    Replies
    1. Open your browser developer console and check network activity. It could be due to the fact that some of your front-end assets (JavaScript, CSS, images) are not loaded properly with ARR. Try the solution at : https://stackoverflow.com/questions/3771831/iis-7-5-no-images-css-js-showing

      Delete