diff options
author | Brant Knudson <bknudson@us.ibm.com> | 2015-08-06 09:37:43 -0500 |
---|---|---|
committer | Brant Knudson <bknudson@us.ibm.com> | 2015-08-06 09:37:43 -0500 |
commit | 4e498a54d0034b2ce5c87130f080ff580d241600 (patch) | |
tree | d21d11091373e80bf1a4f70ecf1ee54ff82e0ff8 /keystoneclient/session.py | |
parent | d5c5423d6de3710e3480e47062333b33e8de0713 (diff) | |
parent | eae8e83f5a7a170b98ef2d74a4ffd9eac7cc47ba (diff) | |
download | python-keystoneclient-feature/keystoneauth_integration.tar.gz |
Merge remote-tracking branch 'origin/master' into merge-branchfeature/keystoneauth_integration
Conflicts:
keystoneclient/exceptions.py
keystoneclient/fixture/discovery.py
keystoneclient/fixture/v2.py
keystoneclient/fixture/v3.py
keystoneclient/middleware/auth_token.py
keystoneclient/middleware/s3_token.py
keystoneclient/tests/unit/test_auth_token_middleware.py
keystoneclient/tests/unit/test_memcache_crypt.py
keystoneclient/tests/unit/test_s3_token_middleware.py
requirements.txt
test-requirements.txt
Change-Id: Ib51acebaac7966bf37c1562fa15b9061df6a7aa5
Diffstat (limited to 'keystoneclient/session.py')
-rw-r--r-- | keystoneclient/session.py | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/keystoneclient/session.py b/keystoneclient/session.py index 14edf46..cace4f7 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -899,11 +899,37 @@ class Session(object): class TCPKeepAliveAdapter(requests.adapters.HTTPAdapter): - """The custom adapter used to set TCP Keep-Alive on all connections.""" + """The custom adapter used to set TCP Keep-Alive on all connections. + + This Adapter also preserves the default behaviour of Requests which + disables Nagle's Algorithm. See also: + http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx + """ def init_poolmanager(self, *args, **kwargs): - if requests.__version__ >= '2.4.1': - kwargs.setdefault('socket_options', [ + if 'socket_options' not in kwargs: + socket_options = [ + # Keep Nagle's algorithm off (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1), + # Turn on TCP Keep-Alive (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1), - ]) + # Set the maximum number of keep-alive probes + (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 4), + # Send keep-alive probes every 15 seconds + (socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 15), + ] + + # Some operating systems (e.g., OSX) do not support setting + # keepidle + if hasattr(socket, 'TCP_KEEPIDLE'): + socket_options += [ + # Wait 60 seconds before sending keep-alive probes + (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60) + ] + + # After waiting 60 seconds, and then sending a probe once every 15 + # seconds 4 times, these options should ensure that a connection + # hands for no longer than 2 minutes before a ConnectionError is + # raised. + + kwargs['socket_options'] = socket_options super(TCPKeepAliveAdapter, self).init_poolmanager(*args, **kwargs) |