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

op-mode: T6471: add optimized get_config_dict #3628

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

jestabro
Copy link
Contributor

Change Summary

Add a faster get_config_dict for use by op-mode commands. This function avoids the overhead of reading the full config-dict in Config (implicitly used by ConfigTreeQuery) --- the overhead is necessary for config-mode, and is moderated by vyos-configd and caching; it is unnecessary and slow in op-mode, which has no daemon (yet).

Note that a low-level Popen is used instead of a vyos.utils.process function, as it was noticed that as well incurred a heavy performance hit: this will be investigated in a separate task.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes)
  • Migration from an old Vyatta component to vyos-1x, please link to related PR inside obsoleted component
  • Other (please describe):
    Performance improvement available for op-mode scripts.

Related Task(s)

Related PR(s)

Component(s) name

Proposed changes

How to test

Loading a non-trivial config (using vyos-1x/smoketest/configs/bgp-big-as-cloud), test with a Python script, as one would call in a op-mode show command, with interpreter startup and import overhead intact:

#!/usr/bin/env python3

import argparse

from vyos.configquery import ConfigTreeQuery
from vyos.configquery import op_mode_config_dict

parser = argparse.ArgumentParser()
parser.add_argument('--path', nargs='*', help='path to subtree')
parser.add_argument('--op-mode', action='store_true', help='use op-mode version')
parser.add_argument('--no-print', action='store_true', help='no output, for timing test')
args = parser.parse_args()

path = args.path

if args.op_mode:
    out = op_mode_config_dict(path)
else:
    out = ConfigTreeQuery().get_config_dict(path)
        
if not args.no_print:
    print(out)

Results (representative example over repeated runs):

vyos@vyos:~$ time ./config_dict.py --path interfaces ethernet --no-print

real    0m0.373s
user    0m0.156s
sys     0m0.212s
vyos@vyos:~$ time ./config_dict.py --path interfaces ethernet --no-print --op-mode

real    0m0.133s
user    0m0.083s
sys     0m0.050s

Smoketest result

Checklist:

  • I have read the CONTRIBUTING document
  • I have linked this PR to one or more Phabricator Task(s)
  • I have run the components SMOKETESTS if applicable
  • My commit headlines contain a valid Task id
  • My change requires a change to the documentation
  • I have updated the documentation accordingly

@jestabro jestabro self-assigned this Jun 11, 2024
@jestabro jestabro requested a review from a team as a code owner June 11, 2024 03:45
Copy link

github-actions bot commented Jun 11, 2024

👍
No issues in PR Title / Commit Title

@c-po c-po merged commit 0deb393 into vyos:current Jun 11, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants