等待网络会导致客户端超时吗?

Mot*_*Azu 9 c# parallel-processing async-await

我有一个服务器正在执行Azure队列指示的工作.它几乎总是在非常高的CPU上并行执行多个任务,并且一些任务使用Parallel.ForEach.在运行任务期间,我通过CloudQueue.AddMessageAsync使用await 调用将分析事件写入另一个Azure队列.

我注意到成千上万的这些分析文章因以下错误而失败:

WebException: The remote server returned an error: (500) Internal Server Error.

我检查了Azure的存储事件日志,我有一堆很好的PutMessage命令,端到端占用80.000ms,但它们只需要1ms用于Azure本身.我得到的HTTP状态代码是500,Azure描述了客户端超时的原因.

我认为正在发生的是我的代码调用AddMessageAsync并从那时起我的线程被释放,网络驱动程序正在发送请求并等待响应.获得响应时,网络驱动程序需要一个线程来获取响应,并且计划执行该任务并调用我的继续.由于我的服务器经常处于高负载状态,因此任务需要很长时间才能获得一个线程,然后Azure服务器会确定这是一个客户端超时.

调用azure的代码:

await cloudQueue.AddMessageAsync(new CloudQueueMessage(aMessageContent));
Run Code Online (Sandbox Code Playgroud)

例外:

StorageException: The remote server returned an error: (500) Internal Server Error.
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result):11
Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions+<>c__DisplayClass4.<CreateCallbackVoid>b__3(IAsyncResult ar):45
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task):82
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):41
AzureCommon.Data.AsyncQueueDataContext+<AddMessage>d__d.MoveNext() in c:\BuildAgent\work\14078ab89161833\Azure\AzureCommon\Data\Async\AsyncQueueDataContext.cs:60
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task):82
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task):41
AzureCommon.Storage.AzureEvent+<DispatchAsync>d__1.MoveNext() in c:\BuildAgent\work\14078ab89161833\Azure\AzureCommon\Events\AzureEvent.cs:354

WebException: The remote server returned an error: (500) Internal Server Error.
System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult):41
Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult getResponseResult):44
Run Code Online (Sandbox Code Playgroud)

我说的为什么会这样吗?如果是这样,那么使用单线程同步上下文对我来说会更好吗?

Azure存储日志中的一行.您可以在此处找到有关每个属性含义的详细信息.

<request-start-time>            <operation-type>     <request-status>     <http-status-code>    <end-to-end-latency-in-ms>      <server-latency-in-ms>
2014-07-29T14:55:20.0794198Z    PutMessage           ClientTimeoutError   500                   86929                           1
Run Code Online (Sandbox Code Playgroud)

谢谢.

小智 0

错误 500 意味着服务器收到了错误的请求或者由于各种其他原因而崩溃。我不认为这与线程的高负载有关。请考虑采取以下行动:

  • 检查您正在使用的队列的名称。名称必须小写,以字符开头。这是一个常见问题,会导致错误 500,但服务器不会显示任何错误消息。
  • 设置 Azure 存储 SDK 客户端的重试策略,最好使用指数重试策略。
  • 确保使用最新的 Azure 存储 SDK,因为底层协议最近已更改为更高效的协议。