工作进程中cpu占用率高
我目前正在用 C# 编写的 .net Web 应用程序上运行性能测试。我有一个测试工具,可以模拟 Windows Server 2008 上 200 个用户的负载。
这会导致 CPU 使用率非常高,高达约 80%,这是我担心的问题。我觉得这可能是我的代码中的一个问题,因为它是导致 CPU 使用率高的 Web 应用程序的工作流程。
我如何进一步调试以帮助找到导致此问题的代码可能存在的问题?我可以使用任何工具来帮助我完成此任务吗?我正在服务器上运行性能监视器来收集状态,但这只能帮助我到目前为止。
I am currently running performance tests on a .net web application written in c#. I have test tool that simulates a load of 200 users on a windows server 2008.
This is resulting in very hign cpu useage of ~80% which is a concern for me. I feel it may be an issue in my code as its the work process for web application that is causing the high cpu useage.
How can I debug in to this further to help find what the issue may be with my code that is causing this? Are there any tools that I could use to assist me with this? I am running perf monitor on the server to collect states but this only goes so far in assisting me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Visual Studio Ultimate 和 Premium 版本附带一个分析器,可以帮助您快速找到消耗 CPU 最多的方法调用。请参阅:http://msdn.microsoft.com/en-us/library/ms182372 .aspx
另一种选择是 ANTS Profiler,它有 21 天的试用期,而且非常好。请参阅:http://www.red-gate.com/supportcenter/content /ANTS_Profiler/articles/profiling_web_app
Editions Ultimate and Premium of Visual Studio come with a profiler that can help you quickly find method calls that are consuming the most CPU. See: http://msdn.microsoft.com/en-us/library/ms182372.aspx
An alternative is ANTS Profiler, which has a 21-day trial and it's REALLY good. See: http://www.red-gate.com/supportcenter/content/ANTS_Profiler/articles/profiling_web_app
将客户端代码(模拟 200 个用户的测试工具)与服务器分开,并将客户端放在不同的计算机上。
通常客户端代码是瓶颈。
separate the client code (your test tool that simulates 200 users) from the server and put the client on a different machine.
often the client code is the bottleneck.
如果 @Diego 的答案没有产生最佳结果,请将其从 200 个用户增加到 200,000 个用户,然后运行 DebugDiag 并将其设置为使用高 CPU 设置捕获转储并使盒子崩溃。我本打算将此作为评论说出来,但我想我应该为您提供以下步骤:
使用 IIS 定义高 CPU 利用率问题
当 IIS 进程(INETINFO.EXE、DLLHOST.EXE、W3WP.EXE)由于 CPU 使用率过高而停止响应传入请求并且不提供网页服务时,将确定 CPU 使用率过高。我们将使用以下步骤来获取所需的数据。
故障排除步骤
从 http://www.microsoft.com/downloads/details.aspx?FamilyID=9bfa49bc-376b-4a54-95aa-73c9156706e7&DisplayLang=en 在服务器上。默认安装路径为 C:\Program Files\IIS Resources\DebugDiag,可以在安装过程中更改。
在问题发生之前设置性能监视器日志记录:
a) 打开 DebugDiag(开始 -> 程序 -> IIS 诊断)
b) 进入工具菜单->选项和设置
c) 选择“性能日志”选项卡
d) 单击“启用性能计数器数据记录”
e) 单击“确定”
注意:数据采样间隔和开始监控的时间取决于 CPU 峰值重现的时间。
通过以下步骤取消选中“调试异常捕获”(IIS5 和 IIS5.1):
a) 打开 IIS 的 MMC
b) 右键单击计算机名称,然后单击“属性”
c) 单击主 WWW 属性的编辑按钮
d) 转到主目录选项卡
e) 单击底部的“配置”按钮
f) 转到“进程选项”选项卡并取消选中“启用调试异常捕获”
g) 单击“确定”
通过以下步骤创建挂起规则:
a) 打开 DebugDiag(开始 -> 程序 -> IIS 诊断)
b) 选择“IIS 挂起”并单击“下一步”
c) 单击“添加 URL”并输入重现挂起的 URL,例如 http://ComputerName/HelloWorld.aspx,然后单击“确定”。当询问“测试指定的 URL”时,选择“是”。
d) 单击“确定”,然后单击“下一步”
e) 单击“添加转储目标”并选择所需的目标类型
f) 单击“确定”,然后单击“下一步”
g) 单击“规则名称”的“下一步”。可以在此处更改“用户转储位置”。
h) 选择“立即激活规则”并单击完成
请注意,状态为“活动”。每次创建转储文件时,Userdump 计数都会增加。
如果安装时服务器处于高 CPU 状态,请手动获取数据。在 DebugDiag 中,转到“进程”选项卡,右键单击进程并选择“创建完整用户转储”。
在转储进程后大约两分钟停止 PerfMon 日志记录:
a) 打开 DebugDiag(开始 -> 程序 -> IIS 诊断)
b) 进入工具菜单->选项和设置
c) 选择“性能日志”选项卡
d) 单击“禁用性能计数器数据记录”
e)
通过选择“高级分析”选项卡并单击“添加数据文件”来分析转储。添加 .dmp 后,选择“Crash/Hang Analyzers”脚本并单击“开始分析”。完成后,将在 C:\Program Files\IIS Resources\DebugDiag\Reports 中创建报告 (.mht) 并显示如果使用自定义 DLL,则可以在 Internet Explorer 中添加自定义 PDB 文件的符号路径(工具菜单 -> 选项和设置 -> 符号搜索路径)
If @Diego answer doesn't yeild the best results, bump it up from 200 to 200,000 users and run DebugDiag and set it up to capture the dump with high CPU Settings and crash the box. I was going to say this as a comment but I thought I'd give you the steps:
Defining High CPU Utilization Problems with IIS
High CPU is identified when an IIS process (INETINFO.EXE, DLLHOST.EXE, W3WP.EXE) stops responding to incoming requests and does not serve web pages due to excessive CPU Utilization. We will use the steps below to get the data needed.
Troubleshooting Steps
Install DebugDiag from http://www.microsoft.com/downloads/details.aspx?FamilyID=9bfa49bc-376b-4a54-95aa-73c9156706e7&DisplayLang=en on the server. The default install path is C:\Program Files\IIS Resources\DebugDiag and can be changed during the installation.
Set up Performance Monitor Logging before the issue occurs:
a) Open DebugDiag (Start -> Programs -> IIS Diagnostics)
b) Go to the Tools menu -> Options and Settings
c) Select the Performance Log tab
d) Click “Enable Performance Counter Data Logging”
e) Click OK
Note: The Data Sampling Interval and time to start monitoring is subjective to when the CPU spike reproduces.
Uncheck Debug Exception Catching (IIS5 and IIS5.1) with the following steps:
a) Open the MMC for IIS
b) Right-click the computer name and click Properties
c) Click the Edit button for the Master WWW properties
d) Go to the Home Directory tab
e) Click the Configuration button towards the bottom
f) Go to the "Process Options" tab and uncheck "Enable Debug Exception Catching"
g) Click OK
Create a Hang Rule with the following steps:
a) Open DebugDiag (Start -> Programs -> IIS Diagnostics)
b) Select "IIS Hang" and click Next
c) Click "Add URL" and enter a URL that reproduces the hang, e.g. http://ComputerName/HelloWorld.aspx, and click OK. Select YES when asked to "test the specified URL".
d) Click OK and click Next
e) Click "Add Dump Target" and select the desired Target Type
f) Click OK and click Next
g) Click Next for "Rule Name". The "Userdump Location" can be changed here.
h) Select "Activate the rule now" and click Finish
Notice the Status is Active. The Userdump Count will increase each time a dump file is created.
Get the Data Manually if the server is in a high CPU state at the time of the install. In DebugDiag, go to the Processes tab, right-click the process and select "Create Full Userdump".
Stop PerfMon Logging about two minutes after taking a dump of the processes:
a) Open DebugDiag (Start -> Programs -> IIS Diagnostics)
b) Go to the Tools menu -> Options and Settings
c) Select the Performance Log tab
d) Click "Disable Performance Counter Data Logging"
e) Click OK
Analyze the Dump by selecting the "Advanced Analysis" tab and clicking "Add Data Files". When the .dmp is added, select the "Crash/Hang Analyzers” script and click "Start Analysis". When finished, a report (.mht) will be created in C:\Program Files\IIS Resources\DebugDiag\Reports and displayed in Internet Explorer with the results and recommendations. If using custom DLL’s, the Symbol path (Tools menu -> Options and Settings -> Symbol Search Path) to the custom PDB files can be added.
到目前为止有趣的答案。有 Psscor4 工具 - SOS.dll 调试扩展的继承者。它有助于调查来自 CLR 的许多实时数据。我建议深入阅读 Tess' od Toms 博客。很多用于 ASP.NET 调试的内容。
另外,请查看 PerfView 工具。我还没有测试过,但它声称能够比 CLPProfiler 更好地处理大型堆。
Interesting answers so far. There is the Psscor4 tool - the successor of SOS.dll debugging extension. It helps investigating many live data from the CLR. I suggest some deep readings in Tess' od Toms blogs. Lot of stuff for ASP.NET debugging.
Also, take a look at the PerfView tool. I didn't test is yet, but it claims to be able to handle large sized heaps better than CLPProfiler.