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
module http_client - support for keeping connections open #542
Comments
Discussed this with Daniel and in general it's ok. What I wonder is if we in order to support this properly in the case if we access two or more servers need to move the connection data structure somewhere else, like in process memory but indexed on http_con objects or simply reset it if the http_con object is different from the previous one used in the same process. If you don't understand this confusing message, please report so and I'll try to explain better - just wanted to write down this thought before it disappeared in the mists of a confused mind... |
The purpose of this feature is to eliminate the TCP/TLS handshake for every query. I wouldn't think calling reset + set_options was the significant bit. |
Exactly. We may have to have a pkg-memory array of connections related to the connection objects. This needs to be reset if there's a config reload at some point. The benefits are huge, so this is an important enhancement. |
According to this: https://curl.haxx.se/libcurl/c/CURLOPT_MAXCONNECTS.html , libcurl can per default keep up to 5 open persistent connections in the handle. So as long as 5 or fewer connections are used, everything is fine. Perhaps there should be a module option to set this to a higher value? |
Sorry, this won't make it into 4.4. I think this would be a very useful addition though and hope to get time to get back to it. |
Well if we have one handle per curl con everything will be fine. I have some new code in master that splits up configuration in shared memory and some data like last result code and redirect URL in package memory which is per process. If we move the curl handle into package memory we can have one handle per connection. We just need to make sure we clean up properly. I think the infrastructure for getting this done is on it's way by the latest commits, just need to run more tests and make sure the memory handling works as planned. As I want to be able to reload the configuration file at some point, we need to figure out how to handle that too. |
Committed code to MASTER. When testing with a TLS server connection reuse saves a lot of time. Thank you for this suggestion. Please try it out. |
I've tried to use the modparam "keep_connections", and it works! But like the other default parameters, it must be specified before the connection definition to have effect, which I still find unintuitive. It would be neat if this was documented. |
You are right. Either documentation or a fix. |
Thank you for testing! |
The current implementation uses curl_easy_init() to create a CURL easy handle and curl_easy_cleanup() to destroy the handle, including all open connections within it.
If curl_easy_cleanup() isn't called, it's possible to reuse an open connection for the next http call. To reset the CURL options, curl_easy_reset() can be used instead.
To use curl_easy_cleanup() or curl_easy_reset() should probably be configurable.
http_client_keep_connections_open.diff
The text was updated successfully, but these errors were encountered: