Andy
Andy

Reputation: 2762

What is the maximum page rendering speed in MVC.NET, and how to improve it?

I am measuring page rendering speed, firing a StopWatch at OnBeginRequest, and stopping it at OnResultExecuted, thereby measuring the entire page render cycle. I get the following time stamps during rendering:

0 ms - OnBeginRequest
+1.1 ms - OnActionExecuting
+2 ms - OnActionExecuted
+3 ms - OnResultExecuted

the three latter timestamps are of course application-specific, but I am wondering what happens during the 1.1 millisecond between the moment the app receives the request and the action method gets control?

How to reduce this time? What is the maximum rendering speed you ever obtained with MVC.NET (pages per second) and how did you do it?

Upvotes: 1

Views: 681

Answers (2)

Egor Pavlikhin
Egor Pavlikhin

Reputation: 17981

Time taken to render a page is different to number of requests per seconds are not directly correlated values (similar to FPS and time per frame in game development see here). Especially in a multi-threaded environment.

Personally on my machine an empty MVC applications renders the default controller and view in 0.8-1.1 ms. Of course the route collection is almost empty, so that presumably saves a lot of time. There are a few optimizations you can make, you can find them on the net easily, one of the primary ones is: clear your view engines and add just the view engine you are using, that will save a roundtrip to the hard drive on every request.

ViewEngines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngine()));

As for real websites I was able to get a real world MVC application to render more than 2000 requests per second. One thing you might want to try is to put your Temp ASP.Net files and your website folder on a RAM drive, since MVC and IIS do hit the physical assembly file on every request, but realistically the gain is too small to be noticeable or worth anyone's time.

If you look at the source code here page generation time is at 1 ms (this is not entirely true since it's in the middle of the view, but very close nevertheless). That server is running on a RAM drive. You can speed it up a little bit more by moving ASP.Net Temp Files to a RAM drive, but I couldn't get it under 0.8 ms no matter what.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Many things happen: routes are parsed, controller is located and instantiated, action method is called. Make sure that you are running in Release mode:

<compilation debug="false" />

so that your measurement results are more realistic. In reality the time between receiving the request and invoking the controller action is never a bottleneck. It is the time spent inside the controller action that you should focus on reducing. This is where your application might gain a real performance boost. There are different techniques for improving performance and a popular one is to use caching.

According to Gu:

Today’s ASP.NET MVC 3 RC2 build contains many bug fixes and performance optimizations. Our latest performance tests indicate that ASP.NET MVC 3 is now faster than ASP.NET MVC 2, and that existing ASP.NET MVC applications will experience a slight performance increase when updated to run using ASP.NET MVC 3.

Upvotes: 1

Related Questions