简体   繁体   中英

HttpClient.GetAsync() CPU consumption is high

I have a service which uses HttpClient class to fetch some resources from other services. As part of our performance testing, we mocked the HttpClient.GetAsync() call in order to remove the dependencies from external services, and replaced it with a method which returns content from local disk. The thing which is surprising is the CPU utilization went from 65% to 22%. So, when the performance test was done without the mock, the CPU utilization was 65%, and with mock it decreased to 22%. But the RPS remained constant

Also, when i started increasing the load, the CPU utilization and the RPS went up, which i think is expected.

My question is - is HttpClient.GetAsync() such an expensive operation ? and if yes then how can i confirm this with performance analysis ? which tool can help me here.

Note: The performance test are run with 100 User Load per second using Visual Studio Load Testing Framework.

Thanks, Javed

I typically construct my requests and use HttpClient.SendAsync(request) and rarely notice any spikes in CPU utilization. Also, 100 requests per second is a ton of requests. Consider re-designing your architecture so that it will perform better under heavy load. Things such as reducing the number of calls to HttpClient.SendAsync or HttpClient.GetAsync will improve your performance. You may also consider load balancing between an array of servers to reduce the response time and CPU load. Another consideration would be to cache responses to the external services that you interface with to reduce external HTTP calls. You could then rely on the cached response until the cache needs to be refreshed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM