C# azure队列性能

C# azure队列性能,c#,performance,azure,C#,Performance,Azure,对于windows azure队列,每个存储的可扩展性目标应该是大约500条消息/秒()。我有一个简单的程序,它只向队列中写入几条消息。程序需要10秒钟才能完成(每秒4条消息)。我在一台虚拟机(位于西欧)内运行该程序,我的存储帐户也位于西欧。我没有为我的存储设置地理复制。我的连接字符串设置为使用http协议 // http://blogs.msdn.com/b/windowsazurestorage/archive/2010/06/25/nagle-s-algorithm-is-n

对于windows azure队列,每个存储的可扩展性目标应该是大约500条消息/秒()。我有一个简单的程序,它只向队列中写入几条消息。程序需要10秒钟才能完成(每秒4条消息)。我在一台虚拟机(位于西欧)内运行该程序,我的存储帐户也位于西欧。我没有为我的存储设置地理复制。我的连接字符串设置为使用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();
//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());
CreateIfNotExist();
var w=新秒表();
w、 Start();
对于(int i=0;i<50;i++)
{
Console.WriteLine(“nr{0}”,i);
AddMessage(新的CloudQueueMessage(“hello”+i));
}
w、 停止();
WriteLine(“经过的:{0}”,w.elapsedmillesons);
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();
CloudStorageAccount-storageAccount=CloudStorageAccount.Parse(ConfigurationManager.AppSettings[“DataConnectionString]”);
var cloudQueueClient=storageAccount.CreateCloudQueueClient();
var queue=cloudQueueClient.GetQueueReference(Guid.NewGuid().ToString());
//ServicePointManager.UseNagleAlgorithm=false;//如果在这里更改nagle算法,性能将正常。
CreateIfNotExist();
ServicePointManager.UseNagleAlgorithm=false;//太晚了,队列已经创建,没有“nagle”
var w=新秒表();
w、 Start();
对于(int i=0;i<50;i++)
{
Console.WriteLine(“nr{0}”,i);
AddMessage(新的CloudQueueMessage(“hello”+i));
}
w、 停止();
WriteLine(“经过的:{0}”,w.elapsedmillesons);
queue.Delete();

Sandrino建议使用app.config文件配置ServicePointManager的解决方案的优点是,ServicePointManager在应用程序启动时初始化,因此您不必担心时间依赖性。

几天前我回答了一个类似的问题:

在表存储中添加1000个项目需要3分钟,随着我在回答中所描述的更改,它下降到4秒(250个请求/秒)。最后,表存储和存储队列并没有什么不同。后端是一样的,数据只是以不同的方式存储。表存储和队列都是通过RESTAPI公开的,因此如果您改进处理请求的方式,您将获得更好的性能

最重要的变化是:

  • expect100Continue
    :false
  • useNagleAlgorithm
    :false(您已经在这样做了)
  • 与连接管理/maxconnection结合的并行请求

此外,在创建服务点之前,还应增加ServicePointManager.DefaultConnectionLimit。实际上,Sandrino的回答说了同样的事情,但是使用了config

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

选择分布式分区键

将您的帐户配置在计算机和客户附近

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

从2012年7月起,Microsoft将队列和表的SLA设置为2000 tps


我没有阅读Sandrino的链接答案,抱歉,我只是在看Build 2012会话时提到了这个问题。

如果从循环中删除Console.WriteLine()会怎么样?这样会快几毫秒,但仍然大约4条消息/秒。我认为500/s是单个队列的总体可伸缩性性能,不一定是串行读/写。单线程不是如何扩展的,所以可能是您的往返延迟。您可以切换到异步还是尝试批处理操作?我尝试了你的建议,并立即奏效(使用你另一篇文章中的system.net配置部分)。非常感谢。然而,我很好奇为什么没有app.config中的更改,我的代码就不能很好地工作,毕竟我也通过编程将nagle算法设置为false。我发现,当您以编程方式配置ServicePointManager时,您必须在实例化任何队列之前进行配置。我的性能也有问题,您的速度为4 m/s。这些改进给了您什么?