如何分析ASP.NET MVC应用程序中的请求性能?

时间:2022-06-01 18:54:11

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

我想捕获ASP.NET MVC应用程序中的请求的命中时间,处理时间,内存消耗和响应时间。

Is there any way or tool to perform this?

有没有办法或工具来执行此操作?

3 个解决方案

#1


11  

Check the miniprofiler, developed by the * team

检查由*团队开发的miniprofiler

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

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.

这有助于您进行一些分析。有一个nuget pacakge可用于将其添加到您的项目中。

Scott has written a post about how to use that.

斯科特写了一篇关于如何使用它的帖子。

You can also look into Glimpse.

你也可以看看Glimpse。

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

有一些商业产品可以进行内存和性能分析,例如telerik just trace。您可以下载他们的试用版并使用它

#2


6  

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:

您可以创建自己的小型性能测试监视器。这是Steven Sanderson的书,Pro Asp.Net MVC 2框架的第670页:

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:

然后添加到您的web.config:

<add name="PerfModule" type="Namespace.PerformanceMonitorModule, AssemblyName"/>

#3


2  

Not free but it is really good:

不是免费但非常好:

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

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

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

dotTrace是.NET应用程序的性能和内存分析器系列。

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

我们的最新版本dotTrace 5.2性能可帮助.NET开发人员快速找到性能瓶颈并优化其应用程序。

#1


11  

Check the miniprofiler, developed by the * team

检查由*团队开发的miniprofiler

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

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.

这有助于您进行一些分析。有一个nuget pacakge可用于将其添加到您的项目中。

Scott has written a post about how to use that.

斯科特写了一篇关于如何使用它的帖子。

You can also look into Glimpse.

你也可以看看Glimpse。

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

有一些商业产品可以进行内存和性能分析,例如telerik just trace。您可以下载他们的试用版并使用它

#2


6  

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:

您可以创建自己的小型性能测试监视器。这是Steven Sanderson的书,Pro Asp.Net MVC 2框架的第670页:

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:

然后添加到您的web.config:

<add name="PerfModule" type="Namespace.PerformanceMonitorModule, AssemblyName"/>

#3


2  

Not free but it is really good:

不是免费但非常好:

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

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

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

dotTrace是.NET应用程序的性能和内存分析器系列。

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

我们的最新版本dotTrace 5.2性能可帮助.NET开发人员快速找到性能瓶颈并优化其应用程序。