Disable reverse dns lookup
The BaseHTTPServer will do a reverse dns lookup when log message, which will cause 10 seconds latency in some network environment. This will significantly slow down the api request when wsgiref.simple_server is used. This patch creates a class, which inherits from simple_server.WSGIRequestHandler but overrides address_string method, and passes it to handler_class param of simple_server.make_server. Change-Id: Ia38c7719ed700ab5867dcc4bcf3700bff282a907 Closes-Bug: #1291229
This commit is contained in:
parent
fa7a9733dc
commit
bad95ca2bc
@ -30,6 +30,12 @@ API_SERVICE_OPTS = [
|
||||
default='0.0.0.0',
|
||||
help='The listen IP for the ceilometer API server.',
|
||||
),
|
||||
cfg.BoolOpt('enable_reverse_dns_lookup',
|
||||
default=False,
|
||||
help=('Set it to False if your environment does not need '
|
||||
'or have dns server, otherwise it will delay the '
|
||||
'response from api.')
|
||||
),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
@ -121,6 +121,21 @@ def get_server_cls(host):
|
||||
return server_cls
|
||||
|
||||
|
||||
def get_handler_cls():
|
||||
cls = simple_server.WSGIRequestHandler
|
||||
|
||||
# old-style class doesn't support super
|
||||
class CeilometerHandler(cls, object):
|
||||
def address_string(self):
|
||||
if cfg.CONF.api.enable_reverse_dns_lookup:
|
||||
return super(CeilometerHandler, self).address_string()
|
||||
else:
|
||||
# disable reverse dns lookup, directly return ip adress
|
||||
return self.client_address[0]
|
||||
|
||||
return CeilometerHandler
|
||||
|
||||
|
||||
def build_server():
|
||||
# Build the WSGI app
|
||||
root = VersionSelectorApplication()
|
||||
@ -128,7 +143,8 @@ def build_server():
|
||||
# Create the WSGI server and start it
|
||||
host, port = cfg.CONF.api.host, cfg.CONF.api.port
|
||||
server_cls = get_server_cls(host)
|
||||
srv = simple_server.make_server(host, port, root, server_cls)
|
||||
srv = simple_server.make_server(host, port, root,
|
||||
server_cls, get_handler_cls())
|
||||
|
||||
LOG.info(_('Starting server in PID %s') % os.getpid())
|
||||
LOG.info(_("Configuration:"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user