From b155da424a0b2a48b3c248decac809ecaf93408c Mon Sep 17 00:00:00 2001 From: Flaper Fesp Date: Wed, 2 Jan 2013 12:20:02 +0100 Subject: [PATCH] Check whether poll is available or not and let eventlet chose the best hub when it isn't. Change-Id: I5fb05a71e8c62d84cee1da9ea05f67ffbad18b9d --- swift/common/utils.py | 25 +++++++++++++++++++++++++ swift/common/wsgi.py | 5 +++-- swift/obj/replicator.py | 4 ++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index fc28fb74e3..233c3c96af 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -751,6 +751,31 @@ def get_logger(conf, name=None, log_to_console=False, log_route=None, return adapted_logger +def get_hub(): + """ + Checks whether poll is available and falls back + on select if it isn't. + + Note about epoll: + + Review: https://review.openstack.org/#/c/18806/ + + There was a problem where once out of every 30 quadrillion + connections, a coroutine wouldn't wake up when the client + closed its end. Epoll was not reporting the event or it was + getting swallowed somewhere. Then when that file descriptor + was re-used, eventlet would freak right out because it still + thought it was waiting for activity from it in some other coro. + """ + try: + import select + if hasattr(select, "poll"): + return "poll" + return "selects" + except ImportError: + return None + + def drop_privileges(user): """ Sets the userid/groupid of the current process, get session leader, etc. diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 8a892a67e3..02dccfba99 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -33,7 +33,7 @@ from urllib import unquote from swift.common.swob import Request from swift.common.utils import capture_stdio, disable_fallocate, \ drop_privileges, get_logger, NullLogger, config_true_value, \ - validate_configuration + validate_configuration, get_hub def monkey_patch_mimetools(): @@ -135,7 +135,8 @@ def run_wsgi(conf_file, app_section, *args, **kwargs): wsgi.HttpProtocol.log_message = \ lambda s, f, *a: logger.error('ERROR WSGI: ' + f % a) wsgi.WRITE_TIMEOUT = int(conf.get('client_timeout') or 60) - eventlet.hubs.use_hub('poll') + + eventlet.hubs.use_hub(get_hub()) eventlet.patcher.monkey_patch(all=False, socket=True) eventlet_debug = config_true_value(conf.get('eventlet_debug', 'no')) eventlet.debug.hub_exceptions(eventlet_debug) diff --git a/swift/obj/replicator.py b/swift/obj/replicator.py index fb1d6974f3..56cceb5b95 100644 --- a/swift/obj/replicator.py +++ b/swift/obj/replicator.py @@ -33,13 +33,13 @@ from eventlet.support.greenlets import GreenletExit from swift.common.ring import Ring from swift.common.utils import whataremyips, unlink_older_than, lock_path, \ compute_eta, get_logger, write_pickle, renamer, dump_recon_cache, \ - rsync_ip, mkdirs, config_true_value, list_from_csv + rsync_ip, mkdirs, config_true_value, list_from_csv, get_hub from swift.common.bufferedhttp import http_connect from swift.common.daemon import Daemon from swift.common.http import HTTP_OK, HTTP_INSUFFICIENT_STORAGE from swift.common.exceptions import PathNotDir -hubs.use_hub('poll') +hubs.use_hub(get_hub()) PICKLE_PROTOCOL = 2 ONE_WEEK = 604800