如何对正在运行的 ASP.NET 应用程序进行非侵入式分析?

发布于 2024-08-12 06:09:35 字数 234 浏览 3 评论 0 原文

情况: ASP.NET 实时网站有时太忙。

在代码中添加完整的分析会对性能产生太大的影响。使用性能监视器,我们很快就在“所有堆中的字节数”计数器中找到了锯齿形数字,该计数器与 GC 计数器配对。我们认为某些代码片段是罪魁祸首。

对于某些页面、库、函数或其他什么,是否有办法或可能临时“注入”分析?最好尽可能轻,因为任何额外的开销都可能导致这个脆弱的系统崩溃。我知道 .NET 不支持方法回调挂钩(这在 AOP 中很常见)。

Situation: ASP.NET live website that's occasionally too busy.

Adding full profiling to the code will be too heavy an impact on the performance. Using performance monitor, we've quickly find a saw-teeth figure in the "bytes in all heaps" counter, which pair with the GC counters. We consider certain pieces of code as being the culprit.

Is there a way or possibility to temporarily "inject" profiling, either for certain pages, libs, functions or whatever? Preferably as lightweight as possible, as any additional overhead might bring down this fragile system. I'm aware that .NET does not support method callback hooks (as is common with AOP).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

昨迟人 2024-08-19 06:09:36

一些想法:

  1. 使用自定义 Windows 性能计数器。它们非常轻量级(1 到 2%),您不仅可以使用它们进行计数,还可以使用它们进行计时测量,以查看某些操作慢于阈值的频率等。
  2. 如果您使用的是 IIS 7,您可以启用失败请求跟踪。为了限制性能影响,请注意不要为太多页面启用它。这些跟踪可以提供大量详细信息,如果需要,您可以通过编程方式向其中注入更多信息。
  3. 使用 Windows 事件日志在异常情况下写入自定义详细信息。只要您不过分,对性能的影响就很小。
  4. 锯齿状内存行为的原因之一可能是在应该调用 Dispose() 时没有调用(或者将 IDisposable 对象包装在 using 语句中,这将为您调用它);您可能需要检查您的代码以查找该内容。

如果它有帮助,您可能还对我书中的性能提示感兴趣:Ultra-快速 ASP.NET

编辑:您还可以尝试使用 .NET Memory Profiler(提供免费试用)来附加到正在运行的进程。与计数器相比,它具有相当大的侵入性,但如果您需要捕获当前内存状态的快照来调试问题,可能没有更好的选择。

A few ideas:

  1. Use custom Windows performance counters. They are very lightweight (1 to 2%), and you can use them not just to count, but also for timing measurements, to look at how often certain operations are slower than a threshold, etc.
  2. If you're using IIS 7, you can enable Failed Request Tracing. To limit the perf impact, be careful to not enable it for too many pages. Those traces can provide lots of detail, and you can inject more info into them programmatically if you need to.
  3. Use the Windows Event log to write custom details under exceptional conditions. Perf impact is minimal as long as you don't over-do it.
  4. One cause of sawtooth memory behavior can be not calling Dispose() when you should (or wrapping IDisposable objects in using statements, which will call it for you); you might want to review your code to look for that.

In case it's helpful, you might also be interested in the performance tips from my book: Ultra-Fast ASP.NET.

Edit: you might also try using .NET Memory Profiler (free trial available) to attach to the running process. It's fairly invasive compared to counters, but if you need to capture a snapshot of the current state of memory to debug your problem, there may not be a better choice.

财迷小姐 2024-08-19 06:09:36

是的,您可以在应用程序运行时获取应用程序的内存转储并查看其内容保存在记忆中。这应该会强化或否定你的假设。

Yes, you can take a memory dump of the application as it's running and see what it's holding in memory. This should reinforce or deny your assumptions.

猫烠⑼条掵仅有一顆心 2024-08-19 06:09:36

我最近针对类似的挑战发布了一个可能的解决方案:

分析多层、分布式 Web 应用程序(服务器端) 显示了一种高级方法(在 URL 级别进行分析),即:

  • 独立于平台和语言
  • 完全非侵入性
  • 提供高级方法您的应用程序花费大部分时间的图片

这个想法是使用现有网络日志并将其转换为“一张图片相当于 1000 个单词”类型图表。

这种方法对于需要更精细细节的用例来说是不够的,但它对我个人有帮助,并且可能值得在您的案例中探索。

I recently posted a possible solution to a similar challenge:

Profiling a multi-tiered, distributed, web application (server side) shows a high level approach (profiling on the URL level) that is:

  • platform and language independent
  • completely non invasive
  • gives a high-level picture of where your application is spending most of its time

The idea is to use existing web logs and convert them into a "one-picture is worth a 1000 words" kind of chart.

This approach is not sufficient for use-cases requiring more fine-level detail, but it helped me personally, and may be worth exploring in your case.

烟柳画桥 2024-08-19 06:09:36

你能做到这个 在 ASP .NET 上?这是了解正在发生的情况的快速方法。

Can you do this on ASP .NET? It's a good quick way to find out what's going on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文