PowerShell可通过powercfg命令启用高性能电源计划并设处理器状态为100%,再配合TCP自动调谐、网络卸载及服务优化实现服务器性能提升。
powershell 可以直接调整 windows 服务器的性能等级(即电源计划与处理器性能状态),但需注意:windows 本身没有“性能等级”这一原生术语,实际对应的是电源计划(power plan)、处理器电源管理策略和tcp 自动调谐级别等关键参数。这些设置共同影响服务器在高负载下的响应速度、吞吐量和资源调度效率。
切换并锁定高性能电源计划
默认的“平衡”计划会动态降低 CPU 频率以省电,对服务器不利。应强制启用“高性能”或自定义计划,并禁用节能缩放:
- 运行 Get-ExecutionPolicy 确保策略允许脚本执行(推荐 RemoteSigned)
- 用 Get-PowerPlan(需先导入 PowerShellGet 模块)或 powercfg /list 查看可用计划 GUID
- 执行:
powercfg /setactive <高性能计划GUID> - 进一步优化:关闭处理器节能缩放
powercfg /setacvalueindex scheme_current sub_processor PROCTHROTTLEMAX 100
powercfg /setdcvalueindex scheme_current sub_processor PROCTHROTTLEMAX 100
powercfg /setacvalueindex scheme_current sub_processor PROCTHROTTLEMIN 100
powercfg /setdcvalueindex scheme_current sub_processor PROCTHROTTLEMIN 100
powercfg /setactive scheme_current
配置 TCP 自动调谐与网络卸载
TCP 性能直接受自动调谐级别影响。新式 Windows 默认为 normal,但高吞吐场景建议设为 highlyrestricted 或 experimental(需实测):
- 查看当前设置:Get-NetTCPSetting | Select-Object SettingName, AutoTuningLevelLocal
- 设为高吞吐模式:Set-NetTCPSetting -SettingName InternetCustom -AutoTuningLevelLocal experimental
- 启用网卡高级功能(如 RSS、RSC、LRO):Get-NetAdapterAdvancedProperty -Name "*" 查属性名,再用 Set-NetAdapterAdvancedProperty 启用(例如:-DisplayName "Receive Side Scaling" -DisplayValue "Enabled")
- 禁用可能干扰的卸载项(如 TCP Chimney):Set-NetIPInterface -Chimney Disabled
限制后台服务与系统动画开销
非核心视觉与服务会争抢 CPU 和内存资源,尤其在虚拟化或容器化环境中:
- 停用视觉效果:Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects' -Name 'VisualFXSetting' -Value 2
- 禁用 Windows Search(若非必需):Stop-Service WSearch -Force; Set-Service WSearch -StartupType Disabled
- 关闭遥测与诊断数据收集:Set-Service DiagTrack -StartupType Disabled; Stop-Service DiagTrack -Force
- 禁用 Windows Update 自动重启(生产环境慎用):New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" -Name NoAutoRebootWithLoggedOnUsers -Value 1 -PropertyType DWord -Force
验证与持续监控
调整后必须验证是否生效且无副作用:
- 确认电源策略已应用:powercfg /query 检查 PROCTHROTTLEMAX/MIN 是否为 100
- 检查 TCP 设置是否持久:Get-NetTCPSetting -SettingName InternetCustom | fl *
- 用 perfmon 添加计数器:\Processor(_Total)\% Processor Time、\Network Interface(*)\Bytes Total/sec、\TCPv4\Segments Retransmitted/sec(高重传说明网络层仍有瓶颈)
- 保存基线日志:logman start "ServerPerfBaseline" -o C:\logs\perf_$(Get-Date -Format 'yyyyMMdd') -f bincirc -max 512 -c "\Processor(*)\% Processor Time" "\Memory\Available MBytes"



















