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
Improve websocket throughput and reduce latency #92967
Conversation
related issue #90281
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Put on my production. I ran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Some minor suggestions on commenting the code.
Thanks. Added some comments to better explain what is going on here. |
Note to future per discord discussion Most of the remaining overhead is in aiohttp https://github.com/aio-libs/aiohttp/blob/b2a7983aed047e36c3418e788096d7f46cea7e1e/aiohttp/http_websocket.py#L594 Some of that should improve in cpython 3.12 but the bulk of the run time is now compression which we can do little about (unless we can optimize libz). |
This is crazy! How can a core concept like asyncio.Queue be a place to performance optimize. Feel like that should be raised to cpython level. |
This one surprised me as well. I think |
Proposed change
related issue #90281
Since we have only one consumer we can make the implementation use a simple
deque
andasyncio.Future
to wake the consumer when thedeque
is changed.The tests were a bit light in some places so I added some more coverage as well.
_send_message
fell off all thepy-spy
s after this change. The execution flow is now much simplier:The writer gets a similar improvement where nearly all the overhead is
send_str
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: