Tuesday, September 10, 2013

Are you sleeping?

When running a server with a large number of sites and using our new Dynamic Worker-Process Page-Out, an administrator might need to figure out what’s going on with the sites for tracking and resource optimization reasons. The simplest way to know of a site going into hibernation is by visiting the event viewer. When IIS puts a site to sleep, it logs an event ID no. 2310, which looks like this:


By querying the event log (with powershell, for example), you can produce a report that lists which sites are getting suspended often. Another type of information you might need is knowing how many of your sites are actually suspended throughout the day. This info can be achieved by examining the Private Working Set Size, which indicates how much memory a process is using. A site that is suspended will typically consume 2-6 MB, while an active site would consume at least 8 MB.

By using WMI to examine the memory usage of all the sites, you can create a data file with this information, which you can later import into something like Excel. Here’s a script for such a thing:

const iForWriting = 2
const iForAppend = 8
iHibernating = 8000000 'Hibernation threshhold
sReportFileName = "SiteReport.csv"
Set oFileObj = CreateObject("Scripting.FileSystemObject")
Set fSaveFile = oFileObj.OpenTextFile(sReportFileName,iForWriting,true)
fSaveFile.Writeline "Date,Time,Active,Hibernating"
set oProcessList = GetObject("winmgmts:{impersonationLevel=impersonate}\\.\root\cimv2").ExecQuery ("Select * From Win32_PerfRawData_PerfProc_Process")
iHibernatingCount = 0
iActiveCount = 0
for each pProcess in oProcessList
if instr(pProcess.name,"w3wp")<> 0 then
if clng(pProcess.WorkingSetPrivate) < iHibernating then
iHibernatingCount = iHibernatingCount +1
iActiveCount = iActiveCount +1
end if
end if
sResult = date & "," & time & "," & iActiveCount & "," & iHibernatingCount
wscript.echo sResult
Set fSaveFile = oFileObj.OpenTextFile(sReportFileName,iForAppend,true)
fSaveFile.Writeline sResult
wscript.sleep 60000

This script runs in a loop, checking and counting how many sites are suspended and how many aren’t, and dumping the result into a CSV file every minute. After this runs for a certain amount of time (ideally, at least 24 hours), you could double-click the CSV file to open it in Excel, and use the graph functions to produce a graph, like this:


Based on these figures, you can establish your performance data for peak and off-peak hours, and plan your expansion and hardware budgeting properly.

Good luck!

Blog post written by Erez Benari and Ahmed ElSayed

1 comment: