zoukankan      html  css  js  c++  java
  • ASP.NET MVC 性能注意事项(转载)

    General

        Make use of a profiler to discover memory leaks and performance problems in your application. personally I suggest dotTrace     Run your site in Release mode, not Debug mode, when in production, and also during performance profiling. Release mode is much faster. Debug mode can hide performance problems in your own code.

    Caching

        Use CompiledQuery.Compile() recursively avoiding recompilation of your query expressions     Cache not-prone-to-change content using OutputCacheAttribute to save unnecessary and action executions     Use cookies for frequently accessed non sensitive information     Utilize ETags and expiration - Write your custom ActionResult methods if necessary     Consider using the RouteName to organize your routes and then use it to generate your links, and try not to use the expression tree based ActionLink method.     Consider implementing a route resolution caching strategy     Put repetitive code inside your PartialViews, avoid render it xxxx times: if you end up calling the same partial 300 times in the same view, probably there is something wrong with that. Explanation And Benchmarks

    Routing

        Use to Url.RouteUrl("User", new { username = "joeuser" }) to specify routes. ASP.NET MVC Perfomance by Rudi Benkovic

        Cache route resolving using this helper UrlHelperCached ASP.NET MVC Perfomance by Rudi Benkovic

    Security

        Use Forms Authentication, Keep your frequently accessed sensitive data in the authentication ticket

    DAL

        When accessing data via LINQ rely on IQueryable     Leverage the Repository pattern     Profile your queries i.e. Uber Profiler     Consider second level cache for your queries and add them an scope and a timeout i.e. NHibernate Second Cache

    Load balancing

        Utilize reverse proxies, to spread the client load across your app instance. (Stack Overflow uses HAProxy (MSDN).

        Use Asynchronous Controllers to implement actions that depend on external resources processing.

    Client side

        Optimize your client side, use a tool like YSlow for suggestions to improve performance     Use AJAX to update components of your UI, avoid a whole page update when possible.     Consider implement a pub-sub architecture -i.e. Comet- for content delivery against reload based in timeouts.     Move charting and graph generation logic to the client side if possible. Graph generation is a expensive activity. Deferring to the client side your server from an unnecessary burden, and allows you to work with graphs locally without make a new request (i.e. Flex charting, jqbargraph, MoreJqueryCharts).     Use CDN's for scripts and media content to improve loading on the client side (i.e. Google CDN)     Minify -Compile- your JavaScript in order to improve your script size     Keep cookie size small, since cookies are sent to the server on every request.

    Global configuration

        If you use Razor, add the following code in your global.asax.cs, by default, Asp.Net MVC renders with an aspx engine and a razor engine. This only uses the RazorViewEngine.

        ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine());

        Add gzip (HTTP compression) and static cache (images, css, ...) in your web.config <system.webServer> <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/> </system.webServer>     Remove unused HTTP Modules     Flush your HTML as soon as it is generated (in your web.config) and disable viewstate if you are not using it <pages buffer="true" enableViewState="false">

  • 相关阅读:
    Notepad++64插件安装方法
    lucene、solr、nutch三者的关系
    更改MySQL数据库的编码为utf8mb4
    对request.getSession(false)的理解(附程序员常疏忽的一个漏洞)
    登录页面的表单验证(登录+密码 )
    MSYS2 环境搭建,并整合Qt
    QAbstractItemView为截断的项显示ToolTip(使用事件过滤)
    TraceTool 跟踪工具的瑞士军刀(C++版使用)
    Indy9的TIdFTPServer封装类
    Delphi 7学习开发控件(继承TGraphicControl只画一条线)
  • 原文地址:https://www.cnblogs.com/jjyjjyjjy/p/3010386.html
Copyright © 2011-2022 走看看