Skip to Content

Solved: How to Fix IIS High CPU Usage on Azure VM with Low Inbound Traffic

Learn how to troubleshoot and resolve the issue of IIS high CPU usage on Azure VM with low inbound traffic, using various tools and methods.

Problem

If you are running an IIS server on an Azure VM, you may encounter a situation where the CPU usage spikes to 100% and the VM becomes unresponsive, even though the inbound traffic is low. This can cause performance degradation, downtime, and frustration for both you and your users. In this article, we will explain the possible causes of this issue, how to diagnose it, and how to fix it using various tools and methods.

Possible Causes of IIS High CPU Usage on Azure VM

There are many factors that can contribute to high CPU usage on an IIS server, such as:

  • A recent code change or deployment that affects the application logic, configuration, or performance.
  • A recent update that introduces a bug, a compatibility issue, or a configuration change.
  • A query change or outdated indexes that make the database queries more CPU-intensive.
  • A data change or a lack of appropriate indexes that increase the workload on the database server.
  • Azure VM-specific processes or extensions that consume CPU resources, such as RDAgent, Monitoring Agent, MMA agent, or Security client.
  • A misconfiguration of the CPU property on the app pool that allows the worker process to consume excessive CPU resources.

How to Diagnose IIS High CPU Usage on Azure VM

To troubleshoot and resolve the issue of IIS high CPU usage on Azure VM, you need to identify the problematic process, thread, or application that is causing the CPU spike. You can use various tools and methods to collect and analyze the performance data, such as:

PerfInsights

This is a tool that is designed for Azure VMs and can provide a user-friendly report that includes Azure best practices, SQL best practices, high-resolution I/O latency graphs, CPU and memory tabs, and more. You can download and run PerfInsights on your Azure VM and select the flags that you want to collect, such as Perfmon, Xperf, and Netmon. The tool will generate a ZIP file that contains the data and the report. You can open the report in a browser and review the findings and recommendations.

Perfmon

This is a built-in tool that can monitor and record the performance counters of various system components, such as CPU, memory, disk, network, and processes. You can use Perfmon to create a data collector set that captures the CPU usage of the processes and threads on your Azure VM. You can then view the data in a graph or a report and identify the process or thread that has the highest CPU utilization.

Procmon

This is a tool that can monitor and log the real-time activity of the processes, threads, registry, file system, and network on your Azure VM. You can use Procmon to filter and capture the events that are related to the process or thread that has the high CPU usage. You can then analyze the events and identify the root cause of the CPU spike, such as a code issue, a configuration issue, or a dependency issue.

DebugDiag

This is a tool that can collect and analyze the memory dumps of the processes and threads on your Azure VM. You can use DebugDiag to create a rule that triggers a memory dump when the CPU usage of the process or thread exceeds a certain threshold. You can then open the memory dump in DebugDiag and use the analysis scripts to find the hot path, the call stack, and the source code of the CPU spike.

How to Fix IIS High CPU Usage on Azure VM

Depending on the cause of the issue, there are different ways to fix the IIS high CPU usage on Azure VM, such as:

Optimize the code

If the issue is caused by a code issue, such as a memory leak, a loop, or a deadlock, you need to review and optimize the code to eliminate the issue. You can use tools such as Visual Studio, Application Insights, or New Relic to debug and profile the code and find the performance bottlenecks and errors.

Update the application

If the issue is caused by a bug or a compatibility issue that is introduced by a recent update, you need to apply the latest patches or fixes to the application or revert to a previous version that works well. You can use tools such as Azure DevOps, GitHub, or Bitbucket to manage the application updates and deployments.

Optimize the queries and indexes

If the issue is caused by a query change or outdated indexes that make the database queries more CPU-intensive, you need to review and optimize the queries and indexes to reduce the CPU load. You can use tools such as SQL Server Management Studio, SQL Server Profiler, or Azure SQL Database Query Performance Insight to monitor and tune the queries and indexes.

Optimize the data and indexes

