-
Notifications
You must be signed in to change notification settings - Fork 97
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
Reduce CPU usage and locking in the connection thread loop #271
Conversation
Verified thread looks good on the trace
|
|
Verified smoke tests pass Testing on Python 3.12.0 perf.py Before Perf Test Iterations Duration Rate After Perf Test Iterations Duration Rate |
Validated this on my production Home Assistant instance. |
The current design uses a
Queue
and times out every0.1s
to check if the thread should terminate. This wakes up the thread every0.1
even if there is no work to do. Anstrace
of the python process with-f
will show this behavior as well as thefutex
.To reduce the overhead, the
Queue
has been replaced with aSimpleQueue
since the minimum python version was bumped to 3.7+ (3.8), and the use case does not require complex functionality.SimpleQueue
avoids all the threading locks. Additionally the queue consumer thread now terminates when it sees the_STOP_RUNNING_SENTINEL
so it does not have to wake up every0.1s
to check if it needs to terminate.This solution builds on #213 (thanks @vovukman) and takes into consideration the sqlalchemy use case detailed in #213 (comment)