簡體   English   中英

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

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

我的MVC控制器出現了一些奇怪的性能問題,或者更確切地說是之前的問題?

根據Mini Profiler輸出,在到達我的控制器之前有120ms的開銷。

有誰知道為什么會這樣? 這是在服務器(非本地)上,具有Compilation debug=false set,因此不存在未在release模式下運行的問題。

在它之后的一切,我可以調整/修改,但在此之前? 我迷路了..

思考?

在此輸入圖像描述

更新

經過一些性能工具后,我偶然在這里 輸入鏈接描述並在 此處 輸入鏈接描述 ,結果如下:

最昂貴的堆棧------------------------------------ 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 + < > 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 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)

團結會導致一些問題嗎?

您應該看看The ASP.NET MVC Pipeline

ASP.NET MVC Pipeline可以分為以下幾個部分 -

  • App initialisation - 在此方法中,您可以將Route對象添加到靜態RouteTable.Routes集合(其類型為RouteCollection)。

  • Routing Part - 路由模塊嘗試將傳入的URL與路由表進行匹配,並調用相應的IRouteHandler。

  • Controller creation - IControllerFactory根據路由參數和默認命名約定創建控制器實例。

  • Action Execution - IActionInvoker標識要執行的方法,IModelBinder驗證並綁定方法參數,IFilterProvider發現要應用的過濾器。 Action返回一個ActionResult類型。

  • View - IViewEngine實例化正確的視圖引擎,並將模型傳遞給視圖。 使用模型驗證提供程序,檢索驗證規則以創建客戶端驗證腳本以及遠程驗證腳本

更多信息:

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

我很抱歉我的英語

有許多
1.Application_BeginRequest(和AuthenticateRequest)在全局或一些HttpModule中
2.filters
3.mvc框架,控制器工廠,動作調用程序等
4.第一次運行時,將il編譯為本機需要花費很多

我認為您可以使用秒表來檢查您的操作代碼花費的時間
這樣你就可以找出需要花費很多時間的地方

120ms不是運行前花費的時間,我認為是行動完成的時間

順便說一下120ms並不算太糟糕

更新

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

在此輸入圖像描述
這張圖片高於代碼運行結果,所以你可以看到
行動是一個孩子只需1.9
和http:// ......成本302,它包括控制器,動作

所以你應該檢查你的動作代碼或動作代碼之外的大部分時間成本
在圖片中,它花費300+,因為它是第一次運行,第二次運行只需4次
第一輪必須慢

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM