如何在.NET Core Web API中配置并发? [英] How to configure concurrency in .NET Core Web API?
问题描述
在过去的WCF中,您可以通过MaxConcurrentCalls
设置来控制服务并发性. MaxConcurrentCalls
默认为16个并发呼叫,但是您可以根据需要提高或降低该值.
In the old WCF days, you had control over service concurrency via MaxConcurrentCalls
setting. MaxConcurrentCalls
defaulted to 16 concurrent calls but you could raise or lower that value based upon your needs.
如何在.NET Core Web API中控制服务器端并发?在我们的情况下,我们可能需要限制它,因为太多的并发请求会阻碍服务器的整体性能.
How do you control server side concurrency in .NET Core Web API? We probably need to limit it in our case as too many concurrent requests can impede overall server performance.
推荐答案
ASP.NET Core application concurrency is handled by its web server. For example:
var host = new WebHostBuilder()
.UseKestrel(options => options.ThreadCount = 8)
由于基于Kestrel异步的实现,因此不建议将Kestrel线程计数设置为较大的值,例如1K
.
It is not recommended to set Kestrel thread count to a large value like 1K
due to Kestrel async-based implementation.