如何100%防止由于iis中的工作进程而导致的CPU使用率

时间:2023-02-05 20:34:43

My CPU usage is 100% most of the the time in Windows Server 2008-R2 with my own vps, vmware, quad core, and 4GB Ram. When I open windows Task Manager and go to the resource monitor I see that 100% usage is because of workerprocess.exe. I have 3 websites in my IIS.

在Windows Server 2008-R2中,我的CPU使用率是100%,使用我自己的vps、vmware、quad core和4GB内存。当我打开windows任务管理器并进入资源监视器时,我看到100%的使用是由于workerprocess.exe。我的IIS中有三个网站。

  • How can I figure out which web site causes that usage
  • 我怎样才能弄清楚是哪个网站导致了这种使用
  • How can I limit it to 80% usage of CPU?
  • 如何将CPU使用率限制在80% ?
  • Could it be a DDOS attack?
  • 这是DDOS攻击吗?
  • Is there any way to prevent DDOS?
  • 有什么方法可以预防DDOS吗?

I installed eset-nod32 on my vps, but it doesn't show any attack in the logs. I've tried searching about IIS and preventing DDOS, and just found an extension for banning IP addresses, but how can I find which IP address are generating traffic?

我在vps上安装了eset-nod32,但是日志中没有显示任何攻击。我尝试过搜索IIS和防止DDOS,并找到了一个禁止IP地址的扩展,但是我怎么才能找到哪个IP地址正在产生流量呢?

The web site is written in ASP.NET and C#. How can I determine what is happening on that web site and which lines of codes are causing that cpu usage?

这个网站是用ASP写的。NET和c#。如何确定web站点上发生了什么,以及哪些代码行导致了cpu的使用?

Also, one of my web sites should access administrator's desktop and read and write some files. So because of that I changed its application pool -> identity (Process Model) to local system, and I don't know if it is related with the CPU usage or not.

另外,我的一个网站应该访问管理员的桌面并读写一些文件。因此,我将它的应用程序池>标识(进程模型)更改为本地系统,我不知道它是否与CPU使用有关。

6 个解决方案

#1


11  

Well, this can take long time to figure out. Few points to narrow it down:

这需要很长时间才能算出来。没有什么可以缩小范围:

  • Identify what is killing the CPU. I recommend Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
  • 确定是什么杀死了CPU。我推荐Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx。
  • Identify what AppPool is causing this
  • 确定是什么AppPool导致了这种情况
  • Fix your code
  • 修复你的代码

#2


69  

Diagnosing

In terms of diagnosing what App Pool is causing trouble, you can:

在诊断应用程序池带来麻烦方面,您可以:

  1. Select the server
  2. 选择服务器
  3. Go to IIS > Worker Processes
  4. 转到IIS >工作进程

如何100%防止由于iis中的工作进程而导致的CPU使用率

This should bring up a menu like this so you can determine which App Pool is running amok.

这应该会弹出这样的菜单,这样您就可以确定哪个应用程序池正在运行amok。

如何100%防止由于iis中的工作进程而导致的CPU使用率

From there you can simply restart the the app pool and 9 times out of 10 that will fix any immediate issues you're having.

从那时起,你只需重新启动应用程序池,10次中就有9次会解决你当前遇到的任何问题。

Treating

Unless you run some sort of controversial business, this is probably not a DDOS attack. It's likely that some code is just hanging because it couldn't get through to another server or got stuck in a loop or mis-allocated resources or your app pool just hasn't been recycled in a while.

除非你经营一些有争议的业务,否则这可能不是DDOS攻击。一些代码可能只是挂起了,因为它无法通过另一个服务器,或者陷入了循环,或者分配错误的资源,或者你的应用程序池已经有一段时间没有被回收了。

You can deal with this problem programmatically without having to manually identify, log in, and recycle the app pool. Just configure the CPU property on your App Pool. You can have it kill (and automatically restart) your process anytime you reach a CPU threshold for a certain amount of time.

您可以以编程的方式处理这个问题,而无需手动识别、登录和回收应用程序池。只需在应用程序池中配置CPU属性。在一定的时间内,当您达到CPU阈值时,可以让它终止(并自动重新启动)进程。

In your case, if you want it to restart at 80%, you can right click on the app pool and go to Advanced Settings and apply the following configurations:

在你的情况下,如果你想让它在80%重新启动,你可以右键点击应用程序池,进入高级设置,应用以下配置:

如何100%防止由于iis中的工作进程而导致的CPU使用率

NOTE: As kraken101 pointed out, different IIS GUIs have treated this differently over time. While the config value is always in 1/1000 of a %, sometimes the GUI takes the whole percent.

注意:正如kraken101指出的那样,不同的IIS gui在不同的时间内处理的不同。虽然配置值总是在%的1/1000,但是有时候GUI会占用整个百分比。

You can add this to your config section like this:

可以将其添加到配置部分,如下所示:

