简体   繁体   English

ASP.NET MVC 请求在 RAM 相对较低时挂起

[英]ASP.NET MVC request hangs when RAM is relatively low

I stuck with the following mysterious problem when using ASP.NET MVC and IIS.在使用 ASP.NET MVC 和 IIS 时,我遇到了以下神秘问题。 I have a very simple controller:我有一个非常简单的控制器:

public class SimpleController : Controller
{
    public ActionResult Huge()
    {
        return Content(new string('a', 3000000));
    }

    public ActionResult Small()
    {
        return Content(new string('a', 1000000));
    }
}

If I run this example with IIS Express or more complicated examples with ordinary IIS, than I sometimes facing a problem, that request to the /Huge method handler just hangs: in browser, it looks like infinite page loading, in Wireshark I saw that TCP connection opened but after this, there is no activity from server (I also try to make raw requests with python via requests lib and in this case it also hangs for /Huge method handler).如果我使用 IIS Express 或使用普通 IIS 运行更复杂的示例,那么有时会遇到问题,对/Huge方法处理程序的请求只是挂起:在浏览器中,它看起来像是无限加载页面,在 Wireshark 中,我看到了 TCP连接打开,但在此之后,没有来自服务器的活动(我也尝试通过requests库使用 python 发出原始请求,在这种情况下,它也为/Huge方法处理程序挂起)。 On the other hand, requests to the /Small method handler works fine.另一方面,对/Small方法处理程序的请求工作正常。

I discovered, that this behavior stably reproduced with a relatively small amount of free RAM.我发现,这种行为可以通过相对少量的可用 RAM 稳定重现。 But it's very strange for me: Process Explorer shows that at least 8GB of RAM is available (problem reproduced when only less than 8GB of free space available, but with more space both of these controllers works fine)但这对我来说很奇怪:Process Explorer 显示至少有 8GB 的​​ RAM 可用(当可用空间少于 8GB 时会重现问题,但如果有更多空间,这两个控制器都可以正常工作)

I also try to reproduce this behavior with ASP NET Core and Kestrel server and with this setup everything works fine and no hangs occurred.我还尝试使用 ASP NET Core 和 Kestrel 服务器重现此行为,并且使用此设置一切正常且未发生挂起。

Can anybody shed the light on this mysterious problem?任何人都可以阐明这个神秘的问题吗? What is the cause of the problem and are there any workarounds for it?问题的原因是什么,是否有任何解决方法?

My configurations are the following:我的配置如下:

  • .NET Framework 4.8 .NET 框架 4.8
  • Windows 10 Pro (version 1909) Windows 10 专业版(版本 1909)
  • RAM: 32 GB (with an enabled swap of the fixed size - 24 GB) RAM:32 GB(启用固定大小的交换 - 24 GB)
  • Server: Microsoft-IIS/10.0服务器:Microsoft-IIS/10.0

I dig a little bit deeper and found errors in HTTP.sys log files ( C:\\Windows\\System32\\LogFiles\\HTTPERR\\httperr1.log ).我深入挖掘了一下,发现 HTTP.sys 日志文件( C:\\Windows\\System32\\LogFiles\\HTTPERR\\httperr1.log )中有错误。 There is an error for request with the following tag: Connection_Abandoned_By_ReqQueue .带有以下标记的请求有错误: Connection_Abandoned_By_ReqQueue This information helps me to find a blog post about a similar problem: https://mvolo.com/low-pagefile-can-cause-503-service-unavailable-on-azure-web-roles/此信息帮助我找到有关类似问题的博客文章: https : //mvolo.com/low-pagefile-can-cause-503-service-unavailable-on-azure-web-roles/

The suggested workaround is to increase swap size.建议的解决方法是增加交换大小。 I do it (increase swap by 64GB to ensure that IIS will be happy with it) - and problem resolved我这样做了(将交换增加 64GB 以确保 IIS 对它感到满意) - 并解决了问题

Anyway, I don't understand what's wrong with IIS and why it can't use available memory in my initial setup (Kestrel in ASP NET Core can handle requests and I write a dummy app that simply allocates some memory - 5-8GB - and it works fine)无论如何,我不明白 IIS 有什么问题以及为什么它不能在我的初始设置中使用可用内存(ASP NET Core 中的 Kestrel 可以处理请求,我编写了一个简单地分配一些内存的虚拟应用程序 - 5-8GB - 和它工作正常)

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

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