Skip to content

Outgoing query scheduling is suboptimal #821

Closed
home-assistant/core
#105868

Description

@bdraco

Its 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.

In #818 the scheduler was abstracted into QueryScheduler so it should be easier to improve it now.

Activity

  1. bdraco commented on Jul 15, 2021

    @bdraco
    MemberAuthor

    One strategy would be that instead of change of the next time, schedule a check to see if we should do another query by checking everything in the cache to see if a refresh is due for that service and then bump the next time if so.

  2. added a commit that references this issue on May 3, 2023
    263576f
  3. bdraco commented on May 4, 2023

    @bdraco
    MemberAuthor

    This is still a problem

  4. bdraco commented on May 4, 2023

    @bdraco
    MemberAuthor
        def process_ready_types(self, now: float) -> List[str]:
            """Generate a list of ready types that is due and schedule the next time."""
            if self.millis_to_wait(now):
                return []
    
            ready_types: List[str] = []
    
            for type_, due in self._next_time.items():
                if due > now:
                    continue
    
                ready_types.append(type_)
                self._next_time[type_] = now + self._delay[type_]
                self._delay[type_] = min(_BROWSER_BACKOFF_LIMIT * 1000, self._delay[type_] * 2)
    
            return ready_types
    

    If it becomes due process_ready_types could recalculate the lowest of all the record.get_expiration_time(_EXPIRE_REFRESH_TIME_PERCENT) for that type in the cache and if its not now, reschedule self._next_time for the type for than but don't update delay

  5. added a commit that references this issue on May 4, 2023
    1bff201
  6. bdraco commented on Dec 14, 2023

    @bdraco
    MemberAuthor

    It might make sense to implement lower on all of these and put everything in a heap queue

  7. bdraco commented on Dec 14, 2023

    @bdraco
    MemberAuthor

    We probably need another object to track on so when its removed, we can mark it removed , and keep track of it like timer handler canceled

    We will need to pop all the ready ones at at once.

  8. bdraco commented on Dec 14, 2023

    @bdraco
    MemberAuthor

    We likely generate an order of magnitude more queries than we should when a service browser is running.

    We should do 3x to get it primed, and than only query to rescue records when they are at the top of the heap

  9. added 2 commits that reference this issue on Dec 14, 2023
    2b1f39c
    d8a3a55
  10. added a commit that references this issue on Dec 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions