I'm seeing consistently high CPU usage for my ASP.NET web application (on the live production box only, naturally....!) and I'm trying to narrow down the cause - it's basically maxing out a quad core Xeon box and there's no way it should be able to do that!
我看到我的ASP.NET Web应用程序的CPU使用率一直很高(仅在现场制作盒上,自然......!)而且我正在努力缩小原因 - 它基本上是最大化四核Xeon盒子并且它无法做到这一点!
The CPU usage of the web process is generally higher than that of the DB process - which rings alarm bells to me on its own (?).
Web进程的CPU使用率通常高于数据库进程的CPU使用率 - 这会自动向我发出警报(?)。
However, using the standard profiling tools (dotTrace, Red Gate etc) only show you the time spent in individual methods (rather than actual CPU usage) - and ultimately still highlight methods that are DB-bound. While this might indicate opportunities for caching or better indexes, I don't see how that in itself would result in high CPU usage of the web application process?
但是,使用标准的分析工具(dotTrace,Red Gate等)只会显示在单个方法中花费的时间(而不是实际的CPU使用率) - 并最终仍然突出显示受DB限制的方法。虽然这可能表明缓存或更好的索引的机会,但我不知道它本身会如何导致Web应用程序进程的高CPU使用率?
Any suggestions or tips as to how I can narrow this down?
关于如何缩小范围的任何建议或提示?
Thanks!
4 个解决方案
#1
Some suggestions to try at the first place.
一些建议尝试在第一位。
1.Deploy with Release Build Check whether the deployed product is in release mode. By running in debug mode, lot of time is wasted loading the pdbs along with the assemblies.
1.Deploy with Release Build检查已部署的产品是否处于发布模式。通过在调试模式下运行,浪费了大量时间将pdbs与程序集一起加载。
2.Disable ViewState Disable viewstate if its not required. ViewState is nothing but data stored in hidden fields to be persisted between requests. it increases the total payload of the page both when served and when requested. There is also an additional overhead incurred when serializing or deserializing view state data that is posted back to the server. Lastly, view state increases the memory allocations on the server.
2.Disable ViewState如果不需要,则禁用viewstate。 ViewState只是存储在隐藏字段中的数据,可以在请求之间保留。它会在服务时和请求时增加页面的总有效负载。在序列化或反序列化发回服务器的视图状态数据时,还会产生额外的开销。最后,视图状态增加了服务器上的内存分配。
3.Disable Session State:
3.Disable Session State:
If you are not going to use it disable Session State. By default it’s on. You can actually turn this off for specific pages or for the whole application.
如果您不打算使用它,请禁用会话状态。默认情况下它已启用。实际上,您可以针对特定页面或整个应用程序关闭此功能。
There are some basic ASP.NET application performance monitoring, check these two MSDN articles "Monitoring ASP.NET Application Performance" and Performance Counters for ASP.NET
有一些基本的ASP.NET应用程序性能监视,请查看这两篇MSDN文章“监视ASP.NET应用程序性能”和ASP.NET的性能计数器
#2
Can you set up some unit tests to call various methods and see what their impact is on processor usage? Visual Studio has some testing tools built in if you're using Team System, but even if you're not, you could write a multithreaded tester to call particular functions hundreds of times.
你能设置一些单元测试来调用各种方法,看看它们对处理器使用的影响是什么?如果您使用Team System,Visual Studio内置了一些测试工具,但即使您不是,也可以编写一个多线程测试程序来调用特定函数数百次。
If you'd like some pointers on how to do this, I can help you build some basic unit testing.
如果您想了解如何执行此操作,我可以帮助您构建一些基本的单元测试。
#3
are you recording/reporting unhandled exception? If not do so and check if any of them correspond with your high CPD spikes you may have a stack overflow causing the spikes.
你在录制/报告未处理的例外吗?如果不这样做并检查它们是否与您的高CPD峰值相对应,则可能会出现堆栈溢出导致峰值。
http://msdn.microsoft.com/en-us/library/ms998306.aspx
You could also look into recoding the time of each request by using a HttpModule and checking which requests are taking up the most time which may indicate the pages that are causing the issue.
您还可以考虑使用HttpModule重新编码每个请求的时间,并检查哪些请求占用的时间最多,这可能表示导致问题的页面。
#4
As Pradeepno notes, the place to start with is really performance counters--they can give you a very good idea of what is consuming what part of the CPU.
正如Pradeepno所说,开始的地方实际上是性能计数器 - 它们可以让您非常了解消耗CPU的哪些部分。
The web app usage being higher than DB usage isn't entirely suprising. If you have decent db design, most web apps are barely going to cause a decently powered DB server to break a sweat.
Web应用程序使用率高于数据库使用率并不完全令人惊讶。如果你有一个不错的数据库设计,大多数网络应用程序几乎不会导致一个体面的动力DB服务器打破汗水。
#1
Some suggestions to try at the first place.
一些建议尝试在第一位。
1.Deploy with Release Build Check whether the deployed product is in release mode. By running in debug mode, lot of time is wasted loading the pdbs along with the assemblies.
1.Deploy with Release Build检查已部署的产品是否处于发布模式。通过在调试模式下运行,浪费了大量时间将pdbs与程序集一起加载。
2.Disable ViewState Disable viewstate if its not required. ViewState is nothing but data stored in hidden fields to be persisted between requests. it increases the total payload of the page both when served and when requested. There is also an additional overhead incurred when serializing or deserializing view state data that is posted back to the server. Lastly, view state increases the memory allocations on the server.
2.Disable ViewState如果不需要,则禁用viewstate。 ViewState只是存储在隐藏字段中的数据,可以在请求之间保留。它会在服务时和请求时增加页面的总有效负载。在序列化或反序列化发回服务器的视图状态数据时,还会产生额外的开销。最后,视图状态增加了服务器上的内存分配。
3.Disable Session State:
3.Disable Session State:
If you are not going to use it disable Session State. By default it’s on. You can actually turn this off for specific pages or for the whole application.
如果您不打算使用它,请禁用会话状态。默认情况下它已启用。实际上,您可以针对特定页面或整个应用程序关闭此功能。
There are some basic ASP.NET application performance monitoring, check these two MSDN articles "Monitoring ASP.NET Application Performance" and Performance Counters for ASP.NET
有一些基本的ASP.NET应用程序性能监视,请查看这两篇MSDN文章“监视ASP.NET应用程序性能”和ASP.NET的性能计数器
#2
Can you set up some unit tests to call various methods and see what their impact is on processor usage? Visual Studio has some testing tools built in if you're using Team System, but even if you're not, you could write a multithreaded tester to call particular functions hundreds of times.
你能设置一些单元测试来调用各种方法,看看它们对处理器使用的影响是什么?如果您使用Team System,Visual Studio内置了一些测试工具,但即使您不是,也可以编写一个多线程测试程序来调用特定函数数百次。
If you'd like some pointers on how to do this, I can help you build some basic unit testing.
如果您想了解如何执行此操作,我可以帮助您构建一些基本的单元测试。
#3
are you recording/reporting unhandled exception? If not do so and check if any of them correspond with your high CPD spikes you may have a stack overflow causing the spikes.
你在录制/报告未处理的例外吗?如果不这样做并检查它们是否与您的高CPD峰值相对应,则可能会出现堆栈溢出导致峰值。
http://msdn.microsoft.com/en-us/library/ms998306.aspx
You could also look into recoding the time of each request by using a HttpModule and checking which requests are taking up the most time which may indicate the pages that are causing the issue.
您还可以考虑使用HttpModule重新编码每个请求的时间,并检查哪些请求占用的时间最多,这可能表示导致问题的页面。
#4
As Pradeepno notes, the place to start with is really performance counters--they can give you a very good idea of what is consuming what part of the CPU.
正如Pradeepno所说,开始的地方实际上是性能计数器 - 它们可以让您非常了解消耗CPU的哪些部分。
The web app usage being higher than DB usage isn't entirely suprising. If you have decent db design, most web apps are barely going to cause a decently powered DB server to break a sweat.
Web应用程序使用率高于数据库使用率并不完全令人惊讶。如果你有一个不错的数据库设计,大多数网络应用程序几乎不会导致一个体面的动力DB服务器打破汗水。