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

Performance 在服务器2012上设置每个用户的CPU限制,performance,powershell,window,windows-server,Performance,Powershell,Window,Windows Server,在Server2008R2上,我使用以下PowerShell以编程方式将CPU限制设置为某个百分比 function Set-UserAccountCPUThrottle { [CmdletBinding()] Param( [ValidateNotNullOrEmpty()] [parameter(Mandatory = $true)] $UserNameToRestrict, [Parameter(Mandatory = $false)] [int]$CpuPercentage = 5 )

在Server2008R2上,我使用以下PowerShell以编程方式将CPU限制设置为某个百分比

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   

}
但是,虽然这确实会根据创建注册表项

它在服务器2012或windows 8上无效。这是坏的还是在server 2012中有一种新的方法可以做到这一点?

根据,除非总CPU使用率超过70%,否则不会强制执行资源管理

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

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

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


这个片段可以在Server2008R2的中间找到,上面的技术确实有效,并且将其限制在百分比范围内。我们在数千台服务器上运行它,有时限制在5%,有时限制在15%,而且工作完美无瑕。它只是不适用于2012年。不过,谢谢你的链接,它们可能会引导我走向正确的方向。我是基于一个使用这种技术的用户帐户。它控制在该用户下运行的windows服务,该服务还定期生成可执行文件。这会持续大约5分钟,由于它会根据用户对其进行限制,这两个进程的组合会使它在服务器2008上保持在x%以下,看起来这是与终端服务相关的,而不是我的上下文。哦,好吧。另一件要测试这种限制的事情是,我创建了一个在用户下运行的计划任务,该用户只运行powershell命令“while($true){}”,它在单个核心盒上使单个进程超过95%。。。在2012服务器上,而在2008 r2上,使用这种技术,它将其保持在5%或我设置的任何值。