【问题标题】:Azure Queue too slow - About 2 minutes until the message is being picked up by Worker RoleAzure 队列太慢 - 大约 2 分钟,直到消息被 Worker Role 拾取
【发布时间】:2013-04-30 00:41:33
【问题描述】:

我在 Web 角色上有一个 WCF,然后是一个工作角色来处理由 WCF 添加到天蓝色队列的消息。

我正在做以下事情:

var queue = queueStorage.GetQueueReference("myqueue");

var message = new CloudQueueMessage(string.Format("{0},{1}", pWord,processed));
queue.AddMessage(message);

那我想等到消息处理完,但是这个时间太长了,平均一条消息2分钟!!

在我的工人角色上,我有以下几点:

这是我的 onStart 方法:

CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
        inputQueue = queueClient.GetQueueReference("myqueue");

然后在我的 Run 方法上:

while (true)
            {
                try
                {
                    // Retrieve and process a new message from the queue.
                    msg = inputQueue.GetMessage();
                    if (msg != null)
                    {
                        result = processMessage(msg);

关于我的 processMessage 方法:

var messageParts = msg.AsString.Split(new char[] { ',' });
            var word = messageParts[0];
            var processed = Convert.ToBoolean(messageParts[2]);
            word = "recibido";
            processed = true;
            addMessageToQueue2(userId,processed);
            return 1;

将消息添加到队列是:

var queue = outputQueue.GetQueueReference("myQueue");
            var message = new CloudQueueMessage(string.Format("{0},{1}", pWord, pProcessed));
            queue.AddMessage(message);

我对队列相当陌生,但我认为这应该可以工作并且每条消息的速度超过 2 分钟。任何帮助将不胜感激。

【问题讨论】:

  • 只是检查:在最后一段代码中,您正在创建对myQueue 的引用。这是实际的队列名称,还是拼写错误?队列名称必须全部小写。
  • 另外,由于您的消息是“{0},{1}”,因此您的行:var processes = Convert.ToBoolean(messageParts[2]); - 应该生成错误,因为 messageParts 应该只能作为 messageParts[0] 或 messageParts[1] 访问 - 你是否陷入了 try/catch?
  • 那只是为了替换我的实际队列名称...是的,我知道队列名称只是小写的困难方式:)
  • 不产生任何异常 viperguynaz
  • 另外:队列绝对没有消息延迟 2 分钟。假设您关闭 Nagle 算法(有关 ServicePointManager 类的详细信息,请参阅this blog post),您将看到惊人的事务率(高达每秒 2,000 个)。

标签: c# azure


【解决方案1】:

代码看起来将相同的消息添加回队列。 GetMessage 只会使消息在 30 秒内无法访问(在您处理消息时),并允许工作人员角色失败。阅读How to use the Queue Storage Service, specifically How to: De-queue the next message了解详情。工人角色的流程:

  • 获取消息
  • 进程消息
  • 如果成功,DeleteMessage 否则重新尝试处理。

另外请注意,除非您使用 StringSplitOptions.None 调用 string.split,否则您不会得到占位符,并且您的结果数组只有 2 个元素长 - 阅读更多内容 String.Split Method (Char[], StringSplitOptions)

【讨论】:

  • 我试试这个让我们看看
猜你喜欢
  • 1970-01-01
  • 2015-04-15
  • 1970-01-01
  • 2014-11-26
  • 2016-08-14
  • 2012-07-23
  • 2017-09-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多