1

在服务器 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 中有新的方法可以做到这一点?

4

1 回答 1

2

根据TechNet 上的此页面,除非总 CPU 使用率大于 70%,否则不会强制执行资源管理。

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

您没有准确提及您要控制的内容。如果您的工作负载是 RDS(虚拟桌面、基于会话的桌面或 RemoteApp 程序),Windows Server 2012 的“FairShare”功能可能对您更有用。相关片段:

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

该片段可以在这个 technet 页面的中间找到。

于 2013-01-30T23:18:12.943 回答