If the issue is caused by a data change or a lack of appropriate indexes that increase the workload on the database server, you need to review and optimize the data and indexes to improve the performance. You can use tools such as SQL Server Management Studio, SQL Server Data Tools, or Azure Data Studio to manage and optimize the data and indexes.

Configure the CPU property on the app pool

If the issue is caused by a misconfiguration of the CPU property on the app pool that allows the worker process to consume excessive CPU resources, you need to configure the CPU property to limit the CPU usage of the worker process. You can right-click on the app pool and go to Advanced Settings and apply the following configurations:

  • Limit: This is the maximum percentage of CPU time that the worker process can use. You can set this value to a reasonable limit, such as 80% or 90%, to prevent the CPU spike.
  • Limit Action: This is the action that the app pool will take when the CPU limit is exceeded. You can set this value to KillW3wp, which will terminate and restart the worker process when the CPU limit is exceeded.
  • Limit Interval: This is the reset period in minutes for the CPU monitoring and throttling limits on the app pool. You can set this value to a short interval, such as 1 or 5 minutes, to monitor and control the CPU usage more frequently.

Configure the Azure VM-specific processes or extensions

If the issue is caused by Azure VM-specific processes or extensions that consume CPU resources, such as RDAgent, Monitoring Agent, MMA agent, or Security client, you need to configure them to reduce the CPU usage. You can use the Azure portal, PowerShell, or CLI to manage the Azure VM-specific processes or extensions and apply the following configurations:

  • RDAgent: This is the process that enables the Remote Desktop Protocol (RDP) access to the Azure VM. You can disable the RDP access if you do not need it or limit the number of concurrent RDP sessions to the Azure VM.
  • Monitoring Agent: This is the process that enables the Azure Monitor service to collect and analyze the performance and diagnostic data from the Azure VM. You can disable the Azure Monitor service if you do not need it or configure the data collection frequency and retention period to reduce the CPU load.
  • MMA agent: This is the process that enables the Azure Log Analytics service to collect and analyze the log data from the Azure VM. You can disable the Azure Log Analytics service if you do not need it or configure the log collection frequency and retention period to reduce the CPU load.
  • Security client: This is the process that enables the Azure Security Center service to provide security recommendations and alerts for the Azure VM. You can disable the Azure Security Center service if you do not need it or configure the security policies and rules to reduce the CPU load.

Frequently Asked Questions (FAQs)

Question: How can I monitor the CPU usage of the IIS server on Azure VM?

Answer: You can use various tools and methods to monitor the CPU usage of the IIS server on Azure VM, such as Perfmon, Procmon, PerfInsights, Azure Monitor, Azure Log Analytics, or Azure Security Center.

Question: How can I identify the problematic process, thread, or application that is causing the CPU spike on the IIS server on Azure VM?

Answer: You can use various tools and methods to identify the problematic process, thread, or application that is causing the CPU spike on the IIS server on Azure VM, such as Perfmon, Procmon, DebugDiag, PerfInsights, Visual Studio, Application Insights, or New Relic.

Question: How can I fix the issue of IIS high CPU usage on Azure VM?

Answer: You can use various tools and methods to fix the issue of IIS high CPU usage on Azure VM, depending on the cause of the issue, such as Visual Studio, Application Insights, New Relic, SQL Server Management Studio, SQL Server Profiler, Azure SQL Database Query Performance Insight, SQL Server Data Tools, Azure Data Studio, Azure DevOps, GitHub, Bitbucket, Azure portal, PowerShell, or CLI.

Summary

In this article, we have explained the possible causes of the issue of IIS high CPU usage on Azure VM with low inbound traffic, how to diagnose it, and how to fix it using various tools and methods. We hope that this article has helped you to troubleshoot and resolve the issue and improve the performance and reliability of your IIS server on Azure VM.

Disclaimer: This article is for informational purposes only and does not constitute professional advice. You should always consult with your IT technical expert before making any changes to your IIS server or Azure VM. We are not responsible for any damages or losses that may result from following the instructions or recommendations in this article.