Improve facts gathering while creating SonicHost instance#21442
Merged
StormLiangMS merged 2 commits intosonic-net:masterfrom Mar 26, 2026
Merged
Improve facts gathering while creating SonicHost instance#21442StormLiangMS merged 2 commits intosonic-net:masterfrom
StormLiangMS merged 2 commits intosonic-net:masterfrom
Conversation
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
lolyu
reviewed
Nov 26, 2025
Collaborator
lolyu
left a comment
There was a problem hiding this comment.
what's the running time usingsonic_basic_facts?
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
I didn't measure the running time of |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
b316cc9 to
6bc1457
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
StormLiangMS
previously approved these changes
Jan 13, 2026
Collaborator
|
One more question, do we get this enhancement tested on a multi asic devices? |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
Yes. Multi-ASIC is covered in PR testing. |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
|
/azpw run |
Collaborator
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
21f2e1e to
9cc147a
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
The SonicHost __init__ method needs to run multiple commands on the SONiC host to gather some basic facts. Execution of each command has some overhead. To improve the performance, multi threads were introduced to run the commands in parallel. It looks like a over kill. In some scenarios, it will cause multiple threads in multiple threads and could make things even more complicated. What's more, getting versions still need to run commands on SONiC host multiple times. To simplify the procedure of gathering facts and ensure performance at the same time, this change introduced a new customized ansible module `sonic_basic_facts.py`. This module will be executed on SONiC host and use various methods to directly gather facts: * call sonic_py_common library * read from config_db using DB connector * read files The time requred to run the `sonic_basic_facts` module is similiar as running a single command on the SONiC device. By this method, the code for gathering facts is significantly simplified with even better performance. When there is no cache, run a script may need 10 seconds less. The __init__ method of MultiAsicSonicHost is also updated to use gathered facts instead of running the config_facts module which is a little bit slow and produces too much log. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
Signed-off-by: Xin Wang <xiwang5@microsoft.com>
9cc147a to
843f73c
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
ravaliyel
pushed a commit
to ravaliyel/sonic-mgmt
that referenced
this pull request
Mar 27, 2026
…21442) * Improve facts gathering while creating SonicHost instance The SonicHost __init__ method needs to run multiple commands on the SONiC host to gather some basic facts. Execution of each command has some overhead. To improve the performance, multi threads were introduced to run the commands in parallel. It looks like a over kill. In some scenarios, it will cause multiple threads in multiple threads and could make things even more complicated. What's more, getting versions still need to run commands on SONiC host multiple times. To simplify the procedure of gathering facts and ensure performance at the same time, this change introduced a new customized ansible module `sonic_basic_facts.py`. This module will be executed on SONiC host and use various methods to directly gather facts: * call sonic_py_common library * read from config_db using DB connector * read files The time requred to run the `sonic_basic_facts` module is similiar as running a single command on the SONiC device. By this method, the code for gathering facts is significantly simplified with even better performance. When there is no cache, run a script may need 10 seconds less. The __init__ method of MultiAsicSonicHost is also updated to use gathered facts instead of running the config_facts module which is a little bit slow and produces too much log. Signed-off-by: Xin Wang <xiwang5@microsoft.com> * Improve robustness of getting router_subtype key Signed-off-by: Xin Wang <xiwang5@microsoft.com> --------- Signed-off-by: Xin Wang <xiwang5@microsoft.com>
This file contains hidden or 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
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.
Description of PR
Summary:
Fixes # (issue)
Type of change
Back port request
Approach
What is the motivation for this PR?
The SonicHost init method needs to run multiple commands on the SONiC host to gather some basic facts. Execution of each command has some overhead. To improve the performance, multi threads were introduced to run the commands in parallel. It looks like an over kill. In some scenarios, it will cause multiple threads in multiple threads and could make things even more complicated. What's more, getting versions still need to run commands on SONiC host multiple times.
How did you do it?
To simplify the procedure of gathering facts and ensure performance at the same time, this change introduced a new customized ansible module
sonic_basic_facts.py. This module will be executed on SONiC host and use various methods to directly gather facts:sonic_basic_factsmodule is similiar as running a single command on the SONiC device. By this method, the code for gathering facts is significantly simplified with even better performance. When there is no cache, run a script may need 10 seconds less.The init method of MultiAsicSonicHost is also updated to use gathered facts instead of running the config_facts module which is a little bit slow and produces too much log.
How did you verify/test it?
Tested on KVM testbed.
Any platform specific information?
Supported testbed topology if it's a new test case?
Documentation