High CPU usage caused by using the same HttpClient instance

This post has been republished via RSS; it originally appeared at: IIS Support Blog articles.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.