如何提高ASP ?NET MVC应用程序性能?
当前回答
这似乎是显而易见的,但是在生产环境中以及在性能分析期间以发布模式而不是调试模式运行站点。释放模式要快得多。调试模式可以在您自己的代码中隐藏性能问题。
其他回答
这不是一个惊天动地的优化,但我想我要把它扔在那里-使用CDN的jQuery,等等。
引用ScottGu自己的话:微软Ajax CDN使你能够显著提高ASP的性能。NET Web Forms和ASP。asp.net MVC应用程序使用ASP。NET AJAX或jQuery。这项服务是免费的,不需要任何注册,可以用于商业和非商业目的。
我们甚至使用CDN为我们的web部件在Moss使用jQuery。
Gzip实现。 对部分视图使用异步呈现。 最小化数据库命中次数。 使用编译后的查询。 运行分析器找出不必要的匹配。优化所有返回响应时间超过1秒的存储过程。 使用缓存。 使用捆绑最小化优化。 对只读内容使用会话缓存和本地存储等HTML 5实用程序。
基本的建议是遵循REST原则,以下几点将这些原则中的一些与ASP。NET MVC框架:
Make your controllers stateless - this is more of a 'Web performance / scalability' suggestion (as opposed to micro/machine level performance) and a major design decision that would affect your applications future - especially in case it becomes popular or if you need some fault tolerance for example. Do not use Sessions Do not use tempdata - which uses sessions Do not try to 'cache' everything 'prematurely'. Use Forms Authentication Keep your frequently accessed sensitive data in the authentication ticket Use cookies for frequently accessed non sensitive information Make your resources cachable on the web Utilize ETags Use expiration Write your custom ActionResult classes if necessary Utilize reverse proxies Compile your JavaScript. There is Closure compiler library to do it as well (sure there are others, just search for 'JavaScript compiler' too) Use CDNs (Content Delivery Network) - especially for your large media files and so on. Consider different types of storage for your data, for example, files, key/value stores, etc. - not only SQL Server Last but not least, test your web site for performance
使用最新版本的任务并行库(TPL),根据. net版本。必须根据不同的用途选择正确的TPL模块。
如果您正在运行您的ASP。NET MVC应用程序在Microsoft Azure (IaaS或PaaS)上,然后至少在第一次部署之前执行以下操作。
Scan your code with static code analyzer for any type of code debt, duplication, complexity and for security. Always enable the Application Insight, and monitor the performance, browsers, and analytics frequently to find the real-time issues in the application. Implement Azure Redis Cache for static and less frequent change data like Images, assets, common layouts etc. Always rely on APM (Application Performance Management) tools provided by Azure. See application map frequently to investigate the communication performance between internal parts of the application. Monitor Database/VM performance too. Use Load Balancer (Horizontal Scale) if required and within the budget. If your application has the target audience all over the globe, then use Azure Trafic Manager to automatically handle the incoming request and divert it to the most available application instance. Try to automate the performance monitoring by writing the alerts based on low performance.
推荐文章
- c# .NET中的App.config是什么?如何使用它?
- 如何找到Java堆大小和内存使用(Linux)?
- 在哪里放置AutoMapper.CreateMaps?
- String类中的什么方法只返回前N个字符?
- 如何在HTML5中改变视频的播放速度?
- 我如何提高ASP。NET MVC应用程序性能?
- 无法解析类型为“Microsoft.AspNetCore.Http.IHttpContextAccessor”的服务
- 如何在没有任何错误或警告的情况下找到构建失败的原因
- Visual Studio弹出提示:“操作无法完成”
- 否ConcurrentList<T>在。net 4.0?
- 在c#中解析字符串为日期时间
- 如何在剃刀视图上引用.css文件?
- 由Jon Skeet撰写的《Singleton》澄清
- 自定义数字格式字符串始终显示符号
- 列表推导式和函数式函数比for循环更快吗?