Whats [ASP.net]MVC doing BEFORE my controller?
Asked Answered
L

2

6

I've got a bit of a strange performance issue occurring with my MVC Controller, or rather before it?

According to the Mini Profiler output, there is a 120ms overhead before reaching my controller.

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.

Everything after it, I can tune/amend, but before it? and I'm lost..

Thoughts??

enter image description here

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)

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.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 (780005)

Could unity be cause some issues?

Libertinism answered 8/1, 2014 at 17:28 Comment(4)
Does this delay happen with other controllers too or only this one has the delay ?Gremial
It only happens on this particular controller, my other controller that calls the same BL this does (and other surrounding logic) is much faster!Libertinism
I see ... I expected a consistent behavior and was going to point at the server itself, but now I'm at a lossGremial
It's only consistency is that it's always THAT controller method..Libertinism
E
1

You should have a look on the The ASP.NET MVC Pipeline

The ASP.NET MVC Pipeline can be divided into the following parts -

  • App initialisation - n this method, you can add Route objects to the static RouteTable.Routes collection (which is of type RouteCollection).

  • Routing Part – Routing module tries to match the incoming URL with the routing table, and calling the corresponding IRouteHandler.

  • Controller creation – the IControllerFactory creates an instance of the controller based on route parameters and default naming conventions.

  • 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. The Action returns a type ActionResult.

  • View – the IViewEngine instantiates the correct view engine and the model is passed to the view. 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/
Explore answered 9/1, 2014 at 7:56 Comment(1)
Do you think it could be Unity cause some problems?Libertinism
S
0

i am sorry for my english

there are many
1.Application_BeginRequest(and AuthenticateRequest) in global or some HttpModule
2.filters
3.mvc framework,controller factory,action invoker and so on
4.when the first time run,it cost many to compile il to native

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

by the way 120ms is not too bad

update

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

enter image description here
this pic is above code run result so you can see
action is a child only cost 1.9
and http://...... cost 302,it include controller,action

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
1st run must be slow

Shainashaine answered 9/1, 2014 at 7:35 Comment(2)
As the profiler shows, this is happening BEFORE my code, so I can't stopwatch it.Libertinism
Nope - this isn't the first run, and it's not my action code that is the problem, as you can see from my pic, MY code runs just fine at 20ms, the problem is the HTTP.Libertinism

© 2022 - 2024 — McMap. All rights reserved.