<applicationPools>
   <add name="DefaultAppPool">
     <cpu limit="80000" action="KillW3wp" resetInterval="00:01:00" />
   </add>
</applicationPools>

Alternatively, you could script it with Powershell's WebAdministration Module like this:
(*make sure web-scripting-tools is enabled)

或者,您可以使用Powershell的WebAdministration模块(*确保启用web- scripttools)编写脚本

Import-Module WebAdministration

$appPoolName = "DefaultAppPool"
$appPool = Get-Item "IIS:\AppPools\$appPoolName"
$appPool.cpu.limit = 80000
$appPool.cpu.action = "KillW3wp"
$appPool.cpu.resetInterval = "00:01:00"
$appPool | Set-Item

Preventing

The steps above will help fix some things once they've broken, but won't really solve any underlying issues you have.

上面的步骤将帮助修复一些问题,但不会真正解决任何潜在的问题。

Here are some resources on doing performance monitoring:

以下是执行性能监视的一些资源:

#3


1  

Use PerfMon to collect data and DebugDiag to analyse.

使用PerfMon收集数据并进行调试分析。

Found this link while searching for similar issue.

在搜索类似问题时找到这个链接。

http://www.iis.net/learn/troubleshoot/performance-issues/troubleshooting-high-cpu-in-an-iis-7x-application-pool

http://www.iis.net/learn/troubleshoot/performance-issues/troubleshooting-high-cpu-in-an-iis-7x-application-pool

#4


0  

Use procmon to define your problem.

使用procmon来定义您的问题。

#5


0  

I was facing the same issues recently and found a solution which worked for me and reduced the memory consumption level upto a great extent.

我最近遇到了同样的问题,找到了一个解决方案,在很大程度上降低了内存的消耗。

Solution:

解决方案:

First of all find the application which is causing heavy memory usage.

首先,找到导致内存占用严重的应用程序。

You can find this in the Details section of the Task Manager.

您可以在任务管理器的Details部分中找到这一点。

Next.

下一个。

  1. Open the IIS manager.
  2. 打开IIS管理器。
  3. Click on Application Pools. You'll find many application pools which your system is using.
  4. 点击应用程序池。您将发现您的系统正在使用的许多应用程序池。
  5. Now from the task manager you've found which application is causing the heavy memory consumption. There would be multiple options for that and you need to select the one which is having '1' in it's Application column of your web application.
  6. 现在,您已经从任务管理器中找到了哪个应用程序导致了严重的内存消耗。这将有多个选项,您需要选择在web应用程序的应用程序列中有“1”的选项。
  7. When you click on the application pool on the right hand side you'll see an option Advance settings under Edit Application pools. Go to Advanced Settings. 5.Now under General category set the Enable 32-bit Applications to True
  8. 当您单击右边的应用程序池时,您将看到编辑应用程序池下的选项Advance设置。进入高级设置。现在,在通用类别下,将Enable 32位应用程序设置为True
  9. Restart the IIS server or you can see the consumption goes down in performance section of your Task Manager.
  10. 重新启动IIS服务器,或者可以在任务管理器的性能部分看到消耗下降。

If this solution works for you please add a comment so that I can know.

如果这个解决方案对您有效,请添加一个注释,以便我知道。

#6


-4  

I recently had this problem myself, and once I determined which AppPool was causing the problem, the only way to resolve the issue was remove that app pool completly and create a new one for the site to use.

最近我自己也遇到了这个问题,一旦我确定是哪个AppPool导致了这个问题,解决这个问题的唯一方法就是完全删除这个应用程序池,并创建一个新的应用程序池供站点使用。

#1


11  

Well, this can take long time to figure out. Few points to narrow it down:

这需要很长时间才能算出来。没有什么可以缩小范围:

  • Identify what is killing the CPU. I recommend Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
  • 确定是什么杀死了CPU。我推荐Process Explorer http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx。
  • Identify what AppPool is causing this
  • 确定是什么AppPool导致了这种情况
  • Fix your code
  • 修复你的代码

#2


69  

Diagnosing

In terms of diagnosing what App Pool is causing trouble, you can:

在诊断应用程序池带来麻烦方面,您可以:

  1. Select the server
  2. 选择服务器
  3. Go to IIS > Worker Processes
  4. 转到IIS >工作进程

如何100%防止由于iis中的工作进程而导致的CPU使用率

This should bring up a menu like this so you can determine which App Pool is running amok.

这应该会弹出这样的菜单,这样您就可以确定哪个应用程序池正在运行amok。

如何100%防止由于iis中的工作进程而导致的CPU使用率

From there you can simply restart the the app pool and 9 times out of 10 that will fix any immediate issues you're having.

从那时起,你只需重新启动应用程序池,10次中就有9次会解决你当前遇到的任何问题。

Treating

Unless you run some sort of controversial business, this is probably not a DDOS attack. It's likely that some code is just hanging because it couldn't get through to another server or got stuck in a loop or mis-allocated resources or your app pool just hasn't been recycled in a while.

