Dsc

從作為 ServerManager.DeploymentProvider.dll 一部分的 WMI 提供程序“deploymentprovider”觀察到高 CPU 使用率

  • October 16, 2015

我正在使用 powerShell Desired State Configuration 在伺服器機器上測試/設置 Windows 功能。我擁有的是 78 個 WindowsFeature 資源,如果需要,可以檢查和安裝。我觀察到的是在 LCM(本地配置管理器)執行和檢查配置時 CPU 使用率很高。我進行了一些調查,發現 WMI 提供程序“deploymentprovider”是負責 WindowsFeature 資源的 ServerManager.DeploymentProvider.dll 的一部分。所以問題是,有沒有人經歷過這個問題並以某種方式解決了它?

提前致謝。

78個WindowsFeature資源很多。您可以嘗試通過使用Script資源並自己編寫程式碼(或創建自定義資源)來合併檢查。花費的大部分 CPU 時間可能是成本,所以如果你一次檢查所有 78 個,它應該會快得多。

   Configuration cWindowsFeatures {
       param
       (
           [parameter(Mandatory=$true)]
           $WindowsFeatures

       )
       Import-DscResource -ModuleName PSDesiredStateConfiguration
       $i=0
       foreach($WindowsFeature in $WindowsFeatures.keys)
       {
           $ResourceName="WindowsFeature$($i)"
           WindowsFeature "$ResourceName"
           {
               Name = "$WindowsFeature"
               Ensure = $WindowsFeatures["$WindowsFeature"][0]
               IncludeAllSubFeature = $WindowsFeatures["$WindowsFeature"][1]
           }
           $i++
       }
}


function Get-TargetResource 
{
   [CmdletBinding()]
   [OutputType([System.Collections.Hashtable])]
   param 
   (      
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string]
       $Id,
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string[]]
       $WindowsFeature
   )

   $retValue=@{}
   $InstalledFeatures=(Get-WindowsFeature -Name $WindowsFeature | Where-Object {$_.InstallState -eq "Installed"}).Name
   $retValue.WindowsFeature=$InstalledFeatures
   return $retValue
}


function Set-TargetResource 
{
   [CmdletBinding()]
   param 
   (      
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string]
       $Id,
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string[]]
       $WindowsFeature
   )

   Install-WindowsFeature -Name $WindowsFeature

}

# The Test-TargetResource cmdlet is used to validate if the role or feature is in a state as expected in the instance document.
function Test-TargetResource 
{
   [CmdletBinding()]
   [OutputType([System.Boolean])]
   param 
   (      
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string]
       $Id,
       [parameter(Mandatory = $true)]
       [ValidateNotNullOrEmpty()]
       [string[]]
       $WindowsFeature
   )

   $return=$false
   $InstalledFeatures=(Get-TargetResource -Id $Id -WindowsFeature $WindowsFeature).WindowsFeature
   if($InstalledFeatures.Count -eq $WindowsFeature.Count)
   {
       Write-Verbose -Message "Seems like all features are already installed"
       $return=$true
   }
   else
   {
       Write-Verbose -Message "Some features are still missing. It'll be necessary to installed them."
   }
   return $return

}


Export-ModuleMember -function Get-TargetResource, Set-TargetResource, Test-TargetResource




Configuration app0 { 
   param (
           [parameter(Mandatory=$true)]
           [string]$MachineName
          )

   Import-DscResource -ModuleNAme cCompositeConfigurationResources
   Import-DscResource -ModuleName cPSDesiredStateConfiguration

   Node $AllNodes.Where{$_.Nodename -eq "$MachineName"}.Nodename {
       #region WindowsFeatures
       cWindowsFeatures cWindowsFeatures0
       {
           WindowsFeatures=$Node.WindowsFeatures
       }
       #endregion WindowsFeatures
   }
}


Configuration app1 { 
   param (
           [parameter(Mandatory=$true)]
           [string]$MachineName
          )

   Import-DscResource -ModuleName cPSDesiredStateConfiguration

   Node $AllNodes.Where{$_.Nodename -eq "$MachineName"}.Nodename {
       #region WindowsFeatures
       cWindowsFeature cWindowsFeature0
       {
           ID = "cWindowsFeature0"
           WindowsFeature=$Node.WindowsFeatures.Keys
       }
       #endregion WindowsFeatures
   }
}

app0 -ConfigurationData $ConfigurationData -OutputPath C:\DSC0 -MachineName app1
app1 -ConfigurationData $ConfigurationData -OutputPath C:\DSC1 -MachineName app1

Start-DSCConfiguration -Path c:\dsc0 -Wait -Force
Start-Sleep 1
Start-DSCConfiguration  -Wait -Force -UseExisting
(Get-DSCConfigurationStatus).DurationInSeconds
Start-DSCConfiguration -Path c:\dsc1 -Wait -Force
Start-Sleep 1
Start-DSCConfiguration  -Wait -Force -UseExisting
(Get-DSCConfigurationStatus).DurationInSeconds



   Directory: C:\DSC0


Mode                LastWriteTime         Length Name                                                                                                                                                                          
----                -------------         ------ ----                                                                                                                                                                          
-a----       10/16/2015   2:23 PM          76182 app1.mof                                                                                                                                                                      


   Directory: C:\DSC1


Mode                LastWriteTime         Length Name                                                                                                                                                                          
----                -------------         ------ ----                                                                                                                                                                          
-a----       10/16/2015   2:23 PM           5152 app1.mof                                                                                                                                                                      
14
0

這是我的程式碼和最終測試結果。find 範例需要大約 80 倍的時間來測試資源。因此,將資源數量保持在最低水平並處理程式碼中的所有內容是值得的。

引用自:https://serverfault.com/questions/728557