• ASP.NET MVC 性能优化总结


    随着项目中各项功能的增加,系统性能越来越糟糕,于是决定对系统做性能优化。现性能优化的相关工作记录下来。
     
    一、如何监测性能问题:
    1. dotTrace: 一款性能测试工具,能够记录程序执行过程中各个方法的调用情况及所花时间等,好像不能记录网站加载情况。
    2. miniProfiler: StackOverflow的一款开源产品,需要在项目中引用做相应的配置,不光能够记录网站的加载情况,还能记录EF的执行情况。适合在开发过程中应用。网址:http://miniprofiler.com/
    3. Chrome的开发工具可监控各项资源的加载情况。
     
    二、优化方法:
    1. 对静态资源添加客户端缓存。
    <staticContent>
          <remove fileExtension=".woff" />
          <!-- In case IIS already has this mime type -->
          <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
          <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
        </staticContent>
     
    2. 添加OutputCache。
    filters.Add(new OutputCacheAttribute
                {
                    NoStore = true,
                    Duration = 10,
                    VaryByParam = "*"
                });
     
    3. 压缩合并JS,CSS:
    利用ScriptBundle,StyleBundle,在BundleConfig文件中注册需要引用的静态资源.
     
    4. 对EF加二级缓存:
    引用DLL包:EFCache.dll
    并在项目中添加如下类,具体步骤参考http://blog.3d-logic.com/2014/03/20/second-level-cache-for-ef-6-1/
    public class Configuration : DbConfiguration
        {
            internal static readonly InMemoryCache Cache = new InMemoryCache();
    
            public Configuration()
            {
                var transactionHandler = new CacheTransactionHandler(Cache);
    
                AddInterceptor(transactionHandler);
    
                Loaded +=
                  (sender, args) => args.ReplaceService<DbProviderServices>(
                    (s, _) => new CachingProviderServices(s, transactionHandler));
            }
    
            public static int GetCountOfCache()
            {
                return Cache.Count;
            }
        }

  • 相关阅读:
    Java 发送http post 请求
    经纬度计算
    js cookie操作
    wdatepicker默认时间为当前时间
    基于ssm的poi反射bean实例
    jbox小型交互表单(ajax)
    点击图片查看大图(纯js)
    查询物理表字段(mysql)
    离线安装 Cloudera ( CDH 5.x )(转载)
    sed命令详解 (转载)
  • 原文地址:https://www.cnblogs.com/cxp9876/p/3803720.html
Copyright © 2020-2023  润新知