安装MiniProfiler

MVC + EF + Bootstrap 2 权限管理系统入门级(附源码)文章中下载了它的源码,调试模式下打开一个页面都要再2.5秒以上,所以使用MiniProfiler、MiniProfiler.MVC4 、MiniProfiler.EF6组件进行了分析。

首先,依次序安装组件。然后,修改Global.aspx.cs 文件:

 protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles); //自定义View
ViewEngines.Engines.Clear();
ExtendedRazorViewEngine engine = new ExtendedRazorViewEngine();
engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.cshtml");
engine.AddPartialViewLocationFormat("~/Areas/Common/Views/Shared/{0}.vbhtml");
ViewEngines.Engines.Add(engine); //Model去除前后空格
ModelBinders.Binders.DefaultBinder = new TrimModelBinder(); //设置MEF依赖注入容器
MefConfig.RegisterMef(); //初始化EF6的性能监控
MiniProfilerEF6.Initialize(); //初始化DB
DatabaseInitializer.Initialize();
} protected void Application_BeginRequest()
{
StackExchange.Profiling.MiniProfiler.Start();
}
protected void Application_EndRequest()
{
StackExchange.Profiling.MiniProfiler.Stop();
}

MiniProfilerEF6.Initialize(); 一定要放在 DatabaseInitializer.Initialize(); 之前,否则会报如下错误:

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

运行站点有可能还会遇到这个错误:

An exception of type 'System.Data.SqlClient.SqlException' occurred in MiniProfiler.dll but was not handled in user code

Additional information: Invalid column name 'CreatedOn'.

解决方法是:

1.禁用这种类型的异常断点(不可取)

2.删除packages\MiniProfiler.3.2.0.157\lib\net40 下的MiniProfiler.PDB文件(我是这么做的)

3.禁用EF的数据库变化跟踪(未验证,应该管用)

Found an answer for my question. Thanks all for replies.

Database.SetInitializer<MyContext<Label>>(null);
This fixes the problem and disables DB changes tracking in EF.

运行站点打开登陆页

Sql占了47.7%,点开可以查看执行了哪些sql语句。

分析页面耗时

首先,调试模式下运行Debug和Release代码,耗时差不多都很长,截图如下:

    

   

然后,非调试模式(Ctrl+F5)运行,截图如下:

非调试模式(Ctrl+F5)的效率还是挺不错的,没想到和调试模式(F5)差别会这么大。使用必应搜了一下找到一个帖子 :Visual C++: Difference between Start with/without debugging in Release mode

里面的解释是

The problem is that Windows drops in a special Debug Heap, if it detects that your program is running under a Debugger. This appears to happen at the OS level, and is 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 has 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/anatomy-of-a-heisenbug.aspx

另外为了更细化的跟踪某个方法的耗时可以在代码中这么写:

    public AdminLayoutAttribute()
{
//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);
var user = SessionHelper.GetSession("CurrentUser") as User;
if (user != null)
{ // using (StackExchange.Profiling.MiniProfiler.StepStatic("AdminLayout"))
using (MiniProfiler.Current.Step("AdminLayout"))
{
// Enqueue a job
var container = System.Web.HttpContext.Current.Application["Container"] as CompositionContainer;
UserService = container.GetExportedValueOrDefault<IUserService>();
RoleService = container.GetExportedValueOrDefault<IRoleService>();
RoleModulePermissionService = container.GetExportedValueOrDefault<IRoleModulePermissionService>();
ModuleService = container.GetExportedValueOrDefault<IModuleService>();
ModulePermissionService = container.GetExportedValueOrDefault<IModulePermissionService>();
PermissionService = container.GetExportedValueOrDefault<IPermissionService>();
}
}
}

再次访问模块管理时就可以看到AdminLayout的耗时了,好像耗时特别小时这里就不记录

总之有这么一个组件确实可以量化执行过程的耗时。对方法调用次数执行分析更强大的工具还是DotTrace,如图:

参考链接:

MiniProfiler(MiniProfiler.EF6监控调试MVC5和EF6的性能)

解决:MiniProfiler.EF出现System.InvalidOperationException”类型的异常在 EntityFramework.dll 中发生

Entity Framework 4.3. Invalid column name 'CreatedOn'

Miniprofiler breaks on missing CreatedOn column

