Merge "wsgi: Start workers in parallel, rather than serially"

This commit is contained in:
Zuul 2022-11-14 17:34:28 +00:00 committed by Gerrit Code Review
commit 6a010499d5

View File

@ -970,7 +970,7 @@ class ServersPerPortStrategy(StrategyBase):
Called when a new worker is started. Called when a new worker is started.
:param socket sock: The listen socket for the worker just started. :param socket sock: The listen socket for the worker just started.
:param server_idx: The socket's server_idx as yielded by :param tuple data: The socket's (port, server_idx) as yielded by
:py:meth:`new_worker_socks`. :py:meth:`new_worker_socks`.
:param int pid: The new worker process' PID :param int pid: The new worker process' PID
""" """
@ -1090,6 +1090,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
signal.signal(signal.SIGUSR1, stop_with_signal) signal.signal(signal.SIGUSR1, stop_with_signal)
while running_context[0]: while running_context[0]:
new_workers = {} # pid -> status pipe
for sock, sock_info in strategy.new_worker_socks(): for sock, sock_info in strategy.new_worker_socks():
read_fd, write_fd = os.pipe() read_fd, write_fd = os.pipe()
pid = os.fork() pid = os.fork()
@ -1114,16 +1115,16 @@ def run_wsgi(conf_path, app_section, *args, **kwargs):
return 0 return 0
else: else:
os.close(write_fd) os.close(write_fd)
worker_status = os.read(read_fd, 30) new_workers[pid] = read_fd
os.close(read_fd) strategy.register_worker_start(sock, sock_info, pid)
# TODO: delay this status checking until after we've tried
# to start all workers. But, we currently use the register for pid, read_fd in new_workers.items():
# event to know when we've got enough workers :-/ worker_status = os.read(read_fd, 30)
if worker_status == b'ready': os.close(read_fd)
strategy.register_worker_start(sock, sock_info, pid) if worker_status != b'ready':
else: raise Exception(
raise Exception( 'worker %d did not start normally: %r' %
'worker did not start normally: %r' % worker_status) (pid, worker_status))
# TODO: signal_ready() as soon as we have at least one new worker for # TODO: signal_ready() as soon as we have at least one new worker for
# each port, instead of waiting for all of them # each port, instead of waiting for all of them