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): reduce unnecessary polling #3319

Closed
wants to merge 2 commits into from
Closed
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 <[email protected]>
Andrew Burdo <[email protected]>
Andrew Svetlov <[email protected]>
Anil V <[email protected]>
Ankush Menat <[email protected]>
Antoine Girard <[email protected]>
Anton Vlasenko <[email protected]>
Artur Kruchinin <[email protected]>
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:
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