AspNetCore (Kestrel) 请求超时

AspNetCore (Kestrel) request timed out

我有以下设置:在应用程序负载均衡器 (AWS) 后面的几个 linux 容器(基于 aspnetcore 2.0.5)中的网络 api 运行

正在使用 HttpClient 向此 api 发出请求的客户端。客户端是 运行 并行调用多个任务。如果并行任务的数量增加,api 开始抛出异常并显示消息 "Request timed out."

调用堆栈为:

at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.PipeCompletion.ThrowFailed() at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.GetResult(ReadResult& result) at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.Pipe.Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.IReadableBufferAwaiter.GetResult() at Microsoft.AspNetCore.Server.Kestrel.Internal.System.IO.Pipelines.ReadableBufferAwaitable.GetResult() at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.d__24.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Frame`1.d__2.MoveNext()

什么会导致此错误,谁在设置超时,我该如何进一步调查?

编辑:如果我尝试用 fiddler 捕获失败的请求,则不会再抛出错误(也许 fiddler 正在以较低的并行度打开连接)。

一个可能的原因是 I/O 绑定操作,您阻塞了 asp.net 个线程。从问题描述来看,您的服务器似乎正在处理特定点的请求。除此之外,它无法做到这一点。

我认为如果您正确使用 Async/Await,那么您可以处理比当前限制更多的并发请求数。

还要检查一下,通过配置是否可以增加 Asp.Net 个线程。传统的 Asp.Net 支持这一点。不确定 Asp.Net Core 是否有此功能。

最后,由于您 运行 在云中,请检查升级服务器配置的可行性。可能升级的配置将帮助您处理更多请求。显然这应该是最后的选择。首先关注使用现有硬件提高应用程序的性能。