Skip to content

Commit 6d60400

Browse files
authored
Enable gunicorn's reuse_port in production (#248)
This causes gunicorn to set `SO_REUSEPORT` on the listening socket, which helps ensure better request distribution between gunicorn workers and thus better performance. We don't enable this in development, since it makes it harder to notice when duplicate gunicorn processes have accidentally been launched (eg in different terminals), since the "address already in use" error no longer occurs. See: https://docs.gunicorn.org/en/stable/settings.html#reuse-port benoitc/gunicorn#2938 https://lwn.net/Articles/542629/ GUS-W-17614363.
1 parent b0034b2 commit 6d60400

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

gunicorn.conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,10 @@
6262
if os.environ.get("ENVIRONMENT") == "development":
6363
# Automatically restart gunicorn when the app source changes in development.
6464
reload = True
65+
else:
66+
# Use `SO_REUSEPORT` on the listening socket, which allows for more even request
67+
# distribution between workers. See: https://lwn.net/Articles/542629/
68+
# We don't enable this in development, since it makes it harder to notice when
69+
# duplicate gunicorn processes have accidentally been launched (eg in different
70+
# terminals), since the "address already in use" error no longer occurs.
71+
reuse_port = True

0 commit comments

Comments
 (0)