mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 02:49:12 +08:00
Merge pull request #2938 from Affirm/reuse-port-fix
Fix reuse-port to balance requests across Gunicorn workers
This commit is contained in:
commit
bacbf8aa51
@ -9,6 +9,7 @@ import signal
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
import socket
|
||||
|
||||
from gunicorn.errors import HaltServer, AppImportError
|
||||
from gunicorn.pidfile import Pidfile
|
||||
@ -151,7 +152,8 @@ class Arbiter:
|
||||
for fd in os.environ.pop('GUNICORN_FD').split(','):
|
||||
fds.append(int(fd))
|
||||
|
||||
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
|
||||
if not (self.cfg.reuse_port and hasattr(socket, 'SO_REUSEPORT')):
|
||||
self.LISTENERS = sock.create_sockets(self.cfg, self.log, fds)
|
||||
|
||||
listeners_str = ",".join([str(lnr) for lnr in self.LISTENERS])
|
||||
self.log.debug("Arbiter booted")
|
||||
@ -604,6 +606,8 @@ class Arbiter:
|
||||
try:
|
||||
util._setproctitle("worker [%s]" % self.proc_name)
|
||||
self.log.info("Booting worker with pid: %s", worker.pid)
|
||||
if self.cfg.reuse_port:
|
||||
worker.sockets = sock.create_sockets(self.cfg, self.log)
|
||||
self.cfg.post_fork(self, worker)
|
||||
worker.init_process()
|
||||
sys.exit(0)
|
||||
|
||||
@ -41,7 +41,7 @@ class GeventWorker(AsyncWorker):
|
||||
sockets = []
|
||||
for s in self.sockets:
|
||||
sockets.append(socket.socket(s.FAMILY, socket.SOCK_STREAM,
|
||||
fileno=s.sock.fileno()))
|
||||
fileno=s.sock.detach()))
|
||||
self.sockets = sockets
|
||||
|
||||
def notify(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user