Skip to content

[action] [PR:22254] sonic-yang-mgmt: Generic Config Updater - performance dependencies#1711

Merged
mssonicbld merged 1 commit intoAzure:202412from
mssonicbld:cherry/msft-202412/22254
Oct 19, 2025
Merged

[action] [PR:22254] sonic-yang-mgmt: Generic Config Updater - performance dependencies#1711
mssonicbld merged 1 commit intoAzure:202412from
mssonicbld:cherry/msft-202412/22254

Conversation

@mssonicbld
Copy link
Collaborator

Why I did it

Important: Please review each commit (including commit message) individually. Looking at the patch-set as a whole may cause confusion.

Generic Config Updater (GCU) is notoriously slow. These patches add some helpers for the GCU overhaul (mostly in sonic-utilities) in order to facilitate the optimizations. These changes are in sonic-yang-mgmt plus a patch to libyang 1.

Changes include:

  • Libyang v1 was not exposing must data for leaf nodes (like it does for other node types). Patch to correct this oversight.
  • Loading of sonic configuration data should not mutate the user-provided data, this forces callers to know they need to deepcopy the data, plus in most instances data won't be mutated.
  • sonic-yang-mgmt test models should more closely mimic real sonic yang models as we can't implement other features that assume this otherwise (sonic mandates that the top-level container has the same name as the module).
  • Import sonic configdb<>yang xpath conversion from sonic-utilities as this should be shared code. 90% of this code is copied from the original source but does contain some bugfixes and enhancements including caching.
  • Make find_schema_dependencies() public, plus add the ability to find dependencies recursively. This implementation is caching.
  • Add new find_schema_must_count(), with recursive capabilities to find if a node (and its children) have must clauses. This implementation is caching.

sonic-utilities PR: sonic-net/sonic-utilities#3831

Stats below ... (stats need both this and the sonic-utilities PR to be relevant)...

Original Performance:
Dry Run:

time sudo config replace -d ./config_db.json
...
real	2m51.588s
user	2m23.777s
sys	0m25.300s

Full:

time sudo config replace ./config_db.json
...
real	14m53.772s
user	12m2.376s
sys	2m8.908s

With Patch:
Dry Run:

time sudo config replace -d ./config_db.json
...
real	0m59.602s
user	0m56.434s
sys	0m2.110s

Full:

time sudo config replace ./config_db.json
...
real	1m54.303s
user	0m58.482s
sys	0m2.545s

So that's roughly 3x improvement for dry-run, and 7.5x improvement for full commit. There is room for improvement on the full commit due to a sleep(1) being used between each patch because of a race condition found in the prior code (that was hidden due to a costly sanity check that has been removed).

Work item tracking

How I did it

Gathered profiling data using cProfile and evaluated where the largest gains could be had.

How to verify it

This patch is standalone as it will not cause any issues in other projects which use sonic-yang-mgmt or libyang, however the performance benefits are in sonic-utilities. Apply both this commit and the sonic-utilities PR to a local branch, build and run sonic-utilities tests. Then create a full image, load it onto a DUT (with default configuration), and use the attached
config_db.json to attempt a config replace operation (tested on Dell S5248F).

Which release branch to backport (provide reason below if selected)

  • 202411

Tested branch (Please provide the tested image version)

master as of 20250521

Description for the changelog

sonic-yang-mgmt: Generic Config Updater - performance dependencies

Link to config_db schema for YANG module changes

N/A

A picture of a cute animal (not mandatory but encouraged)

Fixes sonic-net/sonic-buildimage#22372
Signed-off-by: Brad House bhouse@nexthop.ai

#### Why I did it

***Important***: Please review each commit (including commit message) individually.  Looking at the patch-set as a whole may cause confusion.

Generic Config Updater (GCU) is notoriously slow.  These patches add some helpers for the GCU overhaul (mostly in sonic-utilities) in order to facilitate the optimizations.  These changes are in sonic-yang-mgmt plus a patch to libyang 1.

Changes include:
 * Libyang v1 was not exposing `must` data for leaf nodes (like it does for other node types).  Patch to correct this oversight.
 * Loading of sonic configuration data should not mutate the user-provided data, this forces callers to know they need to deepcopy the data, plus in most instances data won't be mutated.
 * sonic-yang-mgmt test models should more closely mimic real sonic yang models as we can't implement other features that assume this otherwise (sonic mandates that the top-level container has the same name as the module).
 * Import `sonic configdb`<>`yang xpath` conversion from sonic-utilities as this should be shared code.  90% of this code is copied from the original source but does contain some bugfixes and enhancements including caching.
 * Make `find_schema_dependencies()` public, plus add the ability to find dependencies recursively.  This implementation is caching.
 * Add new `find_schema_must_count()`, with recursive capabilities to find if a node (and its children) have must clauses. This implementation is caching.

sonic-utilities PR: sonic-net/sonic-utilities#3831

Stats below ... (stats need both this and the sonic-utilities PR to be relevant)...

<ins>**Original Performance:**</ins>
Dry Run:
```
time sudo config replace -d ./config_db.json
...
real	2m51.588s
user	2m23.777s
sys	0m25.300s
```

Full:
```
time sudo config replace ./config_db.json
...
real	14m53.772s
user	12m2.376s
sys	2m8.908s
```

<ins>**With Patch**:</ins>
Dry Run:
```
time sudo config replace -d ./config_db.json
...
real	0m59.602s
user	0m56.434s
sys	0m2.110s
```

Full:
```
time sudo config replace ./config_db.json
...
real	1m54.303s
user	0m58.482s
sys	0m2.545s
```

So that's roughly 3x improvement for dry-run, and 7.5x improvement for full commit.  There is room for improvement on the full commit due to a `sleep(1)` being used between each patch because of a race condition found in the prior code (that was hidden due to a costly sanity check that has been removed).

##### Work item tracking

#### How I did it

Gathered profiling data using cProfile and evaluated where the largest gains could be had.

#### How to verify it

This patch is standalone as it will not cause any issues in other projects which use sonic-yang-mgmt or libyang, however the performance benefits are in sonic-utilities.   Apply both this commit and the sonic-utilities PR to a local branch, build and run sonic-utilities tests.  Then create a full image, load it onto a DUT (with default configuration), and use the attached
[config_db.json](https://github.com/user-attachments/files/19635712/config_db.json) to attempt a `config replace` operation (tested on Dell S5248F).

#### Which release branch to backport (provide reason below if selected)

- [x] 202411

#### Tested branch (Please provide the tested image version)

master as of 20250521

#### Description for the changelog

sonic-yang-mgmt: Generic Config Updater - performance dependencies

#### Link to config_db schema for YANG module changes
N/A

#### A picture of a cute animal (not mandatory but encouraged)

Fixes sonic-net/sonic-buildimage#22372
Signed-off-by: Brad House <bhouse@nexthop.ai>
@mssonicbld
Copy link
Collaborator Author

Original PR: sonic-net/sonic-buildimage#22254

@mssonicbld
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@r12f
Copy link

r12f commented Oct 17, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@r12f
Copy link

r12f commented Oct 19, 2025

bgp sanity check failing during the test, likely testbed problem:
image

@mssonicbld mssonicbld merged commit 093126c into Azure:202412 Oct 19, 2025
17 checks passed
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.

2 participants