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

[dualtor] Improve mux_simulator #16164

Merged
merged 3 commits into from
Dec 25, 2024
Merged

Conversation

lolyu
Copy link
Contributor

@lolyu lolyu commented Dec 19, 2024

Description of PR

Summary:
Fixes # (issue)

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • Test case(new/improvement)

Back port request

  • 202012
  • 202205
  • 202305
  • 202311
  • 202405

Approach

What is the motivation for this PR?

The dualtor nightly suffers from mux simulator timeout issue, and there are always HTTP timeout failures observed.
This PR tries to improve the mux simulator performance:

  1. improve the all mux toggle performance.
  2. improve the mux simulator read/write throughput.

PR 1522 was a quick fix to address, but it was a temporary quick fix.

How did you do it?

  1. run mux simulator with gunicorn instead of its own built-in HTTP server.
    The mux simulator is running with Flask's own built-in HTTP server. Previously, the mux simulator is running with single-threaded mode, which limits its performance && throughput; and the mux simulator is observed stuck in reading from dead connection; PR 1522 proposes a temporary by running mux simulator in threaded mode. The throughput is improved with the threaded approach, but the built-in server limits the tcp listen backlog to 128, and it is designed for development/test purpose and not recommended to be deployed(Flask's deployment doc).
    So let's run the mux simulator with gunicorn:
  • better performance/throughput with customized worker count
  • increased tcp listen backlog
  1. use thread pool to parallel the toggle requests.
    The mux simulator handles the toggle-all request by toggling each mux port one by one, let's use a thread pool to parallel run thoses toggles to further decrease the response time.

How did you verify/test it?

Run the following benchmarks on a dualtor-120 testbed, and compare the performance of:

  • A: the original mux simulator, with Flask built-in server in single-thread mode.
  • B: the mux simulator with Flask built-in server in threaded mode.
  • C: the mux simulator with this PR.
  1. toggle mux status for all mux ports(one request to toggle one mux port):
  • 20 concurrent users, repeated 2000 times
mux simulator version A B C
elapse time 96s 37s 36s
  1. toggle mux status for all mux ports(one request to toggle all mux ports):
  • 1 user, repeated 1 time.
mux simulator version A B C
elapse time 16s 16s 7s

To summarize, mux simulator with this PR has the best performance in toggles.

Any platform specific information?

Supported testbed topology if it's a new test case?

Documentation

Signed-off-by: Longxiang Lyu <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lolyu lolyu requested a review from Copilot December 19, 2024 12:40

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • ansible/roles/vm_set/templates/mux-simulator.service.j2: Language not supported
Comments suppressed due to low confidence (2)

ansible/roles/vm_set/files/mux_simulator.py:955

  • The variable 'default_handler' is not defined, which will raise a NameError. Define 'default_handler' before using it.
app.logger.removeHandler(default_handler)

ansible/roles/vm_set/files/mux_simulator.py:947

  • The new behavior introduced in the 'setup_mux_simulator' function is not covered by tests. Add tests to cover this new behavior.
def setup_mux_simulator(http_port, vm_set, verbose):
@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lolyu lolyu requested a review from Copilot December 20, 2024 07:25
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • ansible/roles/vm_set/templates/mux-simulator.service.j2: Language not supported

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@lolyu lolyu marked this pull request as ready for review December 23, 2024 01:55
@lolyu lolyu requested review from yxieca and wangxin December 23, 2024 03:15
@wangxin wangxin merged commit 9f2412d into sonic-net:master Dec 25, 2024
19 checks passed
mssonicbld pushed a commit to mssonicbld/sonic-mgmt that referenced this pull request Jan 7, 2025
What is the motivation for this PR?
The dualtor nightly suffers from mux simulator timeout issue, and there are always HTTP timeout failures observed.
This PR tries to improve the mux simulator performance:

improve the all mux toggle performance.
improve the mux simulator read/write throughput.
PR 1522 was a quick fix to address, but it was a temporary quick fix.

How did you do it?
run mux simulator with gunicorn instead of its own built-in HTTP server.
The mux simulator is running with Flask's own built-in HTTP server. Previously, the mux simulator is running with single-threaded mode, which limits its performance && throughput; and the mux simulator is observed stuck in reading from dead connection; PR 1522 proposes a temporary by running mux simulator in threaded mode. The throughput is improved with the threaded approach, but the built-in server limits the tcp listen backlog to 128, and it is designed for development/test purpose and not recommended to be deployed(Flask's deployment doc).

So let's run the mux simulator with gunicorn:
better performance/throughput with customized worker count
increased tcp listen backlog
use thread pool to parallel the toggle requests.
The mux simulator handles the toggle-all request by toggling each mux port one by one, let's use a thread pool to parallel run thoses toggles to further decrease the response time.
How did you verify/test it?
Run the following benchmarks on a dualtor-120 testbed, and compare the performance of:

A: the original mux simulator, with Flask built-in server in single-thread mode.
B: the mux simulator with Flask built-in server in threaded mode.
C: the mux simulator with this PR.

toggle mux status for all mux ports(one request to toggle one mux port):
20 concurrent users, repeated 2000 times
mux simulator version	A	B	C
elapse time	96s	37s	36s

toggle mux status for all mux ports(one request to toggle all mux ports):
1 user, repeated 1 time.
mux simulator version	A	B	C
elapse time	16s	16s	7s

To summarize, mux simulator with this PR has the best performance in toggles.

Any platform specific information?
Supported testbed topology if it's a new test case?

Signed-off-by: Longxiang Lyu <[email protected]>
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202405: #16369

mssonicbld pushed a commit that referenced this pull request Jan 7, 2025
What is the motivation for this PR?
The dualtor nightly suffers from mux simulator timeout issue, and there are always HTTP timeout failures observed.
This PR tries to improve the mux simulator performance:

improve the all mux toggle performance.
improve the mux simulator read/write throughput.
PR 1522 was a quick fix to address, but it was a temporary quick fix.

How did you do it?
run mux simulator with gunicorn instead of its own built-in HTTP server.
The mux simulator is running with Flask's own built-in HTTP server. Previously, the mux simulator is running with single-threaded mode, which limits its performance && throughput; and the mux simulator is observed stuck in reading from dead connection; PR 1522 proposes a temporary by running mux simulator in threaded mode. The throughput is improved with the threaded approach, but the built-in server limits the tcp listen backlog to 128, and it is designed for development/test purpose and not recommended to be deployed(Flask's deployment doc).

So let's run the mux simulator with gunicorn:
better performance/throughput with customized worker count
increased tcp listen backlog
use thread pool to parallel the toggle requests.
The mux simulator handles the toggle-all request by toggling each mux port one by one, let's use a thread pool to parallel run thoses toggles to further decrease the response time.
How did you verify/test it?
Run the following benchmarks on a dualtor-120 testbed, and compare the performance of:

A: the original mux simulator, with Flask built-in server in single-thread mode.
B: the mux simulator with Flask built-in server in threaded mode.
C: the mux simulator with this PR.

toggle mux status for all mux ports(one request to toggle one mux port):
20 concurrent users, repeated 2000 times
mux simulator version	A	B	C
elapse time	96s	37s	36s

toggle mux status for all mux ports(one request to toggle all mux ports):
1 user, repeated 1 time.
mux simulator version	A	B	C
elapse time	16s	16s	7s

To summarize, mux simulator with this PR has the best performance in toggles.

Any platform specific information?
Supported testbed topology if it's a new test case?

Signed-off-by: Longxiang Lyu <[email protected]>
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.

4 participants