简体   繁体   English

ThreadPool.SetMinThreads在IIS托管应用程序中不起作用

[英]ThreadPool.SetMinThreads doesn't work in IIS hosted application

I have ASP.NET 4.6 application that is designed as Web API. 我有设计为Web API的ASP.NET 4.6应用程序。 It has one long running operation that takes about 60 seconds, but this operation isn't heavily loaded, let's imaging that like Thread.Sleep(60000) . 它有一个长时间运行的操作,大约需要60秒,但是此操作负载不重,让我们像Thread.Sleep(60000)这样想象一下。
This operation cannot be asynchronous at the moment because it depends on third party non-async library, therefore it blocks a thread executing this operation for 60 seconds. 此操作目前无法异步,因为它依赖于第三方非异步库,因此它将阻塞执行此操作的线程60秒。 The problem becomes when more than 50 requests are sent to the application at the same moment, new requests are waiting in a queue (sometimes up to 400). 当同时有50个以上的请求发送到应用程序时,新的请求在队列中等待(有时多达400个),问题就变成了。 I tried to increase minimum and maximum number of thread pool threads like this: 我试图增加最小和最大线程池线程数,如下所示:

ThreadPool.SetMinThreads(300, 300);
ThreadPool.SetMaxThreads(500, 500);

These values are successfully changed, and if I run the application on IIS Express, the changes are applied and new threads are allocated very quickly (about 3 seconds), all requests are processed, everyone is happy: 这些值已成功更改,并且如果我在IIS Express上运行该应用程序,则会应用更改并非常快速地(大约3秒)分配新线程,所有请求都得到处理,每个人都很高兴:

IIS Express上托管的应用程序

However if I run the application on IIS 10, it just allocates 40-60 threads and the rest of requests are being queued: 但是,如果我在IIS 10上运行该应用程序,它将仅分配40-60个线程,其余请求正在排队:

IIS 10上托管的应用程序

How can I use ThreadPool.SetMinThreads in IIS hosted applications properly? 如何在IIS托管的应用程序中正确使用ThreadPool.SetMinThreads
Are there any other ways to achieve the same? 还有其他方法可以达到相同目的吗?

The root cause is in IIS limit of concurrent requests execution for Windows 10 Enterprise: there are maximum 10 requests can be executed simultaneously. 根本原因是Windows 10企业版并发请求执行的IIS限制:最多可以同时执行10个请求。 Actually I had 46 threads for the entire process and only 10 threads were from the thread pool. 实际上,整个过程中我有46个线程,而线程池中只有10个线程。 When I had tried to run my application on Windows Server 2012, I didn't experience any issues, so 400 threads were created in the thread pool during few seconds. 当我尝试在Windows Server 2012上运行应用程序时,我没有遇到任何问题,因此在几秒钟内在线程池中创建了400个线程。

Returned back here to share some advices, but you've already fegured it out :( 回到这里分享一些建议,但是您已经弄明白了:(

I found an article regarding the service performance improvement with async methods for Web API (which, in fact wouldn't be helpful for you), in comments there saw another clue: 我发现了一篇有关使用Web API异步方法提高服务性能的文章(实际上,这对您没有帮助),在评论中看到了另外一条线索:

I suspect that poor results of the synchronous solution are explained by the fact that IIS running on desktop Windows allows only a limited number of concurrent requests . 我怀疑,由于在桌面Windows上运行的IIS仅允许有限数量的并发请求 ,因此可以解释同步解决方案的较差结果。 For example this link suggests 10 requests, which is consistent with your results (req/sec ~= 10/delay). 例如, 此链接建议10个请求,这与您的结果一致(req / sec〜= 10 / delay)。 While it definitely shows the ability of asynchronous solutions to consume less resources, results might be different in a real production environment running Windows Server . 尽管它肯定显示了异步解决方案消耗更少资源的能力,但在运行Windows Server的实际生产环境中结果可能会有所不同 ... ... While numbers suggest that indeed asynchronous version is more performant, the difference is not as devastating as testing on a desktop Windows IIS hints. ……尽管数字表明确实确实异步版本具有更高的性能, 但区别不像在桌面Windows IIS提示上进行测试那样具有破坏性 I hope to return to this topic with more data. 我希望以更多数据返回到该主题。

So the reason is exactly in desktop version of the IIS. 因此,原因恰恰是IIS的桌面版本。

IIS 8 on Windows Server 2012 doesn't have any fixed concurrent request limit, apart from whatever limit would be reached when resources are maxed. Windows Server 2012上的IIS 8没有任何固定的并发请求限制,除了资源最大化时将达到的限制。

However, the client version of IIS 8, which is on Windows 8, does have a concurrent connection request limitation to limit high traffic production uses on a client edition of Windows. 但是,Windows 8上的IIS 8客户端版本确实具有并发连接请求限制,以限制 Windows客户端版本上的高流量生产使用

Seems like in Windows 100 the picture is the same. 好像在Windows 100中,图片是一样的。

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

相关问题 ThreadPool.SetMinThreads()是否可以将completionPortThreads编号设置为0? - ThreadPool.SetMinThreads() can the completionPortThreads number be set to 0? 我应该在什么时间和上下文中调用ThreadPool.SetMinThreads - At which time and in which context should I call ThreadPool.SetMinThreads 使用准则:C#中的ThreadPool.SetMaxThreads和ThreadPool.SetMinThreads - Guidelines while using: ThreadPool.SetMaxThreads and ThreadPool.SetMinThreads in C# ThreadPool SetMinThreads-设置它的影响 - ThreadPool SetMinThreads - the impact of setting it 为什么远程调试不适用于IIS托管的WCF服务? - Why doesn't remote debugging work for WCF service hosted by IIS? ThreadPool SetMaxThreads和SetMinThreads Magic Number - ThreadPool SetMaxThreads and SetMinThreads Magic Number 对于 IIS 中托管的 asp.net 站点,简单的 controller 路由在 IIS 中不起作用 - Simple controller routing doesn't work in IIS for asp.net site hosted in IIS IIS 10.0-一个应用程序文件夹的AllowAnonymous(控制器不起作用) - IIS 10.0 - AllowAnonymous for one application folder (Controller doesn't work) IIS / Asp.NET应用程序中托管时的HttpClient证书不起作用 - HttpClient certificate when hosted in IIS/Asp.NET Application not work 在 IIS 应用程序(asp .net)上使用任务/线程池 - Using tasks/ ThreadPool on IIS application (asp .net)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM