Vivek Goel
Vivek Goel

Reputation: 24160

High CPU usage in libcurl with ssl url

I am using 10 threads to connect to https connection. Curl is taking 100% of cpu. How can I reduce that ?

Each Thread Code is like

curl_connection = curl_easy_init();

Now using same connection

setting some header then 
curl_easy_perform(curl_connection);

Upvotes: 1

Views: 2242

Answers (3)

Serge Rogatch
Serge Rogatch

Reputation: 15070

For the others looking into high CPU usage solution in libcurl: It uses a lot of CPU power to initialize a libcurl easy handle with curl_easy_init() and then to destruct it with curl_easy_cleanup(_pCurl). To decrease the CPU usage of libcurl, you need to create a pool of libcurl handles and reuse each handle by calling curl_easy_reset() on the handle. Alternatively, instead of implementing a pool of libcurl handles, you can initialize the handle once per thread and then in a loop before each new web request just call curl_easy_reset().

Upvotes: 2

rigortek
rigortek

Reputation: 23

I guess you call curl_easy_perform in main thread, avoid this, but call it in sub-thread.

Upvotes: 0

David Schwartz
David Schwartz

Reputation: 182819

You can reduce it by running other tasks, then the tasks will split the CPU. Otherwise, you want the CPU to do be doing as much useful work as possible. It's not like you can save it for later.

Upvotes: 1

Related Questions