使用MiniProfiler跟踪MVC + EF + Bootstrap 2 权限管理系统的性能消耗的更多相关文章

  1. MVC + EF + Bootstrap 2 权限管理系统入门级(附源码)

    MVC .EF 学习有大半年了,用的还不是很熟练,正好以做这样一个简单的权限管理系统作为学习的切入点,还是非常合适的. 开发环境: VS 2013 + Git + MVC 5 + EF 6 Code ...

  2. SQLSERVER 数据库性能的的基本 MVC + EF + Bootstrap 2 权限管理

    SQLSERVER 数据库性能的基本 很久没有写文章了,在系统正式上线之前,DBA一般都要测试一下服务器的性能 比如你有很多的服务器,有些做web服务器,有些做缓存服务器,有些做文件服务器,有些做数据 ...

  3. ABP+AdminLTE+Bootstrap Table权限管理系统第五节--WBEAPI及SwaggerUI

    一,Web API ABP的动态WebApi实现了直接对服务层的调用(其实病没有跨过ApiController,只是将ApiController公共化,对于这一点的处理类似于MVC,对服务端的 调用没 ...

  4. ABP+AdminLTE+Bootstrap Table权限管理系统第六节--abp控制器扩展及json封装

    一,控制器AbpController 说完了Swagger ui 我们再来说一下abp对控制器的处理和json的封装. 首先我们定义一个控制器,在新增控制器的时候,控制器会自动继承自AbpContro ...

  5. ABP+AdminLTE+Bootstrap Table权限管理系统第九节--AdminLTE模板页搭建

    AdminLTE 官网地址:https://adminlte.io/themes/AdminLTE/index2.html 首先去官网下载包下来,然后引入项目. 然后我们在web层添加区域Admin以 ...

  6. ABP+AdminLTE+Bootstrap Table权限管理系统第八节--ABP错误机制及AbpSession相关

    上一节我们讲到登录逻辑,我做的登录逻辑很简单的,我们来看一下abp module-zero里面的登录代码. #region Login / Logout public ActionResult Log ...

  7. ABP+AdminLTE+Bootstrap Table权限管理系统第七节--登录逻辑及abp封装的Javascript函数库

    经过前几节,我们已经解决数据库,模型,DTO,控制器和注入等问题.那么再来看一下登录逻辑.这里算是前面几节的一个初次试水. 首先我们数据库已经有的相应的数据. 模型和DTO已经建好,所以我们直接在服务 ...

  8. ABP+AdminLTE+Bootstrap Table权限管理系统第九节--AdminLTE引入及模板页和布局和菜单

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期 AdminLTE AdminLTE 官网地址:https://adminlte.io/themes/AdminLT ...

  9. ABP+AdminLTE+Bootstrap Table权限管理系统第七节--登录逻辑及几种abp封装的Javascript函数库

    返回总目录:ABP+AdminLTE+Bootstrap Table权限管理系统一期         简介 经过前几节,我们已经解决数据库,模型,DTO,控制器和注入等问题.那么再来看一下登录逻辑.这 ...

随机推荐

  1. iphone按home键后,正在运行的程序是否退出了呢?

    是否一直有个疑问,当iphone手机正在运行一个APP,如果按Home键后,那么原来正在运行的程序还在运行吗?如果开发过ios程序,可能不是问题,如果没有开发过的,可能会疑惑了,我就简单的说一下.以几 ...

  2. 《30天自制操作系统》笔记(03)——使用Vmware

    <30天自制操作系统>笔记(03)——使用Vmware 进度回顾 在上一篇,实现了用IPL加载OS程序到内存,然后JMP到OS程序这一功能:并且总结出下一步的OS开发结构.但是遇到了真机测 ...

  3. 学习Scala第一篇-从hello World开始

    最近开始系统性的学习scala.其实之前使用过scala的,比如我在用Gatling这款性能测试工具的时候就接触到了scala了.Gatling本身就是用Scala写的,而且Gatling的性能测试配 ...

  4. 【重要更新】Senparc.Weixin.Open v1.5.1

    本次更新调整了命名空间和文件位置,具体变化为(可以直接在源代码中替换): 旧命名空间(对应文件夹) 新命名空间(对应文件夹) Senparc.Weixin.Open.OAuth Senparc.Wei ...

  5. CSS水平垂直居中的几种方法

    直接进入主题! 一.脱离文档流元素的居中 方法一:margin:auto法 CSS代码: div{ width: 400px; height: 400px; position: relative; b ...

  6. Js~动态判断PC和手机浏览器

    这个只是一个小知识,也是在网上找的,挺好用! 动态判断浏览器是PC还是移动端! <script> var browser={ versions:function(){ var u = na ...

  7. MySQL的Grant命令[转]

    本文实例,运行于 MySQL 5.0 及以上版本. MySQL 赋予用户权限命令的简单格式可概括为: grant 权限 on 数据库对象 to 用户 一.grant 普通数据用户,查询.插入.更新.删 ...

  8. [Java集合] 彻底搞懂HashMap,HashTable,ConcurrentHashMap之关联.

    注: 今天看到的一篇讲hashMap,hashTable,concurrentHashMap很透彻的一篇文章, 感谢原作者的分享. 原文地址: http://blog.csdn.net/zhanger ...

  9. Atitit 词法分析器的设计最佳实践说明attilax总结

    Atitit 词法分析器的设计最佳实践说明attilax总结 1.1. 手写的优点:代码可读,对源代码中的各种错误给出友好的提示信息,用户体验高,1 1.2. 使用状态表比较简单,dfa比较麻烦1 1 ...

  10. c#设计模式-命令模式

    一. 命令(Command)模式 命令(Command)模式属于对象的行为模式[GOF95].命令模式又称为行动(Action)模式或交易(Transaction)模式.命令模式把一个请求或者操作封装 ...