2016-10-07 4 views
0

나는이 스크립트를 꽤 오랫동안 사용 해왔다.하지만 그것에 시간을 할애 할 수 없어서 안심시켜야했다. 나는 지금 그것에 더 집중할 수 있으며, 제대로 작동하지 않는 것 같아서, 도움을 얻을 수 있기를 바랍니다.powershell의 machine.config 파일에 쓰기

이 스크립트는 먼저 다음는이 processModel 다시 쓰기 그리고

$node = $machineConfig.SelectNodes("/configuration/system.web") 
$node.RemoveChild(($node.SelectSingleNode("processModel"))) | Out-Null 

는,이 processModel autoConfig를이 = "진정한"/> 라인에게 machine.config에있는 부분을 삭제하기위한 것입니다

<system.web> 
    <processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"/> 
<httpRuntime minFreeThreads="90" minLocalRequestFreeThreads="80"/> 

다음은 조금 까다 롭습니다. 가상 머신의 CPU 코어 수에 따라 90 및 80을 배수하기를 원합니다. 기계가 4 개의 코어가 있다면 예를 들어, 파일의 아래쪽을 향해, 그 후

<system.web> 
    <processModel maxWorkerThreads="370" maxIoThreads="370" minWorkerThreads="50" minIoThreads="50"/> 
<httpRuntime minFreeThreads="360" minLocalRequestFreeThreads="320"/> 

을 읽을 것, 나는 그것이 이전에 다음 줄

<system.net> 
<connectionManagement> 
<add address = "*" maxconnection = "200" /> 
</connectionManagement> 
</system.net> 

처럼을 추가하려면, 가상 머신의 CPU 코어 수를 200으로 곱해야합니다. 기계가 4 개의 코어가 있다면 그래서 예를 들어, 무슨 내가 가지고있는 코드가하는 일은이 아웃이 processModel 섹션을 쓸 수 있지만 나를 위해 곱하지 않는다는 것입니다

<system.net> 
<connectionManagement> 
<add address = "*" maxconnection = "800" /> 
</connectionManagement> 
</system.net> 

을 읽을 것입니다 그리고 추가하지 않는 것 maxconnection 번호, 그냥 공간을 남겨주세요. 여기에 지금까지

$numberOfCores = Get-WmiObject -class win32_processor numberOfCores | Select-Object -ExpandProperty numberOfCores 
$path = "c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config" 
[xml]$machineConfig = Get-Content $path 
$node = $machineConfig.SelectNodes("/configuration/system.web") 
$node.RemoveChild(($node.SelectSingleNode("processModel"))) | Out-Null 
$processModelxml = $machineConfig.CreateElement("processModel") 
$processModelxml.setAttribute("maxWorkerThreads",370) 
$processModelxml.setAttribute("maxWorkerThreads",370) 
$processModelxml.setAttribute("maxIoThreads",370) 
$processModelxml.setAttribute("minWorkerThreads",50) 
$processModelxml.setAttribute("minIoThreads",50) 
$node.AppendChild($processModelxml) | Out-Null 
$httpRuntimexml = $machineConfig.CreateElement("httpRuntime") 
$httpRuntimexml.setAttribute("minFreeThreads",90 * $numberOfCores) 
$httpRuntimexml.setAttribute("minLocalRequestFreeThreads",80 * $numberOfCores) 
$node.AppendChild($httpRuntimexml) | Out-Null 
[xml]$systemnetxml = @" 
    <system.net> 
    <connectionManagement> 
     <add address = "*" maxconnection = "$(200 * $numberOfCores)" /> 
    </connectionManagement> 
    </system.net> 
"@ 
$machineConfig.configuration.AppendChild($machineConfig.ImportNode($systemnetxml."system.net",$true)) | Out-Null 
$machineConfig.Save("c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config") 

나는 거의 일년이 고민 한 내가 가지고있는 코드입니다, 나는 그것의 하차했고, 나는 그것이 작동하지 않는 것을 발견 다시오고.

그것은 Machine.config 파일의 원래 형식을 왜곡, 또한 다음과 같은 오류를

enter image description here

있습니다. Machine.config는 Windows Server 2012 R2 파일 시스템에 있으므로 자신의 컴퓨터에서 파일을 테스트하려면 먼저 해당 파일의 백업을 만들어야합니다. 나를 도우려고 노력하는 자신의 기계를 망쳐 놓는 것이 싫어.

도와 주셔서 감사합니다. 미리 감사드립니다.

답변

2

구성 작업을 할 수 있도록 설계된 클래스를 사용하지 않는 이유는 무엇입니까?

$numberOfCores = Get-WmiObject -class win32_processor numberOfCores | Select-Object -ExpandProperty numberOfCores 

$machineConfig = [System.Configuration.ConfigurationManager]::OpenMachineConfiguration() 

$processModel = $machineConfig.SectionGroups['system.web'].ProcessModel 
$processModel.SectionInformation.RevertToParent() 
$processModel.MaxWorkerThreads = 370 
$processModel.MaxIOThreads = 370 
$processModel.MinWorkerThreads = 50 
$processModel.MinIOThreads = 50 

$httpRuntime = $machineConfig.SectionGroups['system.web'].HttpRuntime 
$httpRuntime.MinFreeThreads = 90 * $numberOfCores 
$httpRuntime.MinLocalRequestFreeThreads = 80 * $numberOfCores 

$connectionManagement = $machineConfig.SectionGroups['system.net'].ConnectionManagement 
$connectionManagement.ConnectionManagement.Add((New-Object System.Net.Configuration.ConnectionManagementElement *, (200 * $numberOfCores))) 

$machineConfig.Save() 
+0

내게로 돌아와 주셔서 감사합니다. PetSerAI, 죄송합니다. 다시 연락하지 않으 셨습니다. 방금 당신의 솔루션을 시도하고 부분적으로 작동합니다. System.Web을 올바른 위치에두고 간격과 모든 것이 완벽하지만 system.net 섹션을 전혀 추가하지 않고 값을 곱하지 않습니다. 오류에 대한 스크린 샷을 추가하는 방법을 알아낼 수는 없지만 기본적으로 동일한 오류이며 'op_Multiply'라는 메서드가 포함되어 있지 않습니다. - –

+0

하나의 프로세서 만 있습니까? 당신에게'$ numberOfCores' 콘텐츠 란 무엇입니까? – PetSerAl

+0

안녕하세요 PetSerAI, 코어 수가 다를 수 있으므로 최적화가 다를 수 있으므로 항상 동일한 머신이 아니기 때문에 코어 수가 필요합니다. –