mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Fix GC collection on every REST connection
This commit is contained in:
parent
6838a4f6ef
commit
9a2e793be8
8 changed files with 34 additions and 7 deletions
|
|
@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
|
|||
* [#480](https://github.com/Icinga/icinga-powershell-framework/pull/480) Fixes service locking during Icinga Agent upgrade and ensures errors on service management are caught and printed with internal error handling
|
||||
* [#483](https://github.com/Icinga/icinga-powershell-framework/issues/483) Fixes REST-Api SSL certificate lookup from the Icinga Agent, in case a custom hostname was used or in certain domain environments were domain is not matching DNS domain
|
||||
* [#490](https://github.com/Icinga/icinga-powershell-framework/pull/490) Fixes the command `Uninstall-IcingaComponent` for the `service` component which is not doing anything
|
||||
* [#491](https://github.com/Icinga/icinga-powershell-framework/issues/491) Fixes GC collection with `Optimize-IcingaForWindowsMemory` for every incoming REST connection call
|
||||
* [#497](https://github.com/Icinga/icinga-powershell-framework/pull/497) Fixes loop sleep for idle REST-Api threads by replacing them with [BlockingCollection](https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.blockingcollection-1?view=net-6.0) [ConcurrentQueue](https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1?view=net-6.0)
|
||||
|
||||
### Enhancements
|
||||
|
|
|
|||
|
|
@ -62,5 +62,6 @@ function New-IcingaEnvironmentVariable()
|
|||
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
|
||||
$Global:Icinga.Protected.Add('Minimal', $FALSE);
|
||||
$Global:Icinga.Protected.Add('ThreadName', '');
|
||||
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,10 @@
|
|||
properly
|
||||
.PARAMETER ClearErrorStack
|
||||
Also clears the current error stack to free additional memory
|
||||
.PARAMETER SmartGC
|
||||
Ensures that memory is not flushed whenever this function is called, but instead
|
||||
every 30 attempts this function is called to reduce CPU load. Only works for
|
||||
PowerShell sessions with "$Global:Icinga.Protected.ThreadName" being set
|
||||
.EXAMPLE
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
.EXAMPLE
|
||||
|
|
@ -21,9 +25,26 @@
|
|||
function Optimize-IcingaForWindowsMemory()
|
||||
{
|
||||
param (
|
||||
[switch]$ClearErrorStack = $FALSE
|
||||
[switch]$ClearErrorStack = $FALSE,
|
||||
[switch]$SmartGC = $FALSE
|
||||
);
|
||||
|
||||
if ([string]::IsNullOrEmpty($Global:Icinga.Protected.ThreadName) -eq $FALSE -And $SmartGC) {
|
||||
if ($Global:Icinga.Protected.GarbageCollector.ContainsKey($Global:Icinga.Protected.ThreadName) -eq $FALSE) {
|
||||
$Global:Icinga.Protected.GarbageCollector.Add($Global:Icinga.Protected.ThreadName, 0);
|
||||
|
||||
return;
|
||||
} else {
|
||||
$Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] += 1;
|
||||
}
|
||||
|
||||
if ($Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] -le 30) {
|
||||
return;
|
||||
}
|
||||
|
||||
$Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] = 0;
|
||||
}
|
||||
|
||||
# Clear all errors within our error stack
|
||||
if ($ClearErrorStack) {
|
||||
$Error.Clear();
|
||||
|
|
|
|||
|
|
@ -20,9 +20,12 @@ function Add-IcingaForWindowsDaemon()
|
|||
}
|
||||
|
||||
while ($TRUE) {
|
||||
Start-Sleep -Seconds 1;
|
||||
Start-Sleep -Seconds 10;
|
||||
|
||||
# Handle possible threads being frozen
|
||||
Suspend-IcingaForWindowsFrozenThreads;
|
||||
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ function New-IcingaForWindowsRESTApi()
|
|||
while ($TRUE) {
|
||||
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack;
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
|
||||
|
||||
$Connection = Open-IcingaTCPClientConnection `
|
||||
-Client (New-IcingaTCPClient -Socket $Socket) `
|
||||
|
|
|
|||
|
|
@ -101,6 +101,6 @@ function New-IcingaForWindowsRESTThread()
|
|||
Close-IcingaTCPConnection -Client $Connection.Client;
|
||||
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack;
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ function Add-IcingaServiceCheckDaemon()
|
|||
}
|
||||
}
|
||||
|
||||
Optimize-IcingaForWindowsMemory;
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -SmartGC;
|
||||
|
||||
Start-Sleep -Seconds 10;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ function Add-IcingaServiceCheckTask()
|
|||
Clear-IcingaCheckSchedulerEnvironment;
|
||||
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack;
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
@ -133,6 +133,6 @@ function Add-IcingaServiceCheckTask()
|
|||
# Reset certain values from the scheduler environment
|
||||
Clear-IcingaServiceCheckDaemonEnvironment;
|
||||
# Force Icinga for Windows Garbage Collection
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack;
|
||||
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue