Uploaded image for project: 'ActiveMQ .Net'
  1. ActiveMQ .Net
  2. AMQNET-564

Individual Acknowledgements are slow for large amounts of messages

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.7.2
    • Fix Version/s: None
    • Component/s: ActiveMQ
    • Environment:

      .NET 4.5.2
      Apache.NMS 1.7.1
      Apache.NMS.ActiveMQ 1.7.2

      Description

      When using the asynchronious Listener, the consumer gets pushed as many messages as possible from the queue. Using Individual Acknowledgement-Mode all messages need to be Acked.
      When the consumer loads many messages (>>25.000) the Ack. performance degrades badly (< 20 messages / s).

      New messages the consumer recieves are stored at the front of a LinkedList.
      Before the ack is send, the Consumer searches the list front-to-end. Because I (and most people probably) want to ack one of the oldest messages, the whole list needs to be traversed. Afterwards the found message is removed from the list, which traverses the list once again.

      The Code in question from MessageConsumer.cs:

      foreach (MessageDispatch originalDispatch in this.deliveredMessages)
      {
       if (originalDispatch.Message.MessageId.Equals(message.MessageId))
        {
          dispatch = originalDispatch;
          this.deliveredMessages.Remove(originalDispatch);
          break;
        }
      }
      

      I tried two changes to the code, and it is orders of magnitude faster for large amounts of messages (if the oldest message always needs to be acked). I used reflection to access the needed methods/fields because I had some problems compiling the original code.

      // Reverse the iteration
      for (var deliveredMessageNode = deliveredMessages.Last; deliveredMessageNode != null; deliveredMessageNode = deliveredMessageNode.Previous)
                      {
                          var deliveredMessage = deliveredMessageNode.Value;
                          if (deliveredMessage.Message.MessageId.Equals(message.MessageId))
                          {
                              dispatch = deliveredMessage;
      // Use the node to remove the message, don't search again for it
                              deliveredMessages.Remove(deliveredMessageNode);
                              break;
                          }
                      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              Juri Robl Juri Robl
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: