Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
94 views
in Technique[技术] by (71.8m points)

c# - ASP.NET MVC 3 Razor performance

Important Update: See update 5 at the bottom there is no performance issue in asp.net mvc 3, this is a benchmark issue

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?

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%

Update 2 Scott Guthrie answered in his blog:

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.

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.

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

(new answer to respond to your RC2 numbers)

Thanks for the updated numbers. A few points:

  1. 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)
  2. 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.
  3. 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)
  4. 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.
  5. 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...