Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added DscResourceCache #432

Merged
merged 24 commits into from
May 16, 2024
Merged

Added DscResourceCache #432

merged 24 commits into from
May 16, 2024

Conversation

anmenaga
Copy link
Collaborator

@anmenaga anmenaga commented May 8, 2024

PR Summary

Added caching of Get-DscResource results to PSDscAdapter, reducing execution time for classic PS DSC resources:

Before:

PS C:\DSCv3> (Measure-Command {dsc.exe resource list -a "Microsoft.DSC/PowerShell"}).TotalSeconds
8.0908457
PS C:\DSCv3> (Measure-Command {"{'Name':'TestPSRepository1'}" | dsc resource set -r 'PSTestModule/TestPSRepository'}).TotalSeconds
12.1434988

After:

PS C:\DSCv3> (Measure-Command {dsc.exe resource list -a "Microsoft.DSC/PowerShell"}).TotalSeconds
2.3765501
PS C:\DSCv3> (Measure-Command {"{'Name':'TestPSRepository1'}" | dsc resource set -r 'PSTestModule/TestPSRepository'}).TotalSeconds
6.6152832
  1. Cache location is in user-specific folders:
    on Windows - $env:LocalAppData\dsc\PSAdapterCache.json
    for WindowsPS adapter - $env:LocalAppData\dsc\WindowsPSAdapterCache.json
    on Linux/Mac - $env:HOME/.dsc/PSAdapterCache.json

  2. Checks for stale cache:
    a) cache contains every subfolder (+1 level deep to account for new module versions) in PSModulePath (i.e. all visible module paths), which is analyzed when cache is accessed.
    I.e. if PSModulePath changes or a module is added/removed from existing PSModulePath, that is detected, and cache is rebuilt.
    b) for each resource type cache also contains all "*.ps1","*.psd1","*psm1","*.mof" files under $dscResource.ParentPath and their LastWrite timestamps. On accessing the cache LastWrite times of live files is compared with those in cache and cache is rebuilt if they are different.

@anmenaga anmenaga marked this pull request as draft May 8, 2024 07:29
@anmenaga anmenaga marked this pull request as ready for review May 8, 2024 07:29
@anmenaga anmenaga marked this pull request as draft May 8, 2024 07:32
@anmenaga anmenaga marked this pull request as ready for review May 9, 2024 01:40
Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting on changes requested during design review

@anmenaga
Copy link
Collaborator Author

PR description updated; @SteveL-MSFT please take another look.

powershell-adapter/psDscAdapter/psDscAdapter.psm1 Outdated Show resolved Hide resolved
powershell-adapter/Tests/powershellgroup.config.tests.ps1 Outdated Show resolved Hide resolved
powershell-adapter/psDscAdapter/psDscAdapter.psm1 Outdated Show resolved Hide resolved
powershell-adapter/psDscAdapter/psDscAdapter.psm1 Outdated Show resolved Hide resolved
powershell-adapter/psDscAdapter/psDscAdapter.psm1 Outdated Show resolved Hide resolved
anmenaga and others added 2 commits May 15, 2024 16:31
Co-authored-by: Steve Lee <slee@microsoft.com>
Co-authored-by: Steve Lee <slee@microsoft.com>
Comment on lines +60 to +61
if ($PSVersionTable.PSVersion.Major -le 5) {
Join-Path $env:LocalAppData "dsc\WindowsPSAdapterCache.json"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this need to be in the if ($IsWindows) block?

Copy link
Collaborator Author

@anmenaga anmenaga May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows PS does not know "$IsWindows" var; it evaluates to $null there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, forgot about that.

@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue May 16, 2024
Merged via the queue into PowerShell:main with commit 1572460 May 16, 2024
4 checks passed
@anmenaga anmenaga mentioned this pull request May 30, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants