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

fix(anta): Add Semaphore to AsyncEOSDevice #1042

Merged
merged 4 commits into from
Feb 21, 2025

Conversation

carl-baillargeon
Copy link
Contributor

Description

Add a Semaphore of 100 per device to avoid sending too many commands/requests to HTTPX. HTTPX has a default max_connections of 100 so we respect that to avoid high-concurrency performance issues.

Related to:

encode/httpx#3215
encode/httpcore#928
encode/httpcore#929

Benchmarks on i7-12800H, 32GB RAM, 1048576 file descriptors

With Semaphore:

2025-02-13 17:28:22,109 - INFO - Running benchmarks with 64 commands and max_connections=100
2025-02-13 17:28:22,110 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:28:22,110 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:28:23,602 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 1.492405 seconds
2025-02-13 17:28:23,602 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:28:23,603 - INFO - Running benchmarks with 640 commands and max_connections=100
2025-02-13 17:28:23,603 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:28:23,603 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:28:27,111 - INFO - Process Resource Usage - CPU: 20.00%, Memory: 0.16%
2025-02-13 17:28:32,112 - INFO - Process Resource Usage - CPU: 16.60%, Memory: 0.18%
2025-02-13 17:28:37,113 - INFO - Process Resource Usage - CPU: 17.40%, Memory: 0.19%
2025-02-13 17:28:38,123 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 14.519754 seconds
2025-02-13 17:28:38,123 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:28:38,127 - INFO - Running benchmarks with 1600 commands and max_connections=100
2025-02-13 17:28:38,127 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:28:38,127 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:28:42,114 - INFO - Process Resource Usage - CPU: 20.20%, Memory: 0.20%
2025-02-13 17:28:47,116 - INFO - Process Resource Usage - CPU: 18.00%, Memory: 0.20%
2025-02-13 17:28:52,117 - INFO - Process Resource Usage - CPU: 18.00%, Memory: 0.21%
2025-02-13 17:28:57,118 - INFO - Process Resource Usage - CPU: 17.40%, Memory: 0.23%
2025-02-13 17:29:02,119 - INFO - Process Resource Usage - CPU: 16.20%, Memory: 0.24%
2025-02-13 17:29:07,120 - INFO - Process Resource Usage - CPU: 17.40%, Memory: 0.26%
2025-02-13 17:29:12,123 - INFO - Process Resource Usage - CPU: 18.00%, Memory: 0.27%
2025-02-13 17:29:14,493 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 36.365215 seconds
2025-02-13 17:29:14,493 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:29:14,501 - INFO - Running benchmarks with 3200 commands and max_connections=100
2025-02-13 17:29:14,502 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:29:14,502 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:29:17,125 - INFO - Process Resource Usage - CPU: 20.20%, Memory: 0.27%
2025-02-13 17:29:22,126 - INFO - Process Resource Usage - CPU: 18.20%, Memory: 0.27%
2025-02-13 17:29:27,128 - INFO - Process Resource Usage - CPU: 18.20%, Memory: 0.27%
2025-02-13 17:29:32,129 - INFO - Process Resource Usage - CPU: 16.40%, Memory: 0.27%
2025-02-13 17:29:37,132 - INFO - Process Resource Usage - CPU: 17.00%, Memory: 0.27%
2025-02-13 17:29:42,133 - INFO - Process Resource Usage - CPU: 18.60%, Memory: 0.27%
2025-02-13 17:29:47,134 - INFO - Process Resource Usage - CPU: 17.60%, Memory: 0.28%
2025-02-13 17:29:52,135 - INFO - Process Resource Usage - CPU: 18.20%, Memory: 0.29%
2025-02-13 17:29:57,138 - INFO - Process Resource Usage - CPU: 17.60%, Memory: 0.30%
2025-02-13 17:30:02,140 - INFO - Process Resource Usage - CPU: 17.80%, Memory: 0.32%
2025-02-13 17:30:07,142 - INFO - Process Resource Usage - CPU: 17.60%, Memory: 0.33%
2025-02-13 17:30:12,143 - INFO - Process Resource Usage - CPU: 17.60%, Memory: 0.34%
2025-02-13 17:30:17,145 - INFO - Process Resource Usage - CPU: 18.40%, Memory: 0.36%
2025-02-13 17:30:22,147 - INFO - Process Resource Usage - CPU: 17.60%, Memory: 0.37%
2025-02-13 17:30:25,249 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 70.746333 seconds
2025-02-13 17:30:25,249 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:30:25,269 - INFO - Benchmark Results:
2025-02-13 17:30:25,269 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 64
2025-02-13 17:30:25,269 - INFO -   Batch size 1 took 1.492405 seconds
2025-02-13 17:30:25,269 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 640
2025-02-13 17:30:25,269 - INFO -   Batch size 1 took 14.519754 seconds
2025-02-13 17:30:25,269 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 1600
2025-02-13 17:30:25,269 - INFO -   Batch size 1 took 36.365215 seconds
2025-02-13 17:30:25,269 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 3200
2025-02-13 17:30:25,269 - INFO -   Batch size 1 took 70.746333 seconds
2025-02-13 17:30:25,269 - INFO - Resource usage logger task cancelled.

Without Semaphore:

2025-02-13 17:31:38,543 - INFO - Running benchmarks with 64 commands and max_connections=100
2025-02-13 17:31:38,544 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:31:38,544 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:31:39,948 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 1.404417 seconds
2025-02-13 17:31:39,948 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:31:39,949 - INFO - Running benchmarks with 640 commands and max_connections=100
2025-02-13 17:31:39,949 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:31:39,949 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:31:43,567 - INFO - Process Resource Usage - CPU: 77.40%, Memory: 0.18%
2025-02-13 17:31:48,576 - INFO - Process Resource Usage - CPU: 100.00%, Memory: 0.19%
2025-02-13 17:31:53,576 - INFO - Process Resource Usage - CPU: 95.40%, Memory: 0.20%
2025-02-13 17:31:56,802 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 16.853240 seconds
2025-02-13 17:31:56,802 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:31:56,807 - INFO - Running benchmarks with 1600 commands and max_connections=100
2025-02-13 17:31:56,807 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:31:56,807 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:32:17,716 - INFO - Process Resource Usage - CPU: 89.40%, Memory: 0.22%
2025-02-13 17:32:22,881 - INFO - Process Resource Usage - CPU: 99.50%, Memory: 0.23%
2025-02-13 17:32:27,897 - INFO - Process Resource Usage - CPU: 99.90%, Memory: 0.24%
2025-02-13 17:32:32,998 - INFO - Process Resource Usage - CPU: 99.80%, Memory: 0.24%
2025-02-13 17:32:38,005 - INFO - Process Resource Usage - CPU: 99.90%, Memory: 0.26%
2025-02-13 17:32:43,061 - INFO - Process Resource Usage - CPU: 99.70%, Memory: 0.27%
2025-02-13 17:32:48,064 - INFO - Process Resource Usage - CPU: 99.90%, Memory: 0.28%
2025-02-13 17:32:52,257 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 55.450154 seconds
2025-02-13 17:32:52,257 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:32:52,270 - INFO - Running benchmarks with 3200 commands and max_connections=100
2025-02-13 17:32:52,270 - INFO - <172.20.20.111>: Starting benchmarks...
2025-02-13 17:32:52,270 - INFO - <172.20.20.111>: Benchmarking with batch size 1
2025-02-13 17:34:21,817 - INFO - Process Resource Usage - CPU: 97.70%, Memory: 0.29%
2025-02-13 17:34:26,827 - INFO - Process Resource Usage - CPU: 99.00%, Memory: 0.30%
2025-02-13 17:34:31,874 - INFO - Process Resource Usage - CPU: 99.90%, Memory: 0.31%
2025-02-13 17:34:36,932 - INFO - Process Resource Usage - CPU: 99.80%, Memory: 0.32%
2025-02-13 17:34:42,112 - INFO - Process Resource Usage - CPU: 100.20%, Memory: 0.34%
2025-02-13 17:34:47,146 - INFO - Process Resource Usage - CPU: 99.90%, Memory: 0.35%
2025-02-13 17:34:52,175 - INFO - Process Resource Usage - CPU: 99.80%, Memory: 0.36%
2025-02-13 17:34:57,261 - INFO - Process Resource Usage - CPU: 100.10%, Memory: 0.37%
2025-02-13 17:35:02,349 - INFO - Process Resource Usage - CPU: 100.00%, Memory: 0.37%
2025-02-13 17:35:07,368 - INFO - Process Resource Usage - CPU: 99.80%, Memory: 0.39%
2025-02-13 17:35:12,445 - INFO - Process Resource Usage - CPU: 100.10%, Memory: 0.40%
2025-02-13 17:35:17,475 - INFO - Process Resource Usage - CPU: 99.80%, Memory: 0.41%
2025-02-13 17:35:22,505 - INFO - Process Resource Usage - CPU: 100.20%, Memory: 0.41%
2025-02-13 17:35:27,512 - INFO - Process Resource Usage - CPU: 99.70%, Memory: 0.42%
2025-02-13 17:35:32,034 - INFO - <172.20.20.111>: Completed benchmarking with batch size 1 in 159.763054 seconds
2025-02-13 17:35:32,034 - INFO - <172.20.20.111>: Completed benchmarks!
2025-02-13 17:35:32,060 - INFO - Benchmark Results:
2025-02-13 17:35:32,061 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 64
2025-02-13 17:35:32,061 - INFO -   Batch size 1 took 1.404417 seconds
2025-02-13 17:35:32,061 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 640
2025-02-13 17:35:32,061 - INFO -   Batch size 1 took 16.853240 seconds
2025-02-13 17:35:32,061 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 1600
2025-02-13 17:35:32,061 - INFO -   Batch size 1 took 55.450154 seconds
2025-02-13 17:35:32,061 - INFO - Device: 172.20.20.111, Max Connections: 100, Number of Commands: 3200
2025-02-13 17:35:32,061 - INFO -   Batch size 1 took 159.763054 seconds
2025-02-13 17:35:32,061 - INFO - Resource usage logger task cancelled.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

Copy link

codspeed-hq bot commented Feb 14, 2025

CodSpeed Performance Report

Merging #1042 will not alter performance

Comparing carl-baillargeon:fix/semaphore (5fdc1c3) with main (ecce5e5)

Summary

✅ 22 untouched benchmarks

Copy link
Collaborator

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

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

as discussed it LGTM - lets see if/how we can switch to another library for more perf in a future PR

@gmuloc
Copy link
Collaborator

gmuloc commented Feb 21, 2025

that being said - would be cool if we manage to get a benchmark for this kind of stuff running somewhere.. :)

@carl-baillargeon carl-baillargeon merged commit 45f3b5b into aristanetworks:main Feb 21, 2025
25 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