cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: CURL multi handle with easy handles from different threads

From: Rajalakshmi Iyer <raj_at_blismedia.com>
Date: Fri, 10 Jul 2015 07:06:35 +0100

Thanks for getting back. Here is some background to the application in its
current state -

The application has X worker threads that receives 1000s of concurrent
requests per second.

As part of handling these incoming requests, the X worker threads need to
make a callout to an external HTTP server. This callout typically takes up
to 100 ms.

Currently, the X worker threads have implemented this by using a
curl_easy_handle per thread, i.e. a connection per thread that is
continuously making callouts and handling the responses in the callback
function CURLOPT_WRITEFUNCTION.

However, this also means that the application is not doing much except
waiting on external HTTP server. The CPU is hardly utilised.

In order to overcome this, I am planning to use the curl multi interface.
So each of the X curl easy handles from X threads will be added to the curl
multi handle.

Does that sound a reasonable thing to do?

Regards
Raj

On Thu, Jul 9, 2015 at 11:38 PM, Ray Satiro via curl-library <
curl-library_at_cool.haxx.se> wrote:

> On 7/9/2015 5:19 PM, Rajalakshmi Iyer wrote:
>
>> Is it appropriate to have a global CURL multi handle to which easy
>> handles are added by different threads in an application?
>>
>
> It's possible but I don't know whether it's appropriate for you. I'm
> thinking back to what you posted on the list a few days ago and it sounded
> really like you may be experiencing some connectivity issue that is/was
> causing problems. That seems like the issue to address rather than rewrite
> your code. Also it was mentioned you can share DNS and such (but frankly
> I'm skeptical it would help in this case). Anyway, if that's a non-starter
> then please review [1] and "Only use one handle in one thread at any time."
>
>
> [1]: http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading
>
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html

-- 
    Rajalakshmi Iyer  *Senior Software Engineer*    raj-blismedia.com
<http://is.gd/L42zBR>[image: Skype icon]       [image: Blis logo]
<http://www.blismedia.com/>    <http://www.blismedia.com/>
<https://www.facebook.com/BlisMedia?fref=ts>
<https://twitter.com/BlisMedia>
<https://www.linkedin.com/company/blismedia>
<https://plus.google.com/u/0/103190831541608378945/about>
-- 
This email and any attachments to it may be confidential and are 
intended solely for the use of the individual to whom it is addressed. Any 
views or opinions expressed are solely those of the author and do not 
necessarily represent those of BlisMedia Ltd, a company registered in 
England and Wales with registered number 06455773. Its registered office is 
3rd Floor, 101 New Cavendish St, London, W1W 6XH, United Kingdom.
If you are not the intended recipient of this email, you must neither take 
any action based upon its contents, nor copy or show it to anyone. Please 
contact the sender if you believe you have received this email in error.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-07-10