High CPU usage caused by using the same HttpClient instance
Published Mar 11 2019 06:41 PM 8,143 Views
Microsoft

High CPU usage is one of the most common issues that affects web servers. There are several root causes related to server hardware, website traffic or application code.

 

If you use the same instance of an object which is not thread-safe multiple times, this may increase the CPU usage. More specifically, using the same HttpClient instance from different threads increases the CPU usage.

 

The issue may surface in many ways. One if them is -obviously- high resource utilization. You can monitor the resource usage in Task Manager, Resource Monitor or Performance Monitor.

 

post15.png

 

The official documentation for HttpClient recommends using only one instance of this object (Source HttpClient Class). However, for the scenarios where requests step on each other, it’s better to create more than one instance.

 

Solution

 

Applications shouldn’t depend on one instance of HttpClient if the requests overlap each other. Instead of calling the same instance of HttpClient, using new instances of it should help IIS to reduce CPU usage.

4 Comments
Version history
Last update:
‎Mar 11 2019 06:41 PM
Updated by: