Important Update: See update 5 at the bottom there is no performance issue in asp.net mvc 3, this is a benchmark issue
重要的更新:见底部的更新5在asp.net mvc 3中没有性能问题,这是一个基准问题
I've made a simple hello world project in asp.net mvc2,3 aspx and 3 razor and benchmarked them. What I see is:
我在asp.net mvc2、3 aspx和3 razor中做了一个简单的hello world项目,并对它们进行了基准测试。我所看到的是:
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?
剃刀怎么了,太慢了?
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:
更新:我重新做了测试。所有4个测试虚拟目录都使用相同的。net 4集成模式应用程序池。所有的项目都是通过添加新的空的x项目和添加一个有一行文本且没有代码的页面来完成的。所有站点都是在发布模式下编译的。我的系统是windows 7, 4 gb i7 4内核。我已经运行了两次测试来预热iis,这些是第二次运行的结果。apache bench参数:ab -n100000 -c1000结果:
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%
Update 2 Scott Guthrie answered in his blog:
更新2 Scott Guthrie在他的博客中回答:
We haven't fully optimized MVC3 yet (there is usually a lot of cache tuning we do). We expect razor to be the same performance as the .aspx view engine before it is finally released.
我们还没有完全优化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%
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.
更新5所有在发布模式下完成的测试,但是在我的web中,问题是debug="true"。配置文件(它也影响发布构建),在将其更改为false后,发出修复。有趣的是,它是如何只影响剃刀在这个比例上的模板。我们在部署时应该考虑到这一点。
System Requests per second CPU Utilization
----------------------------------------------------
mvc 3 rc2 razor 3940 58%
mvc 3 rc2 aspx 4100 58%
Thanks to asp.net mvc team, excellent job!
感谢asp.net mvc团队,出色的工作!
2 个解决方案
#1
25
(new answer to respond to your RC2 numbers)
(回应RC2号码的新答案)
Thanks for the updated numbers. A few points:
谢谢你更新的电话号码。几个点:
- Your Aspx numbers look good, in the sense that we expect MVC3 Aspx to be on par with MVC2 Aspx (a bit slower in such a Hello World example is expected)
- 您的Aspx数据看起来很好,因为我们期望MVC3 Aspx与MVC2 Aspx一样(在Hello World示例中要慢一点)
- Your Razor numbers look suspect. We know Razor is a bit slower than the equivalent Aspx, however, the difference should be no larger than 5%-7%. Your numbers indicate 50% slower, which simply does not match up with our results. Check if the project compiles in Release and you have
debug="false"
set in web.config. - 你的剃刀号码看起来可疑。我们知道Razor比同等的Aspx慢一点,但是差异不应该超过5%-7%。您的数据显示慢了50%,这与我们的结果不相符。检查项目是否在版本中编译,并在web.config中设置debug="false"。
- Your CPU utilization is a bit suspect. With 1000 concurrent requests the CPU should be utlized 100%. (Even only 8 concurrent requests should be enough since you have 8 virtual cores)
- 您的CPU利用率有点可疑。有了1000个并发请求,CPU就应该被utming为100%。(即使只有8个并发请求也足够了,因为您有8个虚拟内核)
- Your tests are running for about 20-25 seconds. That's a bit on the low side because a short (1-2 seconds) burst of activity elsewhere in the system could throw off your results quite significantly.
- 您的测试运行大约20-25秒。这有点低,因为短时间(1-2秒)的系统活动爆发可能会严重影响您的结果。
- Related to point 4, did you run each scenario once or a few times? Are you seeing much variance in the results? Since your OS is doing other things in the background it's typical to see different results between runs.
- 与第4点相关,您是否运行过每个场景一次或几次?你看到结果有很大差异吗?由于您的操作系统在后台执行其他操作,因此通常会在运行之间看到不同的结果。
#2
19
How did you perform the benchmark? Was your site deployed on IIS in mode Release? Did you use the <deployment retail="true" />
section in your machine.config? Also remember that ASP.NET MVC 3 is still under heavy development so you cannot expect it to be fully optimized yet. At least wait until it hits RTM.
您是如何执行基准测试的?您的站点是否部署在模式版本的IIS上?配置中是否使用了
#1
25
(new answer to respond to your RC2 numbers)
(回应RC2号码的新答案)
Thanks for the updated numbers. A few points:
谢谢你更新的电话号码。几个点:
- Your Aspx numbers look good, in the sense that we expect MVC3 Aspx to be on par with MVC2 Aspx (a bit slower in such a Hello World example is expected)
- 您的Aspx数据看起来很好,因为我们期望MVC3 Aspx与MVC2 Aspx一样(在Hello World示例中要慢一点)
- Your Razor numbers look suspect. We know Razor is a bit slower than the equivalent Aspx, however, the difference should be no larger than 5%-7%. Your numbers indicate 50% slower, which simply does not match up with our results. Check if the project compiles in Release and you have
debug="false"
set in web.config. - 你的剃刀号码看起来可疑。我们知道Razor比同等的Aspx慢一点,但是差异不应该超过5%-7%。您的数据显示慢了50%,这与我们的结果不相符。检查项目是否在版本中编译,并在web.config中设置debug="false"。
- Your CPU utilization is a bit suspect. With 1000 concurrent requests the CPU should be utlized 100%. (Even only 8 concurrent requests should be enough since you have 8 virtual cores)
- 您的CPU利用率有点可疑。有了1000个并发请求,CPU就应该被utming为100%。(即使只有8个并发请求也足够了,因为您有8个虚拟内核)
- Your tests are running for about 20-25 seconds. That's a bit on the low side because a short (1-2 seconds) burst of activity elsewhere in the system could throw off your results quite significantly.
- 您的测试运行大约20-25秒。这有点低,因为短时间(1-2秒)的系统活动爆发可能会严重影响您的结果。
- Related to point 4, did you run each scenario once or a few times? Are you seeing much variance in the results? Since your OS is doing other things in the background it's typical to see different results between runs.
- 与第4点相关,您是否运行过每个场景一次或几次?你看到结果有很大差异吗?由于您的操作系统在后台执行其他操作,因此通常会在运行之间看到不同的结果。
#2
19
How did you perform the benchmark? Was your site deployed on IIS in mode Release? Did you use the <deployment retail="true" />
section in your machine.config? Also remember that ASP.NET MVC 3 is still under heavy development so you cannot expect it to be fully optimized yet. At least wait until it hits RTM.
您是如何执行基准测试的?您的站点是否部署在模式版本的IIS上?配置中是否使用了