New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use connection keep-alive #624
Conversation
Do not forcefully close the connection after every request. This enables HTTP connection keep-alive, also known as persistent TCP and TLS/SSL connection. Keep-alive speed up consecutive HTTP requests by 15% (for local, low-latency network connections to a fast server) to multiple times (high latency connections or remote peers). https://pagure.io/freeipa/issue/6641 Signed-off-by: Christian Heimes <cheimes@redhat.com>
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Apache has a default keep alive timeout of 5 seconds. That's too low for interactive commands, e.g. password prompts. 30 seconds sounds like a good compromise. Signed-off-by: Christian Heimes <cheimes@redhat.com>
| # Increase connection keep alive time. Default value is 5 seconds, which is too | ||
| # short for interactive ipa commands. 30 seconds is a good compromise. | ||
| KeepAlive On | ||
| KeepAliveTimeout 30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree with this change. Since we're no longer closing connections explicitly, we rely on the server to close them. Keeping all the connections open for 30 seconds for a few use cases does not seem like an acceptable trade off.
I suggest we keep the default 5 seconds to ease the load on the server. I think making one extra round trip to establish TLS once again in cases when user is prompted for password is preferable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your assumption is incorrect. For ipa client, the connection is automatically closed by ipaclient.api.Backend.rpcclient.disconnect() or when the client process exits. The 30 seconds keepalive timeout optimizes both ipa and browser sessions. For browser session I would even increase the keepalive timeout for 60 seconds in order to reduce the load on the server.
Modern webservers like Apache use high performance socket handling features of modern operating systems. epoll can easily handle thousands of connections. Repeating TCP handshake and TLS handshake over and over again cost magnitudes more performance than watching a bunch of additional sockets for I/O. A longer keepalive period won't be a problem until we have to handle thousands of client connections simultaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, didn't notice that the connections are actually closed elsewhere in ipa client.
| @@ -686,8 +695,18 @@ def single_request(self, host, handler, request_body, verbose=0): | |||
| return self.parse_response(response) | |||
| except gssapi.exceptions.GSSError as e: | |||
| self._handle_exception(e) | |||
| finally: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment explicitly stating that the connection is not closed on purpose to enable keep-alive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are comments and debug logging calls.
|
I examined this in wireshark. Without this patch, The question is whether this improvement is good enough or whether we want to optimize the RPC to actually use just a single connection. Also, please follow the development process next time and assign yourself to the ticket when you start working on it, so other don't have to invest time into solving the same issue. |
|
The extra connections seem to come from the internals of |
|
This behavior could be caused by https://github.com/python/cpython/blob/master/Lib/socket.py#L688 . What's |
|
@tiran I checked that code as well, |
Do not forcefully close the connection after every request. This enables
HTTP connection keep-alive, also known as persistent TCP and TLS/SSL
connection. Keep-alive speed up consecutive HTTP requests by 15% (for
local, low-latency network connections to a fast server) to multiple
times (high latency connections or remote peers).
pache has a default keep alive timeout of 5 seconds. That's too low for
interactive commands, e.g. password prompts. 30 seconds sounds like a
good compromise.
https://pagure.io/freeipa/issue/6641