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

Improve performance of keepalive rescheduling #8662

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES/8662.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reduce frequency of HTTP keep-alive checks -- by :user:`bdraco`.
bdraco marked this conversation as resolved.
Show resolved Hide resolved

Previously, when processing a request for a keep-alive connection, the keep-alive check would happen every second; the check now occurs when the keep-alive is expected to timeout or 1s later, whichever is later.
bdraco marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 9 additions & 7 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,19 @@ def _process_keepalive(self) -> None:
return

next = self._keepalive_time + self._keepalive_timeout
now = self._loop.time()

# handler in idle state
if self._waiter:
if self._loop.time() > next:
self.force_close()
return
if self._waiter and now > next:
self.force_close()
return

# not all request handlers are done,
# reschedule itself to next second
self._keepalive_handle = self._loop.call_later(
self.KEEPALIVE_RESCHEDULE_DELAY,
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
# reschedule itself to next or
# the next second, whichever is later
reschedule_time = max(next, now + self.KEEPALIVE_RESCHEDULE_DELAY)
self._keepalive_handle = self._loop.call_at(
reschedule_time,
self._process_keepalive,
)

Expand Down
Loading