libcpr / cpr

C++ Requests: Curl for People, a spiritual port of Python Requests.
https://docs.libcpr.org/
Other
6.27k stars 901 forks source link

CPU high usage on windows when i use cpr library #1063

Closed Beeifys closed 2 days ago

Beeifys commented 2 weeks ago

Description

Why my cpu very high on Anti Malware Executable, when i use cpr with thread pool to scraping a websites. Im compiled my executable use Visual Studio 2019 on Windows. Any solution for it?

My software cpu usage: image

Picture of high cpu: image

Example/How to Reproduce

My GET requests code (just part of my code not included some variable on it): cpr::Session session; session.SetUrl(cpr::Url(fullUrl)); session.SetVerifySsl(false); session.SetTimeout(cpr::Timeout{ 30000 });

  cpr::Header headers = customHeaders;
  if (headers.empty()) {
      headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36";
      headers["Host"] = hostname;
  }
  else {
      headers["Host"] = hostname;
  }
  session.SetHeader(headers);
  session.SetCookies(cpr::Cookies(customCookies));
  return session.Get();

My post request code (just part of my code not included some variable on it): session.SetUrl(cpr::Url{ fullUrl }); cpr::Header headers = customHeaders; if (headers.empty()) { headers["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"; headers["Content-Type"] = contentType; } else { headers["Content-Type"] = contentType; } session.SetHeader(headers); session.SetBody(cpr::Body(postBody)); session.SetCookies(cpr::Cookies(customCookies)); return session.Post();

Possible Fix

No response

Where did you get it from?

vcpkg

Additional Context/Your Environment

COM8 commented 2 weeks ago

Asking the obvious: Have you tried deactivating your anti virus or even better add an exclusion rule for the directory where you develop?

This will not just get rid of almost any runtime performance problems, but also improve your compile speed.

https://stackoverflow.com/questions/57202043/windows-defender-might-be-impacting-your-build-performance

COM8 commented 2 days ago

Closing for no response.