简体   繁体   English

C#MVC 5.1 Razor 3.0性能问题

[英]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 我在本地开发机器上使用ab.exe(apache bench),使用IIS 8.5的四核i7 / 8gb ram / windows 8.1 pro

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. 首先,我的web.config有debug = false,trace = false,并且正在以发布模式编译应用程序。 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尝试了一些不同的设置,但目前正在使用这些设置:

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: 15007上的站点是在同一本地计算机上的实时构建模式下的当前实时站点,并且具有所有相同应用程序池设置的相同IIS(默认)15008站点仅具有简单的基本级别代码:

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 〜\\查看\\页\\ 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 〜\\查看\\测试\\ 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: 但是现在我已经禁用了aspx测试并且只包括剃须刀:

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时的比较差异以及其中带有字母“a”的静态txt文件:

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. ASPX代码(如上所述,与剃刀相同但没有删除aspx渲染引擎的代码)似乎比同一项目中的静态文件查找更快。 Which would make some sense as there is less IO overhead to check/stream the file. 这有点意义,因为检查/流传输文件的IO开销较少。

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) 我正在测试的当前实时站点是MVC4 / Razor2,新的也是MVC5 / Razor3,所以虽然我期望有所不同,甚至可能会稍微慢一点,我不会期望一个没有处理的基页击败数据库驱动(db结果缓存,无输出缓存)配方查找和格式化页面,包含大量代码/检查/渲染snipets(太大而无法粘贴)

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. 在我将测试项目更改为MVC5 / Razor3之前,我使用与上面完全相同的代码对MVC4 / Razor2进行了测试,结果大约为2k / sec,因此略高于当前实时站点上的配方页面 - 我也期待。

So i ask what could cause razor to get such poor performance compared to aspx on my system/config/project? 所以我想问一下,与我的系统/配置/项目上的aspx相比,什么可能导致剃刀获得如此糟糕的性能? Anything i have missed or i could check? 我错过了什么,或者我可以检查? Something i have overlooked? 我忽略了什么?

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! 似乎在Views web.config中存在一些配置问题! It was still pointing to v2 instead of v3. 它仍然指向v2而不是v3。 I gather NuGet wasn't very effective in its update. 我认为NuGet的更新效果不是很好。 The page wasn't erroring however. 但该页面没有错误。 Perhaps it was view chaining between 2 and 3? 也许它是2到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: 将视图web.config版本号更新到3.0.0后,我得到了我原先的预期:

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

:D :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: 编辑:以防其有用的ID喜欢添加我已经将当前的实时网站从MVC4 / Razor2更改为MVC5 / Razor3并且RPS的变化是巨大的:

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. 请注意,我写的任何代码都没有变化 - 我不确定在新的mvc中是否只有很多性能调整,或者删除/添加只是修复了我的项目中的某些内容但认为是id共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM