Skip to content

Provider get() call optimization #306

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

Merged
merged 5 commits into from
Dec 5, 2023

Conversation

seanmil
Copy link
Contributor

@seanmil seanmil commented Oct 31, 2022

This PR adds a caching laying which caches the results returned by the provider's get() method to try to actually minimize the calls to get(), per the Puppet Resource API specifications.

@seanmil seanmil requested a review from a team as a code owner October 31, 2022 20:21
@seanmil
Copy link
Contributor Author

seanmil commented Oct 31, 2022

This is one possible way to address #305, but after a lot of consideration, I feel it is the best approach. The complexity should be kept away from the implementer and given Puppet's current design, I believe this approach will do the trick.

To anticipate the one big question I expect everyone will have: When Puppet is running as a daemonized agent this still receives a new cache per run. It seems that the type and provider are instantiated as part of the transaction during the Puppet run, following the fork(). When Puppet is running as "puppet resource" or "puppet apply" it is a one-shot mode and so it will be a one-transaction cache regardless. I confirmed this in my testing, but I am unsure as to how to write a test for it. Nevertheless, in all of my testing this is a massive improvement for environments where get() is a resource/time heavy operation.

@seanmil seanmil changed the title Get call optimization Provider get() call optimization Oct 31, 2022
@seanmil seanmil force-pushed the get_call_optimization branch from ef00677 to 9a56650 Compare October 31, 2022 21:10
@fraenki
Copy link

fraenki commented Jan 4, 2023

This looks super interesting. @joshcooper Could someone please review this PR? Thanks :)

@fraenki
Copy link

fraenki commented Jan 17, 2023

Hey @seanmil, maybe you could create an issue in the Puppet issue tracker and link to your PR from there? From my experience this may help to get some resource assigned to a PR. :)

@CLAassistant
Copy link

CLAassistant commented Apr 19, 2023

CLA assistant check
All committers have signed the CLA.

@seanmil seanmil force-pushed the get_call_optimization branch from 9a56650 to 66034e4 Compare August 11, 2023 16:49
@LukasAud
Copy link
Contributor

Closing and re-opening PR to re-kick testing run. Interested to see if this is green.

@LukasAud LukasAud closed this Nov 23, 2023
@LukasAud LukasAud reopened this Nov 23, 2023
@LukasAud
Copy link
Contributor

PR has failing/cancelled tests. It also seems to be conflicting with recently merged bugfixes. Needs to be addressed before it can be merged.

In preparation for adding a caching layer, switch all code
accessing the instance variable directly to using the accessors.

As part of this, a long standing bug in the RSAPI and an
acceptance test was corrected for strict behavior on
canonicalization with 'puppet resource'.
This helper class will provide a simple cache for Resource API
provider state to minimize the number of get() calls to the
provider.
Adding the cache layer allows the provider.get() results to be
re-used across multiple Puppet::Resource instantiations for a single
actual provider resource within a given Puppet run.
Ensure that remaining data fetched with the provider get() method
is cached.
@seanmil seanmil force-pushed the get_call_optimization branch from be96084 to 53d764d Compare November 28, 2023 17:26
Copy link
Contributor

@LukasAud LukasAud left a comment

Choose a reason for hiding this comment

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

LGTM. Tested branch against Firewall module to ensure nothing breaks outside our CI.

@LukasAud LukasAud merged commit 8f2f02d into puppetlabs:main Dec 5, 2023
@seanmil seanmil deleted the get_call_optimization branch April 30, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants