Using Miniprofiler to track the performance consumption of MVC + EF + Bootstrap 2 Rights Management System

Source: Internet
Author: User

Installing Miniprofiler

In the MVC + EF + Bootstrap 2 Rights Management System entry level (with source) article downloaded its source code, debugging mode to open a page is more than 2.5 seconds, so use Miniprofiler, Miniprofiler.mvc4, The Miniprofiler.ef6 component is analyzed.

First, install the components sequentially. Then, modify the Global.aspx.cs file:

 protected voidApplication_Start () {arearegistration.registerallareas ();            Webapiconfig.register (globalconfiguration.configuration);            Filterconfig.registerglobalfilters (globalfilters.filters);            Routeconfig.registerroutes (routetable.routes);            Bundleconfig.registerbundles (Bundletable.bundles); //Custom ViewViewEngines.Engines.Clear (); Extendedrazorviewengine engine=NewExtendedrazorviewengine (); Engine. Addpartialviewlocationformat ("~/areas/common/views/shared/{0}.cshtml"); Engine. Addpartialviewlocationformat ("~/areas/common/views/shared/{0}.vbhtml");            VIEWENGINES.ENGINES.ADD (engine); //model remove space before and afterModelBinders.Binders.DefaultBinder =NewTrimmodelbinder (); //To set up a MEF Dependency injection containerMEFCONFIG.REGISTERMEF (); //performance monitoring for initializing EF6miniprofileref6.initialize (); //Initialize DBdatabaseinitializer.initialize (); }        protected voidApplication_BeginRequest () {StackExchange.Profiling.MiniProfiler.Start (); }        protected voidapplication_endrequest () {StackExchange.Profiling.MiniProfiler.Stop (); }

Miniprofileref6.initialize (); Must be placed in the databaseinitializer.initialize (); Before, the following error will be reported:

An exception of type ' System.InvalidOperationException ' occurred in EntityFramework.dll is not handled in user code. Additional information:the Entity Framework was already using a dbconfiguration instance before an attempt is made to ad D an ' Loaded ' event handler. ' Loaded ' event handlers can only added as part of application start up before the Entity Framework is used. "

You may also encounter this error when you run the site:

An exception of the type ' System.Data.SqlClient.SqlException ' occurred in MiniProfiler.dll and is not handled in user code

Additional information:invalid column name ' CreatedOn '.

The workaround is to:

1. Disable this type of exception breakpoint (undesirable)

2. Delete the miniprofiler.pdb file under PACKAGES\MINIPROFILER.3.2.0.157\LIB\NET40 (I did it)

3. Disable database change tracking for EF (not validated, should work)

 for  for replies. Database.setinitializer<MyContext<Label>> (null in EF.

Run Site open landing page

SQL takes up 47.7%, and it opens to see which SQL statements are executed.

Analyze page time-consuming

First of all, running debug and release code in debugging mode is almost a long time, as follows:

Then, the non-debug mode (CTRL+F5) runs as follows:

Non-debug mode (CTRL+F5) efficiency is very good, did not expect and debug mode (F5) difference will be so large. Search with Bing to find a post: Visual C + +: difference between Start with/without debugging in Release mode

The explanation inside is

The problem is this Windows drops in a special Debug Heap, if it detects this your program is running under a Debugger. This appears to happen at the OS level, and are independent of any debug/release mode settings for your compilation.

You can work around this ' feature ' by setting an environment variable: _no_debug_heap=1

This same issue have been driving me nuts for a while; Today I found the following, from whence this post is derived:http://blogs.msdn.com/b/larryosterman/archive/2008/09/03/a Natomy-of-a-heisenbug.aspx

In addition, the time-consuming of tracking a method in a more granular way can be written in code:

     PublicAdminlayoutattribute () {//todo:test//var userrole = new List<userrole> {new Userrole {Id = 1, UserId = 1, Roleid = 1}}; //var user = new User {Id = 1, LoginName = "admin", loginpwd = "8wdjlk8moki=", userrole = userrole}; //sessionhelper.setsession ("CurrentUser", user);            varuser = Sessionhelper.getsession ("CurrentUser") asUser; if(User! =NULL)            {                              //using (StackExchange.Profiling.MiniProfiler.StepStatic ("Adminlayout"))               using (MiniProfiler.Current.Step ("Adminlayout"))                {                    //Enqueue a job                    varcontainer = system.web.httpcontext.current.application["Container"] asCompositioncontainer; UserService= Container. Getexportedvalueordefault<iuserservice>(); RoleService= Container. Getexportedvalueordefault<iroleservice>(); Rolemodulepermissionservice= Container. Getexportedvalueordefault<irolemodulepermissionservice>(); ModuleService= Container. Getexportedvalueordefault<imoduleservice>(); Modulepermissionservice= Container. Getexportedvalueordefault<imodulepermissionservice>(); Permissionservice= Container. Getexportedvalueordefault<ipermissionservice>(); }            }        }

Once again access to the module management can see Adminlayout time , as if time-consuming special hours here is not recorded

In summary, there is a component that can actually quantify the time-consuming process of execution. Perform analysis of the number of method calls more powerful tools or dottrace,

Reference Links:

Miniprofiler (Miniprofiler.ef6 monitor Debug MVC5 and EF6 performance)

FIX: Miniprofiler.ef occurrence System.InvalidOperationException "Type of exception occurs in EntityFramework.dll

Entity Framework 4.3. Invalid column name ' CreatedOn '

Miniprofiler breaks on missing createdon column

Using Miniprofiler to track the performance consumption of MVC + EF + Bootstrap 2 Rights Management System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.