在服务器2012上设置每个用户的CPU限制

时间:2013-01-29 23:58:44

标签: performance powershell window windows-server

在服务器2008 R2上,我使用以下PowerShell以编程方式将CPU LIMIT设置为特定百分比

function Set-UserAccountCPUThrottle
{
[CmdletBinding()]
Param(
[ValidateNotNullOrEmpty()]
[parameter(Mandatory = $true)]
$UserNameToRestrict,
[Parameter(Mandatory = $false)]
[int]$CpuPercentage = 5
)

write-host "about to restrict user account $UserNameToRestrict to use ${CpuPercentage}% CPU"

  try
    {     
      $objUser = New-Object System.Security.Principal.NTAccount($UserNameToRestrict)
      $local:ResolvedSID= $objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value.trim()   
    }
  catch
    {
      throw "Cannot resolve the User (or find its SID) for $UserNameToRestrict"
    }    
 $regpath = "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Quota System\${local:ResolvedSID}"
 #in creating a new key for this sid, it will remove any old item
mkdir $regpath -Force -ErrorAction stop | out-null
#as the old key if existing was removed by the above code, this will create a new value
 New-ItemProperty -Path $regpath  -Name "CpuRateLimit" -Value $CpuPercentage -PropertyType "DWord" -Force -ErrorAction stop | out-null   

}

但是,这确实会为http://technet.microsoft.com/en-us/library/ff384148(v=ws.10).aspx

创建注册表项

它对服务器2012或Windows 8有空效果。这是否已损坏或是否有新的方法在服务器2012中执行此操作?

1 个答案:

答案 0 :(得分:2)

根据this page on TechNet,除非总CPU使用率大于70%,否则不会强制执行资源管理。

你的机器忙吗?该页面还描述了可能不会发生资源管理的其他一些情况。

你没有准确提到你想控制的是什么。如果您的工作负载是RDS(虚拟桌面,基于会话的桌面或RemoteApp程序),则Windows Server 2012“FairShare”功能可能对您更有用。相关摘要:

  

“RD会话主机中的资源共享。在Windows Server 2012中,   RD会话主机服务器分配CPU,磁盘I / O和网络I / O等   单个用户不能消耗会产生负面影响的资源   影响同一主机上的其他用户。每个用户都会得到一个“公平的   分享”。这是以最小的开销完成的,所以CPU,磁盘和   网络资源用于最大容量。“

可以在this technet page.

中途找到该代码段