Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# MVC 5.1 Razor 3.0 Performance Issue

I am using ab.exe (apache bench) on a local dev machine, quad core i7/8gb ram/windows 8.1 pro using IIS 8.5

I am getting some really odd performance results and i can't figure out the issue. First of all my web.config has debug=false, trace=false and the application is being compiled in release mode. Release mode has tracing constant disable and debug constant disabled and optimizations enabled. Unsafe code is unticked.

I've tried a few different settings for ab but am currently using these:

ab -c 150 -n 1000 -s 5 http://localhost:15007/partials/recipes/_recipe-930.html
ab -c 150 -n 30000 -s 5 http://localhost:15007/partials/recipes/_recipe-930.html > log-currentsite.txt

ab -c 150 -n 1000 -s 5 http://localhost:15008/razor
ab -c 150 -n 30000 -s 5 http://localhost:15008/razor > log-razor.txt

Yes i went overboard on the warm up - but it doesn't take long :)

The site on 15007 is a current live site in live build mode on the same local computer and same IIS with all the same app pool settings (default) the 15008 site has only simple base level code:

Route config:

routes.MapRoute(name: "Razor", url: "razor", defaults: new { controller = "Page", action = "Index" });
routes.MapRoute(name: "ASPX", url: "aspx", defaults: new { controller = "Test", action = "Index" });

Controllers:

public class PageController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

public class TestController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

~\Views\Page\Index.cshtml

@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
        Testing
    </div>
</body>
</html>

~\Views\Test\Index.aspx

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
</head>
<body>
    <div>
        Testing
    </div>
</body>
</html>

However right now i have disabled the aspx testing and am only including razor:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new RazorViewEngine());   

        AreaRegistration.RegisterAllAreas();

        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
}

Results:

log-currentsite.txt:
Requests per second:    1896.31 [#/sec] (mean)

log-razor.txt
Requests per second:    1163.77 [#/sec] (mean)

And just to show you a comparative difference when i had ASPX enabled in the project and a static txt file with the letter 'a' in it:

ASPX
Requests per second:    8086.47 [#/sec] (mean)

Static File:
Requests per second:    7503.54 [#/sec] (mean)

The ASPX code (as above, same project as the razor but without the code removing the aspx rendering engine) seems to be faster than a static file look up in the same project also. Which would make some sense as there is less IO overhead to check/stream the file.

But the question is why isn't the razor pages performing at least closeish?

The current live site i'm testing against is MVC4/Razor2 and the new one is MVC5/Razor3 as well so while i would expect a difference, maybe even a slightly slower result i would not have expected a base page that does no processing to beat a DB driven (db result cached, no output caching) recipe lookup and formatting page with lots of code/checks/rendering snipets (too large to paste)

Before i changed the test project to MVC5/Razor3 i did test it with MVC4/Razor2 with the exact same code as above and the results came in at around ~2k/sec so slightly higher than the recipe page on the current live site - which i would expect also.

So i ask what could cause razor to get such poor performance compared to aspx on my system/config/project? Anything i have missed or i could check? Something i have overlooked?

like image 907
White Dragon Avatar asked Dec 28 '25 20:12

White Dragon


1 Answers

Aha, asking the question i guess gave my mind time to think perhaps.

It seems that there was some config issues in the Views web.config! It was still pointing to v2 instead of v3. I gather NuGet wasn't very effective in its update. The page wasn't erroring however. Perhaps it was view chaining between 2 and 3? I wouldn't have thought that was possible however.

After updating the views web.config version numbers to 3.0.0 i get what i originally expected:

Razor:
Requests per second:    9696.84 [#/sec] (mean)

:D

EDIT: Just in case its helpful id like to add that i have changed the current live site from MVC4/Razor2 to MVC5/Razor3 and the change in RPS was massive:

From:

log-currentsite.txt:
Requests per second:    1896.31 [#/sec] (mean)

To:

log-currentsite.txt:
Requests per second:    5063.96 [#/sec] (mean)

Note that there was no changes to any of the code i wrote - i'm not sure if there was just a lot of performance tweaking in the new mvc or if removing/adding just fixes up something in my project but thought id share.

like image 174
White Dragon Avatar answered Dec 31 '25 08:12

White Dragon