如何在.NET Core Web API中配置并发? [英] How to configure concurrency in .NET Core Web API?

查看:1618
本文介绍了如何在.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应用程序并发性由其

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.

更多信息: Kestrel是否使用单个线程来处理诸如Node.js之类的请求?

新的Limits属性为

您现在可以为以下内容添加限制:

You can now add limits for the following:

  1. 最大客户端连接数
  2. 最大请求正文大小
  3. 最大请求正文数据速率
  1. Maximum Client Connections
  2. Maximum Request Body Size
  3. Maximum Request Body Data Rate

例如:

.UseKestrel(options =>
{
    options.Limits.MaxConcurrentConnections = 100;
}

IIS

当Kestrel在反向代理后面运行时,您可以调整代理本身.例如,您可以在web.configaspnet.config中配置IIS应用程序池:

IIS

When Kestrel runs behind a reverse proxy you could tune the proxy itself. For example, you could configure IIS application pool in web.config or in aspnet.config:

<configuration>
  <system.web>
    <applicationPool
        maxConcurrentRequestsPerCPU="5000"
        maxConcurrentThreadsPerCPU="0"
        requestQueueLimit="5000" />
  </system.web>
</configuration>

当然 Nginx Apache 具有自己的并发设置.

Of course Nginx and Apache have their own concurrency settings.

这篇关于如何在.NET Core Web API中配置并发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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