Use oslo.utils.netutils function to set tcp_keepalive

Use netutils.set_tcp_keepalive to set tcp keepalive parameters.
In addition to the existing conf option for tcp_keepidle, new
values were added for tcp_keepalive (to turn on/off this feature,
tcp_keepalive_interval (to specify gap between successive probes) and
tcp_keepalive_count (to specify number of probes).

Change-Id: I60c3bbf5f3deff8bdffe97af76052386e4598b45
This commit is contained in:
Thomas Bechtold 2014-11-13 16:04:06 +01:00
parent fad5e37e60
commit 04ea460272

View File

@ -30,6 +30,7 @@ import eventlet
import eventlet.wsgi import eventlet.wsgi
import greenlet import greenlet
from oslo.config import cfg from oslo.config import cfg
from oslo.utils import netutils
from paste import deploy from paste import deploy
import routes.middleware import routes.middleware
import six import six
@ -46,10 +47,20 @@ socket_opts = [
default=4096, default=4096,
help="Number of backlog requests to configure the socket " help="Number of backlog requests to configure the socket "
"with."), "with."),
cfg.BoolOpt('tcp_keepalive',
default=True,
help="Sets the value of TCP_KEEPALIVE (True/False) for each "
"server socket."),
cfg.IntOpt('tcp_keepidle', cfg.IntOpt('tcp_keepidle',
default=600, default=600,
help="Sets the value of TCP_KEEPIDLE in seconds for each " help="Sets the value of TCP_KEEPIDLE in seconds for each "
"server socket. Not supported on OS X."), "server socket. Not supported on OS X."),
cfg.IntOpt('tcp_keepalive_interval',
help="Sets the value of TCP_KEEPINTVL in seconds for each "
"server socket. Not supported on OS X."),
cfg.IntOpt('tcp_keepalive_count',
help="Sets the value of TCP_KEEPCNT for each "
"server socket. Not supported on OS X."),
cfg.StrOpt('ssl_ca_file', cfg.StrOpt('ssl_ca_file',
default=None, default=None,
help="CA certificate file to use to verify " help="CA certificate file to use to verify "
@ -177,14 +188,13 @@ class Server(object):
"after trying for 30 seconds") % "after trying for 30 seconds") %
{'host': host, 'port': port}) {'host': host, 'port': port})
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
# sockets can hang around forever without keepalive
sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
# This option isn't available in the OS X version of eventlet # sockets can hang around forever without keepalive
if hasattr(socket, 'TCP_KEEPIDLE'): netutils.set_tcp_keepalive(sock,
sock.setsockopt(socket.IPPROTO_TCP, CONF.tcp_keepalive,
socket.TCP_KEEPIDLE, CONF.tcp_keepidle,
CONF.tcp_keepidle) CONF.tcp_keepalive_interval,
CONF.tcp_keepalive_count)
return sock return sock