带有Node JS库的Azure Service Bus队列的最大吞吐量? [英] Max throughput for Azure Service Bus Queue with Node JS library?

查看:57
本文介绍了带有Node JS库的Azure Service Bus队列的最大吞吐量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Azure NodeJS库,我无法以每秒超过5或6条消息的速度接收来自Azure Service Bus队列的消息.这比官方文档建议的要慢几个数量级.我正在使用关闭分区的队列(如此处建议

Using the Azure NodeJS libraries, I'm unable to receive messages off of an Azure Service Bus Queue any faster than 5 or 6 messages a second. This is orders of magnitude slower than what the official docs suggest. I'm using a Queue with partitioning turned off (as recommended here Polling an Azure Service Bus Queue from an Azure WebJob using Node.js), reading in ReceiveAndDelete mode. Essentially I am just calling .receiveQueueMessage() repeatedly.

基于此问题( Azure服务总线可伸缩性)似乎与其他类似使用NodeJS时,每秒还会看到5/6条消息.这几乎是一个硬性限制吗?有任何已知的解决方法或优化方法吗?

Based on this question (Azure Service Bus Scalability) seems like others are also seeing 5/6 messages a second when using NodeJS. Is this pretty much a hard limit? Any known workarounds or optimizations?

推荐答案

您提供的线程中的代码很棒,它似乎在管道工作流中从Service Bus Queue接收消息,此消息将在之后接收到下一条消息.完成接收上一个.

The code in the thread which you provide is awesome, and it seems to receive messages from Service Bus Queue in a pipeline workflow, which will receive the next message after finished receiving the previous one.

并且如官方网站上所述在方案"阶段的高吞吐量队列"部分,我们可以找到适合您情况的以下几点:

And as mentions on official site at High-throughput queue section under Scenarios stage, we can find the following points which are appropriate to your situation:

  • 要提高队列的总体接收率,请使用多个消息工厂来创建接收者.

  • To increase the overall receive rate from the queue, use multiple message factories to create receivers.

使用异步操作来利用客户端批处理.

Use asynchronous operations to take advantage of client-side batching.

将批处理间隔设置为50ms,以减少服务总线的数量客户端协议传输.如果使用多个发件人,请增加批处理间隔为100毫秒.

Set the batching interval to 50ms to reduce the number of Service Bus client protocol transmissions. If multiple senders are used, increase the batching interval to 100ms.

要实现这些优化,我们可以利用

To achieve these optimizations, we can leverage the sample on Azure github repo.

并最大化单个队列的吞吐量.我使用上面的示例代码进行了简单的测试,并将循环时间设置为10ms.我测试的结果是:在ReceiveAndDelete模式下,它将每秒收到近50条消息;并且在PeekLock模式下每秒将收到约70条消息,如

And to Maximize the throughput of a single queue. I have a simply test leveraging the sample code above and set the loop time to 10ms. The result in my test is: it will get nearly 50 messages per second in ReceiveAndDelete mode; and it will get about 70 messages per second in PeekLock mode, shown at https://azure.microsoft.com/en-us/documentation/articles/service-bus-nodejs-how-to-use-queues/#receive-messages-from-a-queue

var uuid = require('node-uuid');
var azure = require('azure');
var serviceBus = azure.createServiceBusService(connectionString);

function checkForMessages(sbService, queueName, callback) {
  sbService.receiveQueueMessage(queueName,{ isPeekLock: true }, function (err, lockedMessage) {

    if (err) {
      if (err === 'No messages to receive') {
        console.log('No messages');
      } else {
        callback(err);
      }
    } else {
      callback(null, lockedMessage);
    }
  });
}

function processMessage(sbService, err, lockedMsg) {
  if (err) {
    console.log('Error on Rx: ', err);
  } else {
    console.log('Rx: ', lockedMsg);
    sbService.deleteMessage(lockedMsg, function(err2) {
      if (err2) {
        console.log('Failed to delete message: ', err2);
      } else {
        console.log('Deleted message.');
      }
    })
  }
}

var idx = 0;
function sendMessages(serviceBus, queueName) {
  var msg = 'Message # ' + (++idx) + (' '+uuid.v4());
  serviceBus.sendQueueMessage(queueName, msg, function (err) {
   if (err) {
     console.log('Failed Tx: ', err);
   } else {
     console.log('Sent ' + msg);
   }
  });
}


var queueName = 'myqueue';
serviceBus.getQueue(queueName, function (err,res) {
  if (err) {
   console.log('Failed: ', err);
  } else {
  console.log('current msg count '+ res.MessageCount);
   // var t = setInterval(checkForMessages.bind(null, serviceBus, queueName,function(err, lockedMsg){}), 10);  //ReceiveAndDelete mode
   var t = setInterval(checkForMessages.bind(null, serviceBus, queueName, processMessage.bind(null, serviceBus)), 10);  // PeekLock mode
   // setInterval(sendMessages.bind(null, serviceBus, queueName), 100);
                setTimeout(function(){
                                clearInterval(t);
                                console.log('task over');
                   },1000);
  }
}); 

这篇关于带有Node JS库的Azure Service Bus队列的最大吞吐量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