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

perf(gthread): Use request timeout / 2 for epoll timeout #3319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Andreas Stührk <andy-python@hammerhartes.de>
Andrew Burdo <zeezooz@gmail.com>
Andrew Svetlov <andrew.svetlov@gmail.com>
Anil V <avaitla16@gmail.com>
Ankush Menat <ankushmenat@gmail.com>
Antoine Girard <antoine.girard.dev@gmail.com>
Anton Vlasenko <antares.spica@gmail.com>
Artur Kruchinin <arturkruchinin@gmail.com>
Expand Down
3 changes: 3 additions & 0 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1793,3 +1793,6 @@ set this to a higher value.
``sync`` worker does not support persistent connections and will
ignore this option.

.. note::
When the worker becomes idle, some connections may remain open for
up to twice the specified keepalive value.
7 changes: 6 additions & 1 deletion gunicorn/workers/gthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,13 @@ def run(self):

# can we accept more connections?
if self.nr_conns < self.worker_connections:
# Block for new events until worker times out or keepalive timeout.
select_timeout = self.timeout or 1.0
if self._keep:
Copy link
Author

@ankush ankush Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can hoist this change out of the while loop, but then folks running the default config (keepalive=2) won't see any noticeable difference.

Keeping it inside the loop allows making timeout adaptive to the presence of keepalived sockets.

select_timeout = min(select_timeout, self.cfg.keepalive)

# wait for an event
events = self.poller.select(1.0)
events = self.poller.select(select_timeout)
for key, _ in events:
callback = key.data
callback(key.fileobj)
Expand Down