curl-library
"Connection time-out" using curl multi interface with persistent connections
Date: Mon, 7 Jun 2010 12:35:20 +0530
Hi,
I am using curl multi interface and wish to use persistent connections. If
IIRC while using multi interface, all the connections that are kept alive
for subsequent re-use are stored in the multi handle.
So I never call curl_multi_cleanup(). However I do call
curl_multi_remove_handle(multi_handle, easy_handles[i]) and
curl_easy_cleanup(easy_handles[i]) for each of the easy handles that are
inserted in the multi handle.
Here's what I am doing :-
Every time my application receives a request, I create easy handles(protocol
is HTTP 1.1 ) to get some data from say 10 other servers and then put these
easy handles in the multi handle. Then perform the transfer using
curl_multi_perform and then remove all the easy handles from the multi
handle and cleanup the easy handles as well. But never perform
curl_multi_cleanup on the multi handle.
For the next request, again use the previous multi handle(so that previous
connections could be reused).
However, to my surprise, only a very small number of connections are being
re-used while a large number of them are doing connect() again even though
subsequent requests are also trying to connect to the same server.
The log shows a large number of "Connection time-out"(after setting the
VERBOSE option on easy handles)
This is how the log looks like:-
* Expire cleared
* Closing connection #0
* Connection time-out
* Expire cleared
* Closing connection #1
* Connection time-out
* Expire cleared
* Closing connection #2
* Connection time-out
* Expire cleared
* Closing connection #3
* Connection time-out
* Expire cleared
* Closing connection #4
* Connection time-out
* Expire cleared
* Closing connection #5
* Connection time-out
* Expire cleared
* Closing connection #6
* Connection time-out
* Expire cleared
* Closing connection #7
* Connection time-out
* Expire cleared
* Closing connection #8
* Connection time-out
* Expire cleared
* Closing connection #9
* Connection time-out
* Expire cleared
* Closing connection #10
* Connection time-out
* Expire cleared
* Closing connection #11
* Connection time-out
* Expire cleared
* Closing connection #12
* Connection time-out
* Expire cleared
* Closing connection #13
* Connection time-out
* Expire cleared
* Closing connection #14
* Connection time-out
* Expire cleared
* Closing connection #15
* Connection time-out
* Expire cleared
* Closing connection #16
* Connection time-out
* Expire cleared
* Closing connection #17
* Connection time-out
* Closing connection #18
* Connection time-out
* Expire cleared
* Closing connection #19
The machine ends up with a large number of connections in TIME_WAIT state
and only very few in ESTABLISHED state.
What could be the reason?(Protocol used is HTTP 1.1, so the disconnections
are not because of protocol)
Libcurl version used is 7.19.0.
Regards
lali
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-06-07