Azure队列性能



对于Windows Azure排队排队每个存储的可扩展性目标应为500消息/秒(http://msdn.microsoft.com/en-us/library/windowsazure/hh6977709.aspx)。我有以下简单的程序,这些程序只是将一些消息写入队列。该程序需要10秒才能完成(4条消息/秒)。我正在从虚拟机内部(West-Europe上)运行该程序,而我的存储帐户也位于West-Europe。我没有用于存储的设置地理复制。我的连接字符串已设置为使用HTTP协议。

       // http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-not-friendly-towards-small-requests.aspx
        ServicePointManager.UseNagleAlgorithm = false;
        CloudStorageAccount storageAccount=CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
        var cloudQueueClient = storageAccount.CreateCloudQueueClient();
        var queue = cloudQueueClient.GetQueueReference(Guid.NewGuid().ToString());
        queue.CreateIfNotExist();
        var w = new Stopwatch();
        w.Start();
        for (int i = 0; i < 50;i++ )
        {
            Console.WriteLine("nr {0}",i);
            queue.AddMessage(new CloudQueueMessage("hello "+i));    
        }
        w.Stop();
        Console.WriteLine("elapsed: {0}", w.ElapsedMilliseconds);
        queue.Delete();

知道我如何获得更好的性能?

编辑:

根据Sandrino di Mattia的答案,我重新分析了我最初发布的代码,并发现它还不够完整,无法重现该错误。实际上,在呼叫servicepointManager.usenaglealgorithm = false之前,我已经创建了一个队列。重现我的问题的代码看起来更像是:

        CloudStorageAccount storageAccount=CloudStorageAccount.Parse(ConfigurationManager.AppSettings["DataConnectionString"]);
        var cloudQueueClient = storageAccount.CreateCloudQueueClient();
        var queue = cloudQueueClient.GetQueueReference(Guid.NewGuid().ToString());
        //ServicePointManager.UseNagleAlgorithm = false; // If you change the nagle algorithm here, the performance will be okay.
        queue.CreateIfNotExist();
        ServicePointManager.UseNagleAlgorithm = false; // TOO LATE, the queue is already created without 'nagle'
        var w = new Stopwatch();
        w.Start();
        for (int i = 0; i < 50;i++ )
        {
            Console.WriteLine("nr {0}",i);
            queue.AddMessage(new CloudQueueMessage("hello "+i));    
        }
        w.Stop();
        Console.WriteLine("elapsed: {0}", w.ElapsedMilliseconds);
        queue.Delete();

Sandrino的建议解决方案使用app.config文件配置ServicePointManager。Div>

我几天前回答了一个类似的问题:如何使用Azure存储表实现每秒10个插入物。

对于在表存储中添加1000个项目,它花费了3分钟以上,而我在答案中描述的更改下降到4秒(250个请求/秒)。最后,表存储和存储队列并没有那么不同。后端是相同的,数据只是以不同的方式存储。而且两个表存储和队列都通过REST API暴露,因此,如果您改善了处理请求的方式,您将获得更好的性能。

最重要的更改:

  • expect100Continue:false
  • useNagleAlgorithm:false(您已经在这样做)
  • 并行请求与connectionManagement/maxconnection
  • 结合使用

另外,ServicePointManager.defaultConnectionLimit在制作服务点之前应增加。实际上,桑德里诺的答案说了同样的话,但使用config。

即使在云中也关闭代理检测。在代理配置元素中自动检测。减慢初始化。

选择分布式分区键。

将您的帐户汇总到计算和客户。

设计以根据需要添加更多帐户。

Microsoft将SLA设置为2,000 TPS,截至2012年7月7日。

我没有读过Sandrino的链接答案,对不起,只是在我观看Build 2012会议上的这个问题上。

最新更新