简体   繁体   English

什么[ASP.net] MVC在我的控制器之前做什么?

[英]Whats [ASP.net]MVC doing BEFORE my controller?

I've got a bit of a strange performance issue occurring with my MVC Controller, or rather before it? 我的MVC控制器出现了一些奇怪的性能问题,或者更确切地说是之前的问题?

According to the Mini Profiler output, there is a 120ms overhead before reaching my controller. 根据Mini Profiler输出,在到达我的控制器之前有120ms的开销。

Does anyone know why this would be? 有谁知道为什么会这样? This is on a server (Not local), that has Compilation debug=false set, so it's not an issue of not running in release mode. 这是在服务器(非本地)上,具有Compilation debug=false set,因此不存在未在release模式下运行的问题。

Everything after it, I can tune/amend, but before it? 在它之后的一切,我可以调整/修改,但在此之前? and I'm lost.. 我迷路了..

Thoughts?? 思考?

在此输入图像描述

Update 更新

After some performance tooling I came across enter link description here & enter link description here which resulted in the below: 经过一些性能工具后,我偶然在这里 输入链接描述并在 此处 输入链接描述 ,结果如下:

Most expensive stacks ------------------------------------ System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute System.Web.HttpApplication.ExecuteStep System.Web.HttpApplication+PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost (1716011) 最昂贵的堆栈------------------------------------ System.Web.HttpApplication + CallHandlerExecutionStep.System.Web .HttpApplication.IExecutionStep.Execute System.Web.HttpApplication.ExecuteStep System.Web.HttpApplication + PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting .PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost(1716011)

Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.Unity.UnityContainer.DoBuildUp Microsoft.Practices.Unity.UnityContainer.DoBuildUp System.Web.Mvc.DefaultControllerFactory+DefaultControllerActivator.Create System.Web.Mvc.DefaultControllerFactory.CreateController System.Web.Mvc.MvcHandler.ProcessRequestInit System.Web.Mvc.MvcHandler+< Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2 .BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft.Practices.ObjectBuilder2.BuilderContext.NewBuildUp Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp Microsoft .Practices.Unity.UnityContainer.DoBuildUp Microsoft.Practices.Unity.UnityContainer.DoBuildUp System.Web.Mvc.DefaultControllerFactory + DefaultControllerActivator.Create System.Web.Mvc.DefaultControllerFactory.CreateController System.Web.Mvc.MvcHandler.ProcessRequestInit System.Web。 Mvc.MvcHandler + < >c__DisplayClass6.b__2 System.Web.Mvc.SecurityUtil+<>c__DisplayClassb`1.b__a System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute System.Web.HttpApplication.ExecuteStep System.Web.HttpApplication+PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost (936006) > c__DisplayClass6.b__2 System.Web.Mvc.SecurityUtil + <> c__DisplayClassb`1.b__a System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust System.Web.HttpApplication + CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute System.Web.HttpApplication。 ExecuteStep System.Web.HttpApplication + PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods。 MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost(936006)

Microsoft.Win32.Win32Native.CoCreateGuid StackExchange.Profiling.Timing..ctor StackExchange.Profiling.MVCHelpers.ProfilingViewEngine.Find System.Web.Mvc.ViewEngineCollection+<>c__DisplayClassc.b__a System.Web.Mvc.ViewEngineCollection.Find System.Web.Mvc.ViewEngineCollection.Find System.Web.Mvc.ViewResult.FindView System.Web.Mvc.ViewResultBase.ExecuteResult System.Web.Mvc.ControllerActionInvoker+<>c__DisplayClass1c.b__19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters System.Web.Mvc.ControllerActionInvoker.InvokeAction System.Web.Mvc.Controller.ExecuteCore System.Web.Mvc.ControllerBase.Execute System.Web.Mvc.MvcHandler+<>c__DisplayClass6+<>c__DisplayClassb.b__5 System.Web.Mvc.Async.AsyncResultWrapper+<>c__DisplayClass1.b__0 System.Web.Mvc.MvcHandler+<>c__DisplayClasse.b__d System.Web.HttpApplication+CallHandlerExecutionStep.System.Web.HttpA Microsoft.Win32.Win32Native.CoCreateGuid StackExchange.Profiling.Timing..ctor StackExchange.Profiling.MVCHelpers.ProfilingViewEngine.Find System.Web.Mvc.ViewEngineCollection + <> c__DisplayClassc.b__a System.Web.Mvc.ViewEngineCollection.Find System.Web.Mvc .ViewEngineCollection.Find System.Web.Mvc.ViewResult.FindView System.Web.Mvc.ViewResultBase.ExecuteResult System.Web.Mvc.ControllerActionInvoker + <> c__DisplayClass1c.b__19 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter System.Web.Mvc.ControllerActionInvoker .InvokeActionResultFilter System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters System.Web.Mvc.ControllerActionInvoker.InvokeAction System.Web.Mvc.Controller.ExecuteCore System.Web.Mvc.ControllerBase.Execute System.Web.Mvc.MvcHandler + <> c__DisplayClass6 + <> c__DisplayClassb.b__5 System.Web.Mvc.Async.AsyncResultWrapper + <> c__DisplayClass1.b__0 System.Web.Mvc.MvcHandler + <> c__DisplayClasse.b__d System.Web.HttpApplication + CallHandlerExecutionStep.System.Web.HttpA pplication.IExecutionStep.Execute System.Web.HttpApplication.ExecuteStep System.Web.HttpApplication+PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost (780005) pplication.IExecutionStep.Execute System.Web.HttpApplication.ExecuteStep System.Web.HttpApplication + PipelineStepManager.ResumeSteps System.Web.HttpApplication.BeginProcessRequestNotification System.Web.HttpRuntime.ProcessRequestNotificationPrivate System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting。 PipelineRuntime.ProcessRequestNotification System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper System.Web.Hosting.PipelineRuntime.ProcessRequestNotification ===> Cost(780005)

Could unity be cause some issues? 团结会导致一些问题吗?

You should have a look on the The ASP.NET MVC Pipeline 您应该看看The ASP.NET MVC Pipeline

The ASP.NET MVC Pipeline can be divided into the following parts - ASP.NET MVC Pipeline可以分为以下几个部分 -

  • App initialisation - n this method, you can add Route objects to the static RouteTable.Routes collection (which is of type RouteCollection). App initialisation - 在此方法中,您可以将Route对象添加到静态RouteTable.Routes集合(其类型为RouteCollection)。

  • Routing Part – Routing module tries to match the incoming URL with the routing table, and calling the corresponding IRouteHandler. Routing Part - 路由模块尝试将传入的URL与路由表进行匹配,并调用相应的IRouteHandler。

  • Controller creation – the IControllerFactory creates an instance of the controller based on route parameters and default naming conventions. Controller creation - IControllerFactory根据路由参数和默认命名约定创建控制器实例。

  • Action Execution – the IActionInvoker identifies the method to be executed, the IModelBinder validates and binds the method parameters and the IFilterProvider discovers filters to be applied. Action Execution - IActionInvoker标识要执行的方法,IModelBinder验证并绑定方法参数,IFilterProvider发现要应用的过滤器。 The Action returns a type ActionResult. Action返回一个ActionResult类型。

  • View – the IViewEngine instantiates the correct view engine and the model is passed to the view. View - IViewEngine实例化正确的视图引擎,并将模型传递给视图。 Using Model Validation Provider, the validation rules are retrieved to create client-side validation scripts as well as remote validation scripts 使用模型验证提供程序,检索验证规则以创建客户端验证脚本以及远程验证脚本

For More Info : 更多信息:

http://blog.stevensanderson.com/2007/11/20/aspnet-mvc-pipeline-lifecycle/

i am sorry for my english 我很抱歉我的英语

there are many 有许多
1.Application_BeginRequest(and AuthenticateRequest) in global or some HttpModule 1.Application_BeginRequest(和AuthenticateRequest)在全局或一些HttpModule中
2.filters 2.filters
3.mvc framework,controller factory,action invoker and so on 3.mvc框架,控制器工厂,动作调用程序等
4.when the first time run,it cost many to compile il to native 4.第一次运行时,将il编译为本机需要花费很多

i think you can use a Stopwatch to check how much time the code in you action spend 我认为您可以使用秒表来检查您的操作代码花费的时间
so that you can find out where is the point take to much time 这样你就可以找出需要花费很多时间的地方

120ms is not the time spend before run action ,i think it is time the action done 120ms不是运行前花费的时间,我认为是行动完成的时间

by the way 120ms is not too bad 顺便说一下120ms并不算太糟糕

update 更新

public ActionResult Index()
{
    var profiler = MiniProfiler.Current;
    using (profiler.Step("action"))
    {
        return View();
    }
}

在此输入图像描述
this pic is above code run result so you can see 这张图片高于代码运行结果,所以你可以看到
action is a child only cost 1.9 行动是一个孩子只需1.9
and http://...... cost 302,it include controller,action 和http:// ......成本302,它包括控制器,动作

so you should check most time cost inside you action code or outside you action code 所以你应该检查你的动作代码或动作代码之外的大部分时间成本
in the pic,it cost 300+ because it is 1st run,2nd run is just cost 4 在图片中,它花费300+,因为它是第一次运行,第二次运行只需4次
1st run must be slow 第一轮必须慢

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

相关问题 如何在进行重定向之前确保 controller 和操作存在,asp.net mvc3 - How to make sure controller and action exists before doing redirect, asp.net mvc3 在 ASP.net MVC 中,我可以在完成 controller 操作之前处理我的 cshtml 逻辑吗? - In ASP.net MVC Can I process through my cshtml logic before finishing the controller action? ASP.NET MVC在控制器实例化之前进行身份验证 - ASP.NET MVC Authenticate before controller instantiated asp.net MVC控制器不会在内存数据库中保留 - The asp.net MVC controller does not persist my in memory database ASP.NET MVC 找不到我的控制器方法 - ASP.NET MVC can't find my controller method ASP.Net MVC-正确执行MVVM - ASP.Net MVC - doing MVVM correctly 强制从ASP.NET MVC中的属性重定向,直到到达ASP.NET MVC中的控制器部分 - Force redirect from attribute in ASP.NET MVC before reach a section from controller in ASP.NET MVC 复制本地!= true System.Web.MVC-Asp.net MVC 2控制器中的字典错误操作前 - Copy Local != true System.Web.MVC - Asp.net MVC 2 Dictionary Error in Controller Before Action ASP.NET MVC4验证错误-怎么了 - ASP.NET MVC4 Validation Error - Whats wrong LINQ ASP.NET MVC存储库模式的最佳实践是什么 - Whats the best practice of linq ASP.NET MVC respository pattern
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM