所以我有以下简单的代码:
namespace MyApp
{
public class Startup
{
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
app.Run(async context => {
context.Response.StatusCode = 200;
context.Response.ContentLength = 4;
await context.Response.WriteAsync("test");
});
}
}
public static class Program
{
public static void Main(string[] args)
{
var app = WebHost.CreateDefaultBuilder(args)
.UseKestrel(options => {
options.Listen(IPAddress.Loopback, 5000);
options.AllowSynchronousIO = false;
})
.UseStartup<Startup>()
.Build();
app.Run();
}
}
}
我正在通过运行服务器
$ dotnet run
然后我尝试测试它:
$ ab -p test.json -n 20000 -c 100 http://127.0.0.1:5000/
json 文件是一个小{"test": 1}
字符串。
一开始,请求的处理速度与预期的一样快。但是我发出的请求越多,Kestrel 的速度就越慢。在某些时候(通常在处理 16k 个请求之后)它会挂起并且ab
工具超时。
有趣的是,如果我等待几秒钟并ab
再次运行,它的工作原理完全相同。在某个时候(在 3/4 请求之后的某个地方)它会挂起并超时。所以看起来 Kestrel 在某个时候会自动处理“挂起”请求,并再次准备好再次被阻止。
我已将最大打开文件描述符限制增加到 100000,但这根本不影响行为。我也和 Kestrel 一起玩过,options
但结果还是一样。
是什么原因造成的?我该如何解决?
我正在使用 macOS High Sierra 10.13.2 和 dotnet 核心版本 2.1.3。这种行为与 macOS 有关吗?
编辑:我要结束我自己的问题。这实际上是一个 macOS 问题。