How to analyze the performance of requests in ASP.NET MVC application?

前端 未结 3 523
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 02:53

I would like to capture the hit time, processing time, memory consumption and response time of requests in ASP.NET MVC application.

Is there any way or tool to perfo

相关标签:
3条回答
  • 2020-12-06 03:18

    Not free but it is really good:

    http://www.jetbrains.com/profiler/

    dotTrace is a family of performance and memory profilers for .NET applications.

    Our latest release, dotTrace 5.2 Performance, helps .NET developers quickly find performance bottlenecks and optimize their applications.

    0 讨论(0)
  • 2020-12-06 03:38

    You can create your own little performance test monitor. This is from page 670 of Steven Sanderson's book, Pro Asp.Net MVC 2 Framework:

    public class PerformanceMonitorModule : IHttpModule
    {
        public void Dispose() { /* Nothing to do */ }
        public void Init(HttpApplication context)
        {
            context.PreRequestHandlerExecute += delegate(object sender, EventArgs e)
            {
                HttpContext requestContext = ((HttpApplication)sender).Context;
                Stopwatch timer = new Stopwatch();
                requestContext.Items["Timer"] = timer;
                timer.Start();
            };
            context.PostRequestHandlerExecute += delegate(object sender, EventArgs e)
            {
                HttpContext requestContext = ((HttpApplication)sender).Context;
                Stopwatch timer = (Stopwatch)requestContext.Items["Timer"];
                timer.Stop();
    
                if (requestContext.Response.ContentType == "text/html")
                {
                    double seconds = (double)timer.ElapsedTicks / Stopwatch.Frequency;
                    string result =
                    string.Format("{0:F4} sec ({1:F0} req/sec)", seconds, 1 / seconds);
                    requestContext.Response.Write("<hr/>Time taken: " + result);
                }
            };
        }
    }
    

    Then add to your web.config:

    <add name="PerfModule" type="Namespace.PerformanceMonitorModule, AssemblyName"/>
    
    0 讨论(0)
  • 2020-12-06 03:39

    Check the miniprofiler, developed by the stackoverflow team

    http://code.google.com/p/mvc-mini-profiler/

    This helps you to do some analysis. There is a nuget pacakge available which you can use to add this to your project.

    Scott has written a post about how to use that.

    You can also look into Glimpse.

    There are commerical products to do memory and performance profiling like telerik just trace. You can download their trial version and use that

    0 讨论(0)
提交回复
热议问题