-
Notifications
You must be signed in to change notification settings - Fork 23
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
Significantly reduce heartbeat overhead #301
Conversation
I think this is good to go, but I need to spend a few more hours doing testing with it |
Test Plan:
|
Found an unexpected issue unrelated to this PR. We never get |
We could also trigger a refresh when we see the device via zeroconf to speed up reconnects if its offline for a while |
So there is a race when we reconnect. If its offline for longer than one cycle |
That problem is existing and not related to this PR. Digging into that though now |
So the |
@bdraco I was going to ask you about the |
So when we get a connect error we call
|
So even worse the device just stops getting updates after it hits a connection error |
Its not just the scanner. I stop getting state updates from the device completely but I can still control it. |
I'm going to start another PR to fix that. |
Retest looks good with the other fix |
The heartbeat built into
aiohttp
tries very hard to deliver exact timeouts by canceling the timer handler every time a message is received. When the volume of messages is high (bluetooth), this has a significant overhead. Since we do not need that level of resolution with the heartbeat we can use a significantly more performant heartbeat algorithm.Before this change resetting the heartbeat is ~38% the execution time to receive a websocket message.
Before:
After:
The cancelation of the non-existent heart beat still takes ~4% of the run time but still much better