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

feat: significantly improve efficiency of the ServiceBrowser scheduler #1335

Merged
merged 85 commits into from Dec 16, 2023

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Dec 14, 2023

The query scheduled was sub-optimal because we will schedule a query in the future when a PTR will be close to expiring, but if the PTR is seen again between when it was scheduled and we ask again, we still ask. This lead to an order of magnitude (frequently even 2 orders of magnitude) more queries than needed to rescue records from expiration.

This is a complete rewrite of the ServiceBrowser query scheduler.

fixes #821
replaces and closes #1171

Work tracking:

  • units for _ScheduledPTRQuery
  • units for QueryScheduler
  • unit for schedule_rescue_query
  • test for type being rescheduled
  • pr splits
  • remove prints and debug
  • refactor test_asking_qu/qm_questions to be more reliable
  • handle retries convert time back to expire %, and if less than 100%, schedule for later in 10% increments
  • investigate why Smart Bridge 2 is sometimes missing. It's only responding to qm. So we need to keep the qu first and than fallback to qm

@bdraco
Copy link
Member Author

bdraco commented Dec 14, 2023

Its working as expected and we get a heck of lot less queries we don't need to send.

Need to profile it to make sure all the schedule/reschedule/cancels are not too slow

@bdraco
Copy link
Member Author

bdraco commented Dec 14, 2023

performance looks great.

Sadly there are a lot of tests that check the internals because of scheduling... maybe we need a async_fire_time_changed instead to move time forward to avoid that

src/zeroconf/_services/browser.py Show resolved Hide resolved
src/zeroconf/_services/browser.py Outdated Show resolved Hide resolved
src/zeroconf/_services/browser.py Outdated Show resolved Hide resolved
src/zeroconf/_services/browser.py Outdated Show resolved Hide resolved
src/zeroconf/_services/browser.py Outdated Show resolved Hide resolved
@bdraco bdraco closed this Dec 15, 2023
@bdraco bdraco reopened this Dec 15, 2023
@bdraco bdraco marked this pull request as ready for review December 16, 2023 02:48
@bdraco bdraco merged commit c65d869 into master Dec 16, 2023
33 of 34 checks passed
@bdraco bdraco deleted the efficent_query_scheduler branch December 16, 2023 02:48
bdraco added a commit to bdraco/home-assistant that referenced this pull request Dec 16, 2023
changelog: python-zeroconf/python-zeroconf@0.129.0...0.130.0

Major traffic reduction (fixed python-zeroconf/python-zeroconf#821
and python-zeroconf/python-zeroconf#1337)

The ServiceBrower query scheduler has been rewritten from the ground up to
use a heapq: python-zeroconf/python-zeroconf#1335

ServiceInfo requests are now aware of history and will now space asking
questions far enough apart to avoid being suppressed
python-zeroconf/python-zeroconf#1348
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.

Outgoing query scheduling is suboptimal
1 participant