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


当前回答

我做了上面所有的答案,但还是没有解决我的问题。

最后,我解决了我的网站加载缓慢的问题,在发布配置文件PrecompileBeforePublish设置为真。如果你想使用msbuild,你可以使用这个参数:

 /p:PrecompileBeforePublish=true

这真的很有帮助。现在我的MVC ASP。NET加载速度快10倍。

其他回答

使用捆绑和缩小还可以帮助您提高性能。它基本上减少了页面加载时间。

Gzip实现。 对部分视图使用异步呈现。 最小化数据库命中次数。 使用编译后的查询。 运行分析器找出不必要的匹配。优化所有返回响应时间超过1秒的存储过程。 使用缓存。 使用捆绑最小化优化。 对只读内容使用会话缓存和本地存储等HTML 5实用程序。

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

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

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

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

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

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

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