performance - 如何解决“Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException:由于数据到达太慢导致读取请求正文超时”?
问题描述
在进行 API 性能测试时 [例如,线程数/用户数:50,循环计数:10],由于以下异常,使用 POST 方法的 5% 到 8% 样本失败:
**Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException: Reading the request body timed out due to data arriving too slowly. See MinRequestBodyDataRate.**
at Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException.Throw(RequestRejectionReason reason)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.PumpAsync()
at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 buffer, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.WebUtilities.StreamHelperExtensions.DrainAsync(Stream stream, ArrayPool`1 bytePool, Nullable`1 limit, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter.ReadRequestBodyAsync(InputFormatterContext context, Encoding encoding)
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.BindModelAsync(ModelBindingContext bindingContext)
at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value)
你能建议我如何解决这个问题吗?
注意:我在 POST 方法中正确实现了 async/await。这仅发生在 POST 方法中,在 500 个样本中,每个 POST 方法只有 20 到 40 个样本失败。在测试时提供相同的输入。
解决方案
您可以将KestrelServerLimits.MinRequestBodyDataRate
属性设置为 null,Program.cs
如下所示:
.UseKestrel(opt =>
{
opt.Limits.MinRequestBodyDataRate = null;
});
参考:
推荐阅读
- php - 使用 PHP 从数据库中填充 Bootstrap 下拉菜单
- c# - 在项目自己的控制台上使用 SetParent,在 winforms 面板中
- java - 我不明白这个错误。(android构建错误科尔多瓦)
- python - 如何在不每次都重新运行函数的情况下重用 Python 类中的返回值?
- text - 滚动时内容淡出
- javascript - 如何停止javascript增量?
- python - statsmodels:如何将方法添加到 MLE 结果类
- html - 如何使用 rvest 收集此表中的所有 url?
- c# - 保存/加载玩家位置和相关场景
- c++ - 获取二维数组动态分配的奇怪输出。我该如何解决这个问题?