ASP.NET MVC 3 Razor 性能 [英] ASP.NET MVC 3 Razor performance

查看:28
本文介绍了ASP.NET MVC 3 Razor 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重要更新:请参阅底部的更新 5,asp.net mvc 3 中没有性能问题,这是一个基准问题

我在 asp.net mvc2,3 aspx 和 3 razor 中做了一个简单的 hello world 项目,并对它们进行了基准测试.我看到的是:

I've made a simple hello world project in asp.net mvc2,3 aspx and 3 razor and benchmarked them. What I see is:

System                  Requests per second
-------------------------------------------
asp.net mvc 2 ASPX                     4200
asp.net mvc 3 Beta 1 ASPX              3200
asp.net mvc 3 Beta 1 Razor             1700

剃须刀怎么了,这么慢?

What's wrong with razor, it's so slow?

更新:我重做了测试.所有 4 个测试虚拟目录都使用相同的 .net 4 集成模式应用程序池.所有项目都是通过添加新的空 x 项目并添加 1 页、1 行文本且没有代码来完成的.所有站点都以发布模式编译.我的系统是 windows 7, 4 gb i7 4 cores.我已经运行了 2 次测试来预热 iis,这些是第二次运行的结果.apache 工作台参数:ab -n100000 -c1000结果:

Update: I've redone the test. All 4 test virtual directories uses the same .net 4 integrated mode app pool. All projects are done with add new empty x project and adding 1 page with 1 line text and with no code. all sites are compiled in release mode. My system is windows 7, 4 gb i7 4 cores. I've run the test 2 times to warm up iis and these are second run results. apache bench parameters : ab -n100000 -c1000 results:

System         Requests per second   CPU Utilization
----------------------------------------------------
asp.net 4                     4780               43%
mcv 2                         4322               58%
mvc 3 beta 1 aspx             2324               54%
mvc 3 beta 1 razor            1615               54%

更新 2 Scott Guthrie 在他的博客中回答:

Update 2 Scott Guthrie answered in his blog:

我们还没有完全优化 MVC3(我们通常会进行很多缓存调整).我们希望 razor 在最终发布之前具有与 .aspx 视图引擎相同的性能.

System         Requests per second   CPU Utilization
----------------------------------------------------
mvc 3 rc1 razor               1960               54%
mvc 3 rc2 razor               2187               54%
mvc 3 rc2 aspx                4014               58%

更新 5 在发布模式下完成的所有测试,但是,问题出在我的 web.config 文件中的 debug="true"(也会影响发布版本),之后将其更改为 false,问题已解决.有趣的是,它如何以这种规模只影响剃刀模板.我们在部署时应该考虑到这一点.

Update 5 all tests done in release mode but, the problem was debug="true" in my web.config file (that also effects release builds), after change it to false, issue fixed. And it's interesting how it's effecting only razor templating at this scale. This should be in our mind on deployments.

System         Requests per second   CPU Utilization
----------------------------------------------------
mvc 3 rc2 razor               3940               58%
mvc 3 rc2 aspx                4100               58%

感谢 asp.net mvc 团队,干得好!

Thanks to asp.net mvc team, excellent job!

推荐答案

(响应您的 RC2 编号的新答案)

(new answer to respond to your RC2 numbers)

感谢更新的数字.几点:

Thanks for the updated numbers. A few points:

  1. 您的 Aspx 数字看起来不错,因为我们希望 MVC3 Aspx 与 MVC2 Aspx 相当(在这样的 Hello World 示例中预计会慢一点)
  2. 你的 Razor 数字看起来很可疑.我们知道 Razor 比等效的 Aspx 慢一点,但是,差异应该不大于 5%-7%.你的数字表明慢了 50%,这与我们的结果不符.检查项目是否在 Release 中编译,并且您在 web.config 中设置了 debug="false".
  3. 您的 CPU 利用率有点可疑.对于 1000 个并发请求,CPU 应该被 100% 使用.(即使只有 8 个并发请求也应该足够了,因为您有 8 个虚拟内核)
  4. 您的测试运行了大约 20-25 秒.这有点偏低,因为系统中其他地方的短暂(1-2 秒)突发活动可能会显着影响您的结果.
  5. 关于第 4 点,您是将每个场景运行一次还是几次?您是否看到结果有很大差异?由于您的操作系统在后台执行其他操作,因此在运行之间通常会看到不同的结果.

这篇关于ASP.NET MVC 3 Razor 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