ThreadPool.SetMinThreads在IIS托管应用程序中不起作用 [英] ThreadPool.SetMinThreads doesn't work in IIS hosted application

查看:87
本文介绍了ThreadPool.SetMinThreads在IIS托管应用程序中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有设计为Web API的ASP.NET 4.6应用程序.它有一个长时间运行的操作,大约需要60秒,但是此操作负载不重,让我们像Thread.Sleep(60000)那样想象一下.
此操作目前不能异步,因为它依赖于第三方非异步库,因此它将阻塞执行此操作的线程60秒钟.当同时有50个以上的请求发送到应用程序时,新的请求正在队列中等待(有时多达400个),问题就变成了问题.我试图增加这样的线程池线程的最小和最大数量:

I have ASP.NET 4.6 application that is designed as Web API. 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).
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. 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). I tried to increase minimum and maximum number of thread pool threads like this:

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

这些值已成功更改,如果我在IIS Express上运行该应用程序,则会应用更改并非常快速地(大约3秒)分配新线程,所有请求都得到处理,每个人都很高兴:

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 10上运行该应用程序,它只会分配40-60个线程,其余请求正在排队:

However if I run the application on IIS 10, it just allocates 40-60 threads and the rest of requests are being queued:

如何在IIS托管的应用程序中正确使用ThreadPool.SetMinThreads? 还有其他方法可以达到相同目的吗?

How can I use ThreadPool.SetMinThreads in IIS hosted applications properly?
Are there any other ways to achieve the same?

推荐答案

根本原因是Windows 10企业版并发请求执行的IIS限制:最多可以同时执行10个请求.实际上,整个过程中我有46个线程,而线程池中只有10个线程.当我尝试在Windows Server 2012上运行应用程序时,我没有遇到任何问题,因此在几秒钟内在线程池中创建了400个线程.

The root cause is in IIS limit of concurrent requests execution for Windows 10 Enterprise: there are maximum 10 requests can be executed simultaneously. Actually I had 46 threads for the entire process and only 10 threads were from the thread pool. 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.

这篇关于ThreadPool.SetMinThreads在IIS托管应用程序中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