除非你经营一些有争议的业务,否则这可能不是DDOS攻击。一些代码可能只是挂起了,因为它无法通过另一个服务器,或者陷入了循环,或者分配错误的资源,或者你的应用程序池已经有一段时间没有被回收了。

You can deal with this problem programmatically without having to manually identify, log in, and recycle the app pool. Just configure the CPU property on your App Pool. You can have it kill (and automatically restart) your process anytime you reach a CPU threshold for a certain amount of time.

您可以以编程的方式处理这个问题,而无需手动识别、登录和回收应用程序池。只需在应用程序池中配置CPU属性。在一定的时间内,当您达到CPU阈值时,可以让它终止(并自动重新启动)进程。

In your case, if you want it to restart at 80%, you can right click on the app pool and go to Advanced Settings and apply the following configurations:

在你的情况下,如果你想让它在80%重新启动,你可以右键点击应用程序池,进入高级设置,应用以下配置:

如何100%防止由于iis中的工作进程而导致的CPU使用率

NOTE: As kraken101 pointed out, different IIS GUIs have treated this differently over time. While the config value is always in 1/1000 of a %, sometimes the GUI takes the whole percent.

注意:正如kraken101指出的那样,不同的IIS gui在不同的时间内处理的不同。虽然配置值总是在%的1/1000,但是有时候GUI会占用整个百分比。

You can add this to your config section like this:

可以将其添加到配置部分,如下所示:

<applicationPools>
   <add name="DefaultAppPool">
     <cpu limit="80000" action="KillW3wp" resetInterval="00:01:00" />
   </add>
</applicationPools>

Alternatively, you could script it with Powershell's WebAdministration Module like this:
(*make sure web-scripting-tools is enabled)

或者,您可以使用Powershell的WebAdministration模块(*确保启用web- scripttools)编写脚本

Import-Module WebAdministration

$appPoolName = "DefaultAppPool"
$appPool = Get-Item "IIS:\AppPools\$appPoolName"
$appPool.cpu.limit = 80000
$appPool.cpu.action = "KillW3wp"
$appPool.cpu.resetInterval = "00:01:00"
$appPool | Set-Item

Preventing

The steps above will help fix some things once they've broken, but won't really solve any underlying issues you have.

上面的步骤将帮助修复一些问题,但不会真正解决任何潜在的问题。

Here are some resources on doing performance monitoring:

以下是执行性能监视的一些资源:

#3


1  

Use PerfMon to collect data and DebugDiag to analyse.

使用PerfMon收集数据并进行调试分析。

Found this link while searching for similar issue.

在搜索类似问题时找到这个链接。

http://www.iis.net/learn/troubleshoot/performance-issues/troubleshooting-high-cpu-in-an-iis-7x-application-pool

http://www.iis.net/learn/troubleshoot/performance-issues/troubleshooting-high-cpu-in-an-iis-7x-application-pool

#4


0  

Use procmon to define your problem.

使用procmon来定义您的问题。

#5


0  

I was facing the same issues recently and found a solution which worked for me and reduced the memory consumption level upto a great extent.

我最近遇到了同样的问题,找到了一个解决方案,在很大程度上降低了内存的消耗。

Solution:

解决方案:

First of all find the application which is causing heavy memory usage.

首先,找到导致内存占用严重的应用程序。

You can find this in the Details section of the Task Manager.

您可以在任务管理器的Details部分中找到这一点。

Next.

下一个。

  1. Open the IIS manager.
  2. 打开IIS管理器。
  3. Click on Application Pools. You'll find many application pools which your system is using.
  4. 点击应用程序池。您将发现您的系统正在使用的许多应用程序池。
  5. Now from the task manager you've found which application is causing the heavy memory consumption. There would be multiple options for that and you need to select the one which is having '1' in it's Application column of your web application.
  6. 现在,您已经从任务管理器中找到了哪个应用程序导致了严重的内存消耗。这将有多个选项,您需要选择在web应用程序的应用程序列中有“1”的选项。
  7. When you click on the application pool on the right hand side you'll see an option Advance settings under Edit Application pools. Go to Advanced Settings. 5.Now under General category set the Enable 32-bit Applications to True
  8. 当您单击右边的应用程序池时,您将看到编辑应用程序池下的选项Advance设置。进入高级设置。现在,在通用类别下,将Enable 32位应用程序设置为True
  9. Restart the IIS server or you can see the consumption goes down in performance section of your Task Manager.
  10. 重新启动IIS服务器,或者可以在任务管理器的性能部分看到消耗下降。

If this solution works for you please add a comment so that I can know.

如果这个解决方案对您有效,请添加一个注释,以便我知道。

#6


-4  

I recently had this problem myself, and once I determined which AppPool was causing the problem, the only way to resolve the issue was remove that app pool completly and create a new one for the site to use.

最近我自己也遇到了这个问题,一旦我确定是哪个AppPool导致了这个问题,解决这个问题的唯一方法就是完全删除这个应用程序池,并创建一个新的应用程序池供站点使用。