Skip to content

Replace wait_event_or_timeout internals with async_timeout - #1081

Merged
bdraco merged 1 commit into
masterfrom
async_timeout
Aug 5, 2022
Merged

bdraco merged 1 commit into
masterfrom
async_timeout

Conversation

@bdraco

@bdraco bdraco commented Aug 5, 2022 •

Copy link
Copy Markdown
Member

Its unlikely that https://bugs.python.org/issue39032 and
python/cpython#83213 will be fixed
soon. While we moved away from an asyncio.Condition, we still
has a similar problem with waiting for an asyncio.Event which
wait_event_or_timeout played well with. async_timeout avoids
creating a task so its a bit more efficient. Since we call
these when resolving ServiceInfo, avoiding task creation
will resolve a performance problem when ServiceBrowsers
startup as they tend to create task storms when coupled
with ServiceInfo lookups.

async_timeout was chosen as a replacement because
its by the asyncio authors and does not add any platform
specific requirements as its pure python.

Its unlikely that https://bugs.python.org/issue39032 and
python/cpython#83213 will be fixed
soon. While we moved away from an asyncio.Condition, we still
has a similar problem with waiting for an asyncio.Event which
wait_event_or_timeout played well with. async_timeout avoids
creating a task so its a bit more efficient. Since we call
these when resolving ServiceInfo, avoiding task creation
will resolve a performance problem when ServiceBrowsers
startup as they tend to create task storms when coupled
with ServiceInfo lookups.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

Merging #1081 (b4319a7) into master (88323d0) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1081      +/-   ##
==========================================
- Coverage   99.92%   99.92%   -0.01%     
==========================================
  Files          23       23              
  Lines        2559     2548      -11     
  Branches      477      476       -1     
==========================================
- Hits         2557     2546      -11     
  Misses          1        1              
  Partials        1        1              
Impacted Files Coverage Δ
zeroconf/_utils/asyncio.py 97.56% <100.00%> (-0.52%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@bdraco

bdraco commented Aug 5, 2022

Copy link
Copy Markdown
Member Author

Testing showed this decreased the number of tasks created by ~500/minute with on my production network, and ~1200/minute on my busy test network

I'll leave this as a draft for a while as I want to make sure it works ok in production for a while

@bdraco

bdraco commented Aug 5, 2022

Copy link
Copy Markdown
Member Author

This has been solid for a day. I want to clean up some of the tests before the next release

@bdraco
bdraco marked this pull request as ready for review August 5, 2022 21:24
@bdraco
bdraco merged commit 7ffea9f into master Aug 5, 2022
@bdraco
bdraco deleted the async_timeout branch August 5, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants