From 873331185713b2e2466456e8cfcdb02ec37ff955 Mon Sep 17 00:00:00 2001 From: John Dickinson Date: Wed, 20 Jul 2016 11:09:35 -0700 Subject: [PATCH] Prevent CPU spinning when there are no children If you deploy an object server but have no rings at all (and are using servers-per-port), then the CPU will spin as it checks for child processes since there are actually no child processes to check. This patch adds a sleep so that the CPU doesn't spin. Change-Id: Iece62367aa2481a21752144b1f4477a3713282fe --- swift/common/wsgi.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 8ee12c8b82..88e61f2293 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -952,12 +952,21 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): with Timeout(loop_timeout, exception=False): try: - pid, status = green_os.wait() - if os.WIFEXITED(status) or os.WIFSIGNALED(status): - strategy.register_worker_exit(pid) - except OSError as err: - if err.errno not in (errno.EINTR, errno.ECHILD): - raise + try: + pid, status = green_os.wait() + if os.WIFEXITED(status) or os.WIFSIGNALED(status): + strategy.register_worker_exit(pid) + except OSError as err: + if err.errno not in (errno.EINTR, errno.ECHILD): + raise + if err.errno == errno.ECHILD: + # If there are no children at all (ECHILD), then + # there's nothing to actually wait on. We sleep + # for a little bit to avoid a tight CPU spin + # and still are able to catch any KeyboardInterrupt + # events that happen. The value of 0.01 matches the + # value in eventlet's waitpid(). + sleep(0.01) except KeyboardInterrupt: logger.notice('User quit') running[0] = False