Skip to content
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

Closed
filiplx opened this issue Mar 11, 2016 · 10 comments
Closed

module http_client - support for keeping connections open #542

filiplx opened this issue Mar 11, 2016 · 10 comments
Assignees

Comments

@filiplx
Copy link

filiplx commented Mar 11, 2016

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

@oej oej self-assigned this Mar 13, 2016
@oej
Copy link
Member

oej commented Mar 15, 2016

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...

@que273
Copy link
Contributor

que273 commented Mar 15, 2016

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.
The tricky bit comes when two servers are used and the process is constantly alternating between them. Do we need to store a 'CURL' object (aka easy handle) for each http_con in this case?
Or can the "CURL" object maintain a pool of open connections and select the correct one based on the specified URL + options?

@oej
Copy link
Member

oej commented Mar 15, 2016

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.

@filiplx
Copy link
Author

filiplx commented Mar 15, 2016

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?

@oej
Copy link
Member

oej commented Mar 30, 2016

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.

@oej
Copy link
Member

oej commented Apr 2, 2016

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.

@oej
Copy link
Member

oej commented Apr 3, 2016

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.

@filiplx
Copy link
Author

filiplx commented Apr 20, 2016

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.

@oej
Copy link
Member

oej commented Apr 20, 2016

You are right. Either documentation or a fix.

@oej
Copy link
Member

oej commented Apr 20, 2016

Thank you for testing!

@oej oej closed this as completed Apr 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants