如何提高ASP ?NET MVC应用程序性能?


当前回答

一件非常简单的事情是在访问页面所需的数据时进行异步思考。无论是从web服务、文件、数据库还是其他东西读取,都尽可能使用异步模型。虽然它不一定会帮助任何一个页面更快,但它会帮助您的服务器整体性能更好。

其他回答

这不是一个惊天动地的优化,但我想我要把它扔在那里-使用CDN的jQuery,等等。

引用ScottGu自己的话:微软Ajax CDN使你能够显著提高ASP的性能。NET Web Forms和ASP。asp.net MVC应用程序使用ASP。NET AJAX或jQuery。这项服务是免费的,不需要任何注册,可以用于商业和非商业目的。

我们甚至使用CDN为我们的web部件在Moss使用jQuery。

基本的建议是遵循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

只是想说说我的意见。优化MVC应用程序中URL路由生成的最有效的方法是…根本不产生它们。

我们大多数人或多或少都知道url是如何在我们的应用程序中生成的,所以只要使用静态Url.Content(“~/Blahblah”)而不是Url.Action()或Url.RouteUrl(),就可以胜过所有其他方法近20倍甚至更多。

PS:我已经运行了几千次迭代的基准测试,如果有兴趣的话可以在我的博客上发布结果。

如果您正在运行您的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.

Code Climber和这篇博客文章提供了提高应用程序性能的详细方法。

编译后的查询将提高应用程序的性能,但它与ASP没有任何共同之处。净MVC。它将加速每一个db应用程序,所以它不是真正的MVC。