请求很少的 Azure 队列限制错误(StorageException:服务器正忙)

Azure queue throttling error with few requests (StorageException: The server is busy)

嗨,

我在 Azure 上使用队列存储。 我有 4 个程序,每个程序 1 request/second(GetMessagesAsync 请求)。 所以我做了 4 request/seconds.

但有时,此异常会导致限制错误:

System.AggregateException: One or more errors occurred. (The server is busy.) ---> Microsoft.WindowsAzure.Storage.StorageException: The server is busy.\r\n at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.d__4`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.WindowsAzure.Storage.Queue.CloudQueue.<>c__DisplayClass83_0.<b__0>d.MoveNext()\r\n

考虑到单个队列的 Azure 目标吞吐量高达每秒 2000 条消息,我不知道为什么会出现此错误。

补充信息:

我在其中进行获取的函数:

protected async Task<IEnumerable<CloudQueueMessage>> GetAndDequeueMessagesAsync(int numberOfMessagesToRetrived = 1) {
            try
            {
                IEnumerable<CloudQueueMessage> messages = await GetMessagesAsync(numberOfMessagesToRetrived);
                foreach (CloudQueueMessage queueMessage in messages)
                {
                    await DequeueMessageAsync(queueMessage);
                }
                return messages;
            }
            catch (Exception e)
            {                
                return new List<CloudQueueMessage>();
            }            
        }

谢谢

根据您的描述,我猜测是存储服务移动分区以改善负载平衡的原因。

据我所知,Azure 存储分区服务器不会只托管一个分区(queue\table 分区键),它会托管多个分区。

如果分区服务器收到太多请求,Azure存储会自动提高负载均衡。

它将把一些分区移动到另一个分区服务器。如果您在移动分区时发送请求,它将 return 503 错误。

有关 Azure 存储如何改进负载平衡的更多详细信息。你可以参考这个azure storage SOSP article's 5.5.1 Load Balance Operation Details .

我建议您可以使用存储客户端库实施重试策略,以确保您的程序正常运行。

更多详情,您可以参考以下文章: Microsoft.WindowsAzure.Storage.RetryPolicies Namespace