Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 异步模型绑定asp.net核心?_Asp.net Core_.net Core_Json.net_Model Binding - Fatal编程技术网

Asp.net core 异步模型绑定asp.net核心?

Asp.net core 异步模型绑定asp.net核心?,asp.net-core,.net-core,json.net,model-binding,Asp.net Core,.net Core,Json.net,Model Binding,我正在开发一个“突发性”的Asp.NETCore2.2站点,在这个站点中,我们有很长一段时间的可预测负载,但偶尔会出现流量爆发。在这些突发事件发生后,其中一台服务器将出现痉挛,并继续以尽可能快的速度向线程池中添加线程(大约每秒1个),直到达到最大约32k线程(我们通常使用大约40个工作线程运行,因此32k似乎过多),然后变得无响应 据我所知,问题在于,在我们大部分异步的代码库中,我们会执行一些线程阻塞,我猜如果所有线程同时阻塞,我们就会进入一个糟糕的状态,新线程添加缓慢,并开始处理新流量(不断涌

我正在开发一个“突发性”的Asp.NETCore2.2站点,在这个站点中,我们有很长一段时间的可预测负载,但偶尔会出现流量爆发。在这些突发事件发生后,其中一台服务器将出现痉挛,并继续以尽可能快的速度向线程池中添加线程(大约每秒1个),直到达到最大约32k线程(我们通常使用大约40个工作线程运行,因此32k似乎过多),然后变得无响应

据我所知,问题在于,在我们大部分异步的代码库中,我们会执行一些线程阻塞,我猜如果所有线程同时阻塞,我们就会进入一个糟糕的状态,新线程添加缓慢,并开始处理新流量(不断涌入)由于新线程仅以每秒1个左右的速度缓慢流入,我们从未获得临界数量的空闲线程,因此它们可以释放任何数量不断增加的阻塞线程,而不是在阻塞线程自身被阻塞之前帮助它们

现在我已经尝试了我的darndest跟踪代码中的所有位置,我们做同步的东西,并用async替换它,我使用了Ben Adams阻塞检测器,我尝试了在线程池中只运行一个工作线程来查看站点挂起的位置,我已经将Kestrel设置为不允许对请求/响应执行同步操作,我相信我已经消除了我自己代码中的所有罪魁祸首,但对于使用JSON主体的asp.net核心模型绑定的api操作,我们会得到InvalidOperationException:

“不允许同步操作。请调用ReadAsync或set 将同步IO改为true。“

使用stacktrace:

at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at Microsoft.AspNetCore.WebUtilities.HttpRequestStreamReader.ReadIntoBuffer()
at Microsoft.AspNetCore.WebUtilities.HttpRequestStreamReader.Read(Char[] buffer, Int32 index, Int32 count)
at Newtonsoft.Json.JsonTextReader.ReadData(Boolean append, Int32 charsRequired)
at Newtonsoft.Json.JsonTextReader.ParseValue()
at Newtonsoft.Json.JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)--- End of stack trace from previous location where exception was thrown ---
...
at Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter.<ReadRequestBodyAsync>d__17.MoveNext()--- End of stack trace from previous location where exception was thrown ---
...
at Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.<BindModelAsync>d__7.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
位于Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.Read(字节[]缓冲区,Int32偏移量,Int32计数)
位于Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.Read(字节[]缓冲区,Int32偏移量,Int32计数)
在Microsoft.AspNetCore.WebUtilities.HttpRequestStreamReader.ReadIntoBuffer()上
位于Microsoft.AspNetCore.WebUtilities.HttpRequestStreamReader.Read(Char[]缓冲区,Int32索引,Int32计数)
位于Newtonsoft.Json.JsonTextReader.ReadData(布尔追加,需要Int32字符)
位于Newtonsoft.Json.JsonTextReader.ParseValue()处
位于Newtonsoft.Json.JsonReader.ReadForType(JsonContract契约,布尔hasConverter)
在Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader读取器,类型objectType,Boolean checkAdditionalContent)——引发异常的前一个位置的堆栈结束跟踪---
...
位于Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter.d_u17.MoveNext()---引发异常的上一个位置的堆栈结束跟踪---
...
在Microsoft.AspNetCore.Mvc.ModelBinding.Binders.BodyModelBinder.d\u 7.MoveNext()\r\n--从引发异常的上一个位置开始的堆栈结束跟踪---\r\n
这可能是问题所在吗?如何获得Asp.NETCore2.2的异步json模型绑定