.NET Core 2.1 API Kestrel 压力测试时的问题
Posted
技术标签:
【中文标题】.NET Core 2.1 API Kestrel 压力测试时的问题【英文标题】:.NET Core 2.1 API Kestrel problems when stress testing 【发布时间】:2020-09-23 06:25:18 【问题描述】:我有一个在 .NET Core 2.1 中开发的 API,在进行压力测试时,它报告了一个 Kestrel Web 服务器错误,我不知道它是什么。
错误信息是:由于数据到达太慢,读取请求正文超时。请参阅 MinRequestBodyDataRate。
我离开了我在 Application Insights 日志中看到的调用堆栈。
Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: 在 Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(Microsoft.AspNetCore.Server.Kestrel.Core,版本=2.1.7.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody+d__4.MoveNext (Microsoft.AspNetCore.Server.Kestrel.Core,版本=2.1.7.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.IO.Pipelines.PipeCompletion.ThrowLatchedException(System.IO.Pipelines,版本=4.0.0.1,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51) 在 System.IO.Pipelines.Pipe.GetReadResult(System.IO.Pipelines,版本=4.0.0.1,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51) 在 System.IO.Pipelines.Pipe.GetReadAsyncResult(System.IO.Pipelines,版本=4.0.0.1,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51) 在 System.IO.Pipelines.Pipe+DefaultPipeReader.GetResult(System.IO.Pipelines,版本=4.0.0.1,文化=中性,PublicKeyToken=cc7b13ffcd2ddd51) 在 System.Runtime.CompilerServices.ValueTaskAwaiter
1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody+<ReadAsync>d__21.MoveNext (Microsoft.AspNetCore.Server.Kestrel.Core, Version=2.1.7.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.ValueTaskAwaiter
1.GetResult (System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream+d__22.MoveNext(Microsoft.AspNetCore.Server.Kestrel.Core,版本=2.1.7.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream+<ReadAsync>d__35.MoveNext (Microsoft.AspNetCore.WebUtilities, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult (System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions+d__3.MoveNext(Microsoft.AspNetCore.WebUtilities,版本=2.1.1.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter+d__17.MoveNext (Microsoft.AspNetCore.Mvc.Formatters.Json,版本=2.1.3.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder+<BindModelAsync>d__7.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.1.16.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder+<BindModelAsync>d__11.MoveNext (Microsoft.AspNetCore.Mvc.Core, Version=2.1.16.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter
1.GetResult (System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Internal.ControllerBinderDelegateProvider+c__DisplayClass0_0+d.MoveNext(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+d__13.MoveNext (Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__23.MoveNext(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__18.MoveNext(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+d__16.MoveNext(Microsoft.AspNetCore.Mvc.Core,版本=2.1.16.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Builder.RouterMiddleware+d__4.MoveNext(Microsoft.AspNetCore.Routing,版本=2.1.1.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+d__6.MoveNext(Microsoft.AspNetCore.Authentication,版本=2.1.2.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware+d__7.MoveNext(Microsoft.AspNetCore.StaticFiles,版本=2.1.1.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 quodem_qcore_gamification.api.Startup+c+ d.MoveNext(quodem-qcore-gamification.api,版本=1.0.0.0,文化=中性,PublicKeyToken=null) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware+d__8.MoveNext(Microsoft.AspNetCore.Cors,版本=2.1.1.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware+d__13.MoveNext (Microsoft.AspNetCore.Server.IISIntegration,版本=2.1.7.0,文化=中性,PublicKeyToken=adb9793829ddae60) 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(System.Private.CoreLib,版本=4.0.0.0,文化=中性,PublicKeyToken=7cec85d7bea7798e) 在 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol+d__188`1.MoveNext(Microsoft.AspNetCore.Server.Kestrel.Core,版本=2.1.7.0,文化=中性,PublicKeyToken=adb9793829ddae60)
【问题讨论】:
【参考方案1】:报错信息是:Reading the request body timed out due to data 到达太慢。请参阅 MinRequestBodyDataRate。
建议大家可以看一下KestrelHttpServer
的源码,在启动文件的Configure
方法中添加如下代码:
app.UseKestrel(opt =>
opt.Limits.MinRequestBodyDataRate = null;
)
【讨论】:
以上是关于.NET Core 2.1 API Kestrel 压力测试时的问题的主要内容,如果未能解决你的问题,请参考以下文章
ASP.NET Core Web服务器 Kestrel和Http.sys 特性详解
结合Jexus + Kestrel 部署 asp.net core 生产环境