Put the brakes on your Application Pools: CPU Rate Limits in Windows Server 2008

Are you using IIS Application Pools to host your customer's web sites? The more sites you host on a single machine the more likely it is one of these sites misbehaves and monopolizes system resources like the CPU. It's so easy for a programmer to do - forget to call the MoveNext() function in a database script and you spin the CPU at 100% until the underlying script engine times out.

This can mean of course that other sites on your machine might not get enough CPU cycles and starve. All this because somebody doesn't play nice and eats all the pie. CPU rate limits on Windows Server 2008 and Windows Server 2008 R2 allow you to cut the pie more equally.

CPU rate limits can limit a particular user account to consume only a configurable percentage of each physical CPU, e.g. 10%. This becomes very handy if the new IIS Application Pool Identities feature in IIS 7.5 (Windows Server 2008 R2) or Windows Sever 2008 SP2 is used.

The following technet article which describes the feature in detail.

I wrote a PowerShell script iif you want to try it yourself:

param ( [Parameter(Mandatory=$true)][string] $account, [Parameter(Mandatory=$true)][int] $rate) 
$objAccount = New-Object System.Security.Principal.NTAccount($account)
$strSID = $objAccount.Translate([System.Security.Principal.SecurityIdentifier]).Value
if ($strSID -eq $null)
{
"Account $account cannot be translated into a SID";
return;
}
"SID for $account : `t$strSID";
$quota_hive = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Quota System\$strSID"

$out = New-Item -path "$quota_hive" -force
$out = New-ItemProperty -path "$quota_hive" -name CpuRateLimit -value $rate
"CPU Rate for account $account set to $rate %"

And here is the same as command-line tool if you don't want to use a PowerShell script.

Now here comes the drawback. The CPU Rate Limit feature has a bug. The kernel is holding on to a handle to the quota object and never lets go of it. This means once you set the CPU rate limit to a particular percentage you can't change this percentage without rebooting the machine. We are working on fixing it - not sure when we'll have a fix though. 

No Comments