【发布时间】:2014-12-09 18:53:34
【问题描述】:
对set-webconfigurationproperty 的每次调用都会泄漏大量内存,并最终使当前进程达到MaxMemoryPerShellMb 的winrs 限制。
一个调用set-webconfigurationproperty的例子+循环检查当前进程工作集。
所有执行都在使用new-pssession 启动并使用invoke-command 执行的远程会话中进行。
[remoteserver]: PS C:\scripts> winrm get winrm/config/winrs
Winrs
AllowRemoteShellAccess = true
IdleTimeout = 7200000
MaxConcurrentUsers = 10
MaxShellRunTime = 2147483647
MaxProcessesPerShell = 25
MaxMemoryPerShellMB = 1024
MaxShellsPerUser = 30
[remoteserver]: PS C:\scripts>
1..100 | %{
Set-WebConfigurationProperty -PSPath IIS:\ -filter "/system.webserver/rewrite/rewriteMaps/rewriteMap[@name='HostNameToServerMap']/add[@key='www.adomain.com']" -name "value" -value "iis04"
new-object psobject -property @{ WorkingSet = "{0:f2} MB" -f ([System.Diagnostics.Process]::GetCurrentProcess().WorkingSet/1mb); Timestamp = get-date }
}
Timestamp WorkingSet
--------- ----------
2014-10-14 22:10:54 964,45 MB
2014-10-14 22:10:56 981,76 MB
2014-10-14 22:10:57 999,95 MB
2014-10-14 22:10:58 1018,86 MB
Set-WebConfigurationProperty : Not enough storage is available to process this command. (Exception from HRESULT: 0x8007
0008)
At line:2 char:1
+ Set-WebConfigurationProperty -PSPath IIS:\ -filter "/system.webserver/rewrite/re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfigurationProperty], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.IIs.PowerShell.Provider.SetConfigu
rationPropertyCommand
2014-10-14 22:10:59 289,46 MB
2014-10-14 22:11:01 216,45 MB
2014-10-14 22:11:02 230,79 MB
2014-10-14 22:11:03 246,11 MB
2014-10-14 22:11:04 263,13 MB
2014-10-14 22:11:05 280,54 MB
2014-10-14 22:11:07 296,83 MB
2014-10-14 22:11:08 313,14 MB
2014-10-14 22:11:09 330,62 MB
2014-10-14 22:11:10 347,47 MB
2014-10-14 22:11:11 365,27 MB
....
set-webconfigurationproperty 消耗的内存没有被释放。
当进程达到 WinRS shell 的限制(在我的示例中为 1024 Mb)时会发生错误。
这个错误已经存在多年,现在我在 Server 2012 R2 上重现了它,因此 IIS 7、7.5、8 和 8.5 都会受到影响。
有没有比在 WinRM 会话中使用 WebAdministration PowerShell 模块的set-webconfigurationproperty 更好的方法来(批量)远程更新 IIS 配置?
【问题讨论】:
标签: powershell iis powershell-remoting