cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: libcurl 7.18.2: Question on CURLMOPT_MAXCONNECTS

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 27 Jun 2008 23:24:45 +0200 (CEST)

On Thu, 26 Jun 2008, Stefan Krause wrote:

> CURLMOPT_MAXCONNECTS is "the maximum amount of simultaneously open
> connections that libcurl may cache" according to the API description. That
> means that at most CURLMOPT_MAXCONNECTS number of sockets are open in
> parallel ?

No. It means that libcurl will not have more than CURLMOPT_MAXCONNECTS
connections open in its cache when you have less than CURLMOPT_MAXCONNECTS
easy handles added. If you add more easy handles, then libcurl will (of
course) create more sockets than so.

> So, does that parameter in fact limit the number of sockets open at a
> certain time ?

Not really, no.

> "Default is 10, and libcurl will enlarge the size for each added easy handle
> to make it fit 4 times the number of added easy handles"
> So, a multi handle without easy handles cashes max. 10 connections. In case I
> add 4 easy handles, how many connections are cached ? 10 (default) + 4 (easy
> handles) * 4 = 26 or 4 (easy handles) * 4 = 16 ? What is the formula ?

Yes it would be 16. Logic taken from the source:

    if((multi->num_easy * 4) > multi->connc->num) {

      newmax = multi->num_easy * 4;

> What happens in case I set the CURLMOPT_MAXCONNECTS to 10 and then add 20
> easy handles ? Are the 20 easy handles processed properly ?

Yes, it'll just limit the number of connections it'll pool so when you close
one of those 20 connections it won't keep it around since it isn't "allowed".
That will of course hamper performance on repeated requests that would
otherwise have been persistent. You should really always allow more
connections than number of easy handles you have added simultaneously.

-- 
  / daniel.haxx.se
Received on 2008-06-27