-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from Icinga/feature/add_code_cache_for_faster…
…_framework_loading Experimental: Adds code caching for faster framework loading ## Current Situation Currently the entire Framework is taking a huge amount of time to load the files. This causes several issues: * Slow loading increases the runtime of checks * High CPU usage for the initial loading of the Framework * High CPU usage over a longer period of time, cause more impcact on the systems ## Possible solutions ### Add caching To reduce the impact for the Framework loading, we could add a cache file containing all Cmdlets, Enums and Functions allowing us to import file on initialization instead of having of to search for all `.psm1` files and load them one by one ### Use Nested Modules for PowerShell Plugins PowerShell plugins right now are using `Use-IcingaPlugins` which searchs for all `.psm1` files inside the plugin folder to load them. We should use `NestedModules` here, as the overall impact is lower. On Framework side we can't do this how ever without loading times to explode. Plugins are tracked [at issue #87 here](Icinga/icinga-powershell-plugins#87) ## Current Status **Mitigated** ## Usage You can enable/disable this feature by using `Enable-IcingaFrameworkCodeCache` and `Disable-IcingaFrameworkCodeCache`. Updating the cache is done with `Write-IcingaFrameworkCodeCache`
- Loading branch information
Showing
8 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<# | ||
.SYNOPSIS | ||
Disables the experimental feature to cache all functions into a single file, | ||
allowing quicker loading times of the Icinga PowerShell Framework | ||
.DESCRIPTION | ||
Disables the experimental feature to cache all functions into a single file, | ||
allowing quicker loading times of the Icinga PowerShell Framework | ||
.FUNCTIONALITY | ||
Experimental: Disables the Icinga for Windows code caching | ||
.EXAMPLE | ||
PS>Disable-IcingaFrameworkCodeCache; | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function Disable-IcingaFrameworkCodeCache() | ||
{ | ||
Set-IcingaPowerShellConfig -Path 'Framework.Experimental.CodeCaching' -Value $FALSE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<# | ||
.SYNOPSIS | ||
Enables the experimental feature to cache all functions into a single file, | ||
allowing quicker loading times of the Icinga PowerShell Framework | ||
.DESCRIPTION | ||
Enables the experimental feature to cache all functions into a single file, | ||
allowing quicker loading times of the Icinga PowerShell Framework | ||
.FUNCTIONALITY | ||
Experimental: Enables the Icinga for Windows code caching | ||
.EXAMPLE | ||
PS>Enable-IcingaFrameworkCodeCache; | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function Enable-IcingaFrameworkCodeCache() | ||
{ | ||
Set-IcingaPowerShellConfig -Path 'Framework.Experimental.CodeCaching' -Value $TRUE; | ||
|
||
Write-IcingaConsoleWarning 'This is an experimental feature and might cause some side effects during usage. Please use this function with caution. Please run "Write-IcingaFrameworkCodeCache" in addition to ensure your cache is updated. This should be done after each update of the Framework in case the feature was disabled during the update run.'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
.SYNOPSIS | ||
Fetches the current enable/disable state of the experimental feature | ||
for caching the Icinga PowerShell Framework code | ||
.DESCRIPTION | ||
Fetches the current enable/disable state of the experimental feature | ||
for caching the Icinga PowerShell Framework code | ||
.FUNCTIONALITY | ||
Experimental: Get the current code caching configuration of the | ||
Icinga PowerShell Framework | ||
.EXAMPLE | ||
PS>Get-IcingaFrameworkCodeCache; | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
.OUTPUTS | ||
System.Boolean | ||
#> | ||
|
||
function Get-IcingaFrameworkCodeCache() | ||
{ | ||
$CodeCaching = Get-IcingaPowerShellConfig -Path 'Framework.Experimental.CodeCaching'; | ||
|
||
if ($null -eq $CodeCaching) { | ||
return $FALSE; | ||
} | ||
|
||
return $CodeCaching; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters