Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I'm using WLBS in Windows 2000 for 2 web servers for redundancy and load balancing. When I want to take one of the services down, I use "WLBS drainstop" from the command line. However from monitoring the number of open connections in IIS, it takes quite a while for the existing connections to be closed. If I run "WLBS stop" the remaining connections will hang for a couple minutes while they figure out the other end of the connection is no longer there. We don't have any need for long running connections, and page requests are returned in well under 10 seconds. Is there some way for WLBS, or IIS to close any open, non-active connections, so that I can remove a server from load balancing without waiting for all the open connections to close by themselves?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Using an old trick from the Joel discussion groups of turning off keep-alive, and then running WLBS drainstop was the key to getting this to work properly. Then I wrote a script in VBS to automate the whole thing. There's 2 scripts. One script to remove the node from the cluster, and another to bring the node back online.

The Remove Script is as follows.

Set IISOBJ = getObject("IIS://LocalHost/W3SVC")
Dim IISInstance
Dim FoundIIS
Dim IISInstanceName 
Dim NumConnections
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

IISInstanceName = "Default Web Site"

FoundIIS = False

For each IISInstance in IISOBJ
    If (IISInstance.Class = "IIsWebServer") Then
    	If (IISInstance.ServerComment = IISInstanceName) Then
    		IISInstance.Put "AllowKeepAlive", False
    		IISInstance.SetInfo()
    		FoundIIS = True
    		Exit For
    	End If
    End If
Next

If Not FoundIIS Then
    WScript.Echo "Could Not Find IIS.  Exiting."
    Wscript.quit()
End If

WSHShell.Run "wlbs drainstop" , 0, true

WScript.Echo " Going To Sleep For: " & IISInstance.Get("ConnectionTimeout") & " Seconds"

WScript.Sleep IISInstance.Get("ConnectionTimeout") * 1000 

WSHShell.Run "wlbs stop" , 0, true

WScript.Echo "Successfully removed node from load balancing"

And the script for bringing the machine back online is as follows.

Set IISOBJ = getObject("IIS://LocalHost/W3SVC")
Dim IISInstance
Dim FoundIIS
Dim IISInstanceName 

IISInstanceName = "Default Web Site"

FoundIIS = False

For each IISInstance in IISOBJ
    If (IISInstance.Class = "IIsWebServer") Then
    	If (IISInstance.ServerComment = IISInstanceName) Then
    		IISInstance.Put "AllowKeepAlive", True
    		IISInstance.SetInfo()
    		FoundIIS = True
    		Exit For
    	End If
        End If
Next

If Not FoundIIS Then
    WScript.Echo "Could Not Find IIS.  Exiting."
    Wscript.quit()
End If

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")

WSHShell.Run "wlbs start" , 0, true

WScript.Echo "Successfully added node to load balancing"

You can change the IISInstanceName variable at the top of the script to match the name of your web server. This is the name that shows up when you go to the "Internet Information Services" section under "Administrative Tools". You can change this to whatever you have named your web server. Overall it's a little clunky, but it works. It's Also Possible to change the first Line To

Set IISInstance = getObject("IIS://LocalHost/W3SVC/1")

and then cut out the whole for loop that looks for the server by name, but I think it's a little more "correct" to find the server by name, rather than by some number, which I'm not sure if windows would change under some circumstances of adding and removing web server instances.

share|improve this answer

Just lowering the keepalive timeout from two minutes down to ~20 seconds might be enough.

http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/ea116535-8eb9-4c80-8b14-b34418dbfe42.mspx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.