简体   繁体   English

ASP.NET MVC中的分析和输出缓存

[英]Profiling and output caching in ASP.NET MVC

So I was recently hired by a big department of a Fortune 50 company, straight out of college. 因此,我最近刚从大学毕业时就被一家财富50强公司的大部门雇用。 I'll be supporting a brand new ASP.NET MVC app - over a million lines of code written by contractors over 4 years. 我将支持全新的ASP.NET MVC应用程序-承包商在4年内编写的超过一百万行代码。 The system works great with up to 3 or 4 simultaneous requests, but becomes very slow with more. 该系统最多可同时处理3或4个请求,但随着更多请求变得非常慢。 It's supposed to go live in 2 weeks ... I'm looking for practical advice on how to drastically improve the scalability. 它应该在2周内上线...我正在寻找有关如何大幅改善可伸缩性的实用建议。

The advice I was given in Uni is to always run a profiler first. 我在Uni中得到的建议是始终始终先运行探查器。 I've already secured a sizeable tools budget with my manager, so price wouldn't be a problem. 我已经和经理取得了可观的工具预算,因此价格不会成为问题。 What is a good or even the best profiler for ASP.NET MVC? 什么是ASP.NET MVC的最佳或最佳分析器?

I'm also looking at adding caching. 我也在寻找添加缓存。 There is currently no second level and query cache configured for nHibernate. 当前没有为nHibernate配置第二级和查询缓存。 My current thinking is to use Redis for that purpose. 我目前的想法是将Redis用于此目的。 Also looking at output caching, but unfortunately the majority of the users will login to the site. 还在查看输出缓存,但不幸的是,大多数用户将登录到该站点。 Is there a way to still cache parts of the pages served by MVC? 有没有办法仍然缓存由MVC服务的部分页面?

Do you have any monitoring or instrumentation setup for the application? 您对应用程序有任何监视或检测设置吗? If not, I would highly recommend starting there. 如果没有,我强烈建议从那里开始。 I've been using New Relic for a few years with ASP.NET apps and been very happy with it. 我在ASP.NET应用程序上使用New Relic已经有几年了,对此感到非常满意。

Right off the bat you get a nice graph of request response times broken down into 3 kind of tasks that contribute to the response time 马上,您会得到一张漂亮的请求响应时间图表,该图表分为3种有助于响应时间的任务

  • .NET CLR - Time spent running .NET code .NET CLR-运行.NET代码所花费的时间
  • Database - Time spent waiting on SQL requests 数据库-等待SQL请求所花费的时间
  • Request Queue - Time spent waiting for application workers to become available 请求队列-等待应用程序工作者可用的时间

It also breaks down performance by MVC action so you can see which ones are the slowest. 它还会通过MVC动作破坏性能,因此您可以查看哪些是最慢的。 You also get a breakdown of performance per database query. 您还会获得每个数据库查询的性能明细。 I've used this many times to detect procedures that were way too slow for heavy production loads. 我已经使用了很多次来检测对于繁重的生产负载来说太慢的过程。

If you want to, you can have New Relic add some unobtrusive Javascript to your page that allows you to instrument browser load times. 如果需要,您可以让New Relic在页面上添加一些不引人注目的Javascript,以便您了解浏览器的加载时间。 This helps you figure things out like "my users outside North America spend on average 500ms loading images. I need to move my images to a CDN!" 这可以帮助您解决诸如“我在北美以外的用户平均花费500毫秒来加载图像。我需要将图像移至CDN!”

I would highly recommend you use some instrumentation software like this. 我强烈建议您使用这样的仪器软件。 It will definitely get you pointed in the right direction and help you keep your app available and healthy. 它一定会为您指明正确的方向,并帮助您保持应用程序的可用性和健康状态。

Profiler is a handy tool to watch how apps communicate with your database and debug odd behaviour. Profiler是一种方便的工具,可用于观察应用程序如何与您的数据库进行通信并调试异常行为。 It's not a long-term solution for performance instrumentation given that it puts a load on your server and the results require quite a bit of laborious processing and digestion to paint a clear picture for you. 对于性能检测来说,这不是一个长期的解决方案,因为它给您的服务器带来了负担,并且结果需要相当多的工作和消化才能为您描绘出清晰的画面。

Random thought: check out your application pool configuration and keep and eye out in the event log for too many recycling events. 随机的想法:检查您的应用程序池配置,并留意事件日志中是否有太多的回收事件。 When an application pool recycles, it takes a long time to become responsive again. 当应用程序池回收时,需要长时间才能再次响应。 It's just one of those things can kill performance and you can rip your hair out trying to track it down. 这只是会影响性能的事情之一,您可以扯掉头发以进行追踪。 Improper recycling settings bit me recently so that's why I mention it. 最近,不正确的回收设置使我很头疼,所以才提到它。

For nHibernate analysis (session queries, caching, execution time) you could use HibernatingRhinos Profiler. 对于nHibernate分析(会话查询,缓存,执行时间),可以使用HibernatingRhinos Profiler。 It's developed by the guys that developed nhibernate, so you know it will work really good with it. 它是由开发nhibernate的人员开发的,因此您知道它会非常有用。

Here is the URL for it: http://hibernatingrhinos.com/products/nhprof 这是它的URL: http : //hibernatingrhinos.com/products/nhprof

You could give it a try and decide if it helps you or not. 您可以尝试一下并确定它是否对您有帮助。

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

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