如何加速Azure存储队列

时间:2013-10-22 17:12:59

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

我已经尝试了一切我能想到的提高插入速度的方法。这真的只是一些没有改进的事情。

我需要将一大堆标识符(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次。

我做错了吗?

Simpsons

2 个答案:

答案 0 :(得分:12)

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

ServicePointManager.UseNagleAlgorithm = false; 

答案 1 :(得分:0)

我使用了另一种方法来从公司网络中的笔记本电脑每秒发送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对性能没有影响。