From 8103341388ac4a6accf56019fb287819a703777d Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 22 Jul 2019 14:35:35 +0200 Subject: [PATCH] Improved performance while loading All Perf Counter instances Improved performance for loading all performance counter instances with '*' by adding the sleep after the initialisation of all counters instead for each single one without having to handle the sleep skip manually --- lib/core/perfcounter/New-IcingaPerformanceCounter.psm1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/core/perfcounter/New-IcingaPerformanceCounter.psm1 b/lib/core/perfcounter/New-IcingaPerformanceCounter.psm1 index fe24ddc..83bebfe 100644 --- a/lib/core/perfcounter/New-IcingaPerformanceCounter.psm1 +++ b/lib/core/perfcounter/New-IcingaPerformanceCounter.psm1 @@ -67,12 +67,18 @@ $CounterInstances = New-Object System.Diagnostics.PerformanceCounterCategory($UseCounterCategory); foreach ($instance in $CounterInstances.GetInstanceNames()) { [string]$NewCounterName = $Counter.Replace('*', $instance); - $NewCounter = New-IcingaPerformanceCounterObject -FullName $NewCounterName -Category $UseCounterCategory -Counter $UseCounterName -Instance $instance -SkipWait $SkipWait; + $NewCounter = New-IcingaPerformanceCounterObject -FullName $NewCounterName -Category $UseCounterCategory -Counter $UseCounterName -Instance $instance -SkipWait $TRUE; $AllCountersIntances += $NewCounter; } } catch { return (New-IcingaPerformanceCounterNullObject -FullName $Counter -ErrorMessage ([string]::Format('Failed to deserialize instances for counter "{0}". Exception: "{1}".', $Counter, $_.Exception.Message))); } + + # If we load multiple instances, we should add a global wait here instead of a wait for each single instance + # This will speed up CPU loading for example with plenty of cores avaiable + if ($SkipWait -eq $FALSE) { + Start-Sleep -Milliseconds 500; + } # Add the parent counter including the array of Performance Counters to our # caching mechanism and return the New-IcingaPerformanceCounterResult object for usage