Web Farms - How to tell which node is being served

I work with web farms on a daily basis, and one of the requirements that I run into, for testing, troubleshooting and logging, is to tell which node is handling a specific request. 

To use a current example, at ORCS Web, we're testing Microsoft's new Application Request Routing Module (ARR) for performance, stability and features to see if it offers value along-side our other load balancing solutions.  (Note: ARR is still in RC1 at the time of this writing)  During testing, I want to be able to tell how ARR is distributing the load under different settings.  Does a custom round robin setting really work as promised?  Does the least current requests work?  How can I tell and test?  Etc, etc.

One simple but important piece of information that I want to see over and over is which server node is being served.  Without knowing the server name of the web node, it's just a guessing game, and the testing is pretty useless.

Fortunately the solution is trivial in ASP.NET.  There are multiple ways to do it, but two namespaces that expose the machine name are System.Environment and System.Web.HttpContext.Current.Server. 

To create a testing page that exposes the server name in VB.NET, create a file called CurrentNode.aspx with the following in it:

<%
Response.Write (System.Environment.MachineName)
%>

Or, if you're using C#, the only difference is the ; (semi-colon) requirement on the end:

<%
Response.Write (System.Environment.MachineName);
%>

That is literally all that I put in the file, or else I tack this on the bottom of an existing page.  You'll notice that it's not valid HTML and nothing fancy, but no common browsers will complain, this is something that I can memorize and quickly type, and it's fully functional.

The computer name is obtained by Windows on system boot-up by reading the registry value.

I'm not aware of any differences in functionality, but you can use the following instead:

<%
Response.Write (HttpContext.Current.Server.MachineName)
%>

Hit that page from the load balancer's IP (often called a VIP [virtual IP]) and you'll know which node is handling the request.

This comes in useful for troubleshooting failures too.  You may have users saying that they are receiving errors on your site, but you're unable to reproduce it consistently.  Expose the server name in your error logging so that you know if it's something specific to particular nodes, or if it's global across all nodes.

No Comments