cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: Limiting the number of active connections/transfers.

From: Vladimir Grishchenko <vladgri_at_hotmail.com>
Date: Mon, 4 Apr 2011 15:06:37 -0700

----------------------------------------
> Date: Mon, 4 Apr 2011 23:37:11 +0200
> From: daniel_at_haxx.se
> To: curl-library_at_cool.haxx.se
> Subject: Re: Limiting the number of active connections/transfers.
>
> On Mon, 4 Apr 2011, Vladimir Grishchenko wrote:
>
>> I need to put a hard upper bound on the number of connections through
>> libcurl, is there an easy way of doing it with libcurl? For example, there
>> are CURLMOPT_MAXCONNECTS and CURLOPT_MAXCONNECTS options, but my
>> understanding is that they only apply to cached idle connections that can be
>> reused and libcurl will always attempt to open a new connection when
>> requested and I need to roll out my own solution, is that correct?
>
> As you're mentioning CURLMOPT_MAXCONNECTS I assume you're using the multi
> interface? I'll assume so here.
>
> libcurl will then not keep around more than CURLMOPT_MAXCONNECTS in its pool
> of previous and current connections. However, you then add new easy handles to
> the multi handle, and each such concurrent handle can have its own connection
> so even if you set CURLMOPT_MAXCONNECTS to a very small number, libcurl will
> use more connections than so if you add more easy handles. But when you remove
> the easy handles again, libcurl will not keep more than CURLMOPT_MAXCONNECTS
> in its pool.
>
> Thus: if you set CURLMOPT_MAXCONNECTS to N and you never add more than N easy
> handles to the multi handle (simultaneously, in any single given moment),
> libcurl should not keep more than N connections around.
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

Thanks Daniel, exactly the answer I've been looking for.

As for multi vs. easy, there is a chance I might need to use the latter as well but
not both at the same time. Sounds like for the easy interface, to achieve the same effect,
I need to make sure that the total # of configured CURLOPT_MAXCONNECTS across all alive easy handles
should not be more than N? For example, having at most 6 active easy handles with CURLOPT_MAXCONNECTS
set to 2 on each of them will guarantee there is never more than 6 open connections at any given time?

-Vladimir

                                               
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-04-05