【问题标题】:How to speed up Azure Storage Queue如何加速 Azure 存储队列
【发布时间】:2013-10-31 16:48:44
【问题描述】:

我已经尽我所能来提高插入速度。这实际上只是几件没有改进的事情。

我需要将大量标识符 (Int64) 发送到队列,以便我的多个工作角色可以处理它而不必担心并发问题。

我尝试了foreach 循环(.ToString()BitConverter.GetBytes()):

foreach(long id in ids) {
    queue.AddMessage(new CloudQueueMessage(id.ToString() /*BitConverter.GetBytes(id)*/));
}

还有一个并行的.ForAll<T>()

ids.AsParallel().ForAll(id => queue.AddMessage(new CloudMessage(id.ToString())));

来自本地和同一数据中心内的 WorkerRole,插入的最大值为每秒 5 次,平均每秒 4.73 次。

我做错了吗?

【问题讨论】:

  • 您要添加的消息有多大?
  • @PeterRitchie 2 个字节或 6 个字节,具体取决于方法(BitConverter 与 ToString)

标签: performance azure azure-storage azure-storage-queues


【解决方案1】:

尝试在 tcp 堆栈上禁用 Nagle,因为这会缓冲小数据包,从而导致发送内容延迟超过 1/2 秒。把它放在你的角色开始代码中:

ServicePointManager.UseNagleAlgorithm = false; 

【讨论】:

【解决方案2】:

我使用不同的方法从公司网络中的笔记本电脑每秒发送 1500 条消息,并在与存储帐户位于同一位置的 VM 上达到了 2000 条消息的限制。

我使用了一个异步并行分区器,并结合了一些默认连接限制和分区计数的调整。

ServicePointManager.DefaultConnectionLimit = 1000;

public static async Task SendMessagesAsync(CloudQueue queue, IEnumerable<string> messages)
{
    await Task.WhenAll(
            from partition in Partitioner.Create(messages).GetPartitions(500)
            select Task.Run(async delegate
            {
                using (partition)
                    while (partition.MoveNext())
                        await queue.AddMessageAsync(new CloudQueueMessage(partition.Current));
            }));
}

打开或关闭 Nagle 对性能没有影响。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-10-15
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 2021-02-22
    • 1970-01-01
    • 2014-01-28
    相关资源
    最近更新 更多