-
Notifications
You must be signed in to change notification settings - Fork 123
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
ops/main.py: Use CSafeLoader #325
Merged
Merged
Conversation
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
Testing shows that on a modest yaml file, it can be 2ms instead of 25ms to load a config.yaml. (postgresql's config.yaml). By default 'yaml.safe_load' doesn't use the C loader (neither does yaml.load).
chipaca
approved these changes
Jun 10, 2020
Add a Debug level message if yaml doesn't have the C extensions available.
actions_metadata = None | ||
|
||
if not yaml.__with_libyaml__: | ||
logger.debug('yaml does not have libyaml extensions, using slower pure Python yaml loader') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of logging this to the user?
When not using cyaml, loading of YAML files is about 10x slower (reading
postgresql's config.yaml is ~25ms vs 2ms). So it is potentially a
significant performance degradation. it is logged at DEBUG level so that if
people are digging into things they have a chance of noticing and doing
something about it, but isn't something that will spam the console in the
common case.
Since we read config.yaml and metadata.yaml on *every* hook invocation, it
is a nontrivial amount of time. It isn't something that we do on every
interaction with Juju (relation-get, relation-set, juju-log, etc) so it
isn't bad enough to be a WARNING IMO, but it is something that I don't
think we want to be silent about.
…On Fri, Jun 12, 2020 at 3:52 PM Facundo Batista ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In ops/main.py
<#325 (comment)>:
> @@ -288,8 +277,16 @@ def main(charm_class):
dispatcher = _Dispatcher(charm_dir)
dispatcher.run_any_legacy_hook()
- metadata, actions_metadata = _load_metadata(charm_dir)
- meta = ops.charm.CharmMeta(metadata, actions_metadata)
+ metadata = (charm_dir / 'metadata.yaml').read_text()
+ actions_meta = charm_dir / 'actions.yaml'
+ if actions_meta.exists():
+ actions_metadata = actions_meta.read_text()
+ else:
+ actions_metadata = None
+
+ if not yaml.__with_libyaml__:
+ logger.debug('yaml does not have libyaml extensions, using slower pure Python yaml loader')
What's the point of logging this to the user?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#325 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABRQ7NGLJ3GSYD3G5XDRV3RWIJJBANCNFSM4N2IJG4Q>
.
|
facundobatista
approved these changes
Jun 16, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Resolve the conflict in main, and include the os import.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Testing shows that on a modest yaml file, it can be 2ms instead of 25ms
to load a config.yaml. (postgresql's config.yaml).
By default 'yaml.safe_load' doesn't use the C loader (neither does
yaml.load).
This also unifies the code path that loads YAML for both main.main() and our test suites.