Skip to content

Conversation

@wangxin
Copy link
Collaborator

@wangxin wangxin commented Nov 26, 2025

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

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:

  • 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.

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

@wangxin wangxin requested a review from lolyu November 26, 2025 06:28
@wangxin wangxin requested a review from yxieca as a code owner November 26, 2025 06:28
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wangxin wangxin closed this Nov 26, 2025
@wangxin wangxin reopened this Nov 26, 2025
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@lolyu lolyu left a comment

Choose a reason for hiding this comment

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

what's the running time usingsonic_basic_facts?

@wangxin
Copy link
Collaborator Author

wangxin commented Nov 27, 2025

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@wangxin
Copy link
Collaborator Author

wangxin commented Nov 27, 2025

what's the running time usingsonic_basic_facts?

I didn't measure the running time of sonic_basic_facts. Generally it is similar as running a simple command on DUT.
Overall, when there is no cache, a script execution time can be 20 seconds less. When there is already cache, the time saving is just around 2 seconds.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

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 <[email protected]>
@wangxin wangxin force-pushed the improve-sonichost-init branch from b316cc9 to 6bc1457 Compare December 1, 2025 02:43
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants