简体   繁体   English

长时间运行的应用程序变慢

[英]Long running application slows down

There is an application that consists of three executable files. 有一个由三个可执行文件组成的应用程序。 One of them - a dispatcher, which runs other executables. 其中之一 - 调度程序,运行其他可执行文件。 The dispatcher receives a code from an executable at its completion. 调度程序在完成时从可执行文件接收代码。 That is, only the dispatcher is always running, other executables unloads and loads again. 也就是说,只有调度程序始终在运行,其他可执行文件会卸载并再次加载。 The application runs on the point of service and work around the clock. 该应用程序在服务点运行并全天候工作。 At the first launch the application works fast. 在第一次启动时,应用程序运行得很快。 At the end of the day, the application works terribly slow. 在一天结束时,应用程序运行速度非常慢。 What could be the reason for such a behavior? 这种行为可能是什么原因?

There could be lot of reasons for a slow down over time. 随着时间的推移,可能有很多原因导致减速。 Anywhere from a slow memory leak to anti-virus. 从缓慢的内存泄漏到反病毒的任何地方。 The best you can do is try to build evidence (data) about what area of the application to look first. 您可以做的最好的事情是尝试建立关于首先要查看的应用程序区域的证据 (数据)。 Try not to talk it over with many devs because everyone will have a different opinion about what might be wrong. 尽量不与许多开发者交谈,因为每个人都会对可能出错的地方有不同的看法。 Get the data! 获取数据!

How to get the data: 如何获取数据:

perfmon perfmon is your friend. perfmon perfmon是你的朋友。 There are a lot of counters that you can look at (system wide as well as process specific). 您可以查看许多计数器(系统范围以及特定于流程)。 So you can start by profiling the big 4 (that's memory, disk usage, cpu and networking). 所以你可以从分析大4(那是内存,磁盘使用,cpu和网络)开始。 There are a lot of posts out there about what counters are best, so I won't go into too much detail about the perf counters here. 关于什么计数器是最好的,有很多帖子 ,所以我不会在这里详细介绍perf计数器。

windbg If you indeed see that memory is growing and not being collected it's time to bring in the big guns. windbg如果你确实看到记忆力正在增长而没有被收集,那么就该引进大枪了。 .NET is great at abstracting memory usage away from developers, but this means we have to get underneath .NET sometimes to find out what is not allowing the Garbage Collector to do its work. .NET非常适合从开发人员那里抽象内存使用,但这意味着我们必须在.NET下面找到不允许垃圾收集器完成其工作的内容。 windbg with the sos.dll (managed extensions) is a great tool for this. 带有sos.dll (托管扩展)的windbg是一个很棒的工具。 The hardest part of windbg (in my experience) is just getting the sos extensions loaded properly. windbg中最困难的部分(根据我的经验)只是正确加载了sos扩展。 You have to pay close attention to what target architecture (64 or 32) you are analysing and what CLR version you are running on. 您必须密切关注要分析的目标体系结构(64或32)以及正在运行的CLR版本。

procdump procdump by sysinternals is a great little utility to take memory snapshots from a running process. sysinternals的procdump procdump是一个很好的小工具,用于从正在运行的进程中获取内存快照。 These snapshots (.dmp files) can then be analyzed by windbg. 然后可以通过windbg分析这些快照(.dmp文件)。

sos The sos.dll has shipped with the .NET Framework since v2. sos自v2以来,sos.dll随.NET Framework一起提供。 With v4, Visual Studio 2010 has integrated sos and allows you to analyze .dmp files! 使用v4,Visual Studio 2010集成了sos并允许您分析.dmp文件!

The sos commands for memory leaks that I have found most useful are: 我发现最有用的内存泄漏的sos命令是:

!eeheap -gc (overview of what is in each generation of each heap) !eeheap -gc (每个堆的每一代中的内容概述)

!dumpheap -min <size> (dumps out all objects and types, over a particular <size> ) !dumpheap -min <size> (转储所有对象和类型,超过特定的<size>

!dumpheap -type <type> (dump out all objects of a specific <type> ) !dumpheap -type <type> (转出特定<type>所有对象)

!gcroot <address> (prints out a stack so you can see what parent object is pinning in the GC) !gcroot <address> (打印出一个堆栈,这样你就可以看到GC中的父对象固定了什么)

!do <address> (prints out memory of a specific object) !do <address> (打印出特定对象的内存)

Some other pointers: 其他一些指示:

Usually, you want to snapshot memory under load, so it would be good to have some way to simulate that from outside the system. 通常,您希望在负载下快照内存,因此最好有一些方法来从系统外部模拟内存。 So, it is good to get this running ahead of time and even work it into the QA process for the application. 因此,最好提前运行,甚至将其用于应用程序的QA流程。

For performance problems it is usually best to take regular snapshots over time with a running application. 对于性能问题,通常最好使用正在运行的应用程序随时间拍摄常规快照。 Then you can compare the snapshots when you analyse. 然后,您可以在分析时比较快照。

Well, that was a bit longer than I intended, but hopefully worth it! 嗯,这比我想要的要长一点,但希望值得!

您必须检查调度程序应用程序的内存使用情况......似乎您没有处置未使用的对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM