activemq-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Bain (JIRA)" <>
Subject [jira] [Commented] (AMQ-6239) Performance issue in PrioritizedPendingListIterator
Date Mon, 11 Apr 2016 13:08:25 GMT


Tim Bain commented on AMQ-6239:

This algorithm isn't thread-safe in the face of concurrent removals, so if we expect to use
it when not holding an exclusive lock, we need a change.  The find-the-next-iterator logic
needs to exist in next() as well (and so should be refactored out into a helper method that
I've called getIteratorThatHasNext() in the code below), to handle the case where the current
iterator has a remaining item when hasNext() is called but no longer does when next() is called.

The logic of next() should be:
while (true) {
  Iterator<MessageReference> iterator = getIteratorThatHasNext();
  if (iterator == null) {
    return null;
  MessageReference messageReference =;
  if (messageReference != null) {
    return messageReference;

This algorithm will keep getting the next iterator that should have a next item, and if it
turns out not to then we'll keep getting the next one, until we either fine one with a non-null
next() value or we run out of iterators to try.

> Performance issue in PrioritizedPendingListIterator
> ---------------------------------------------------
>                 Key: AMQ-6239
>                 URL:
>             Project: ActiveMQ
>          Issue Type: Improvement
>          Components: Broker
>    Affects Versions: 5.12.2
>            Reporter: Martin Lichtin
>         Attachments: AMQ-6239-yourkit-1.jpg,
> Sending and consuming 5000 messages to/from a queue, one can see heavy CPU use on the
broker side (v 5.12.2).
> Yourkit shows 
> PrioritizedPendingList$PrioritizedPendingListIterator.<init>
> as a hot spot method. It calls ArrayList.add(Object) around 12 mio times.
> Situation is that FilePendingMessageCursor.isEmpty() iterates over in-memory messages
and therefore (as it is a prioritized queue) uses PrioritizedPendingListIterator which uses
OrderedPendingList.getAsList() which overall turns out to be an expensive method as it converts
the self-managed linked list to a Java ArrayList and then this list is filled into another
ArrayList managed by PrioritizedPendingListIterator.
> PrioritizedPendingListIterator could be improved to walk the priority lists via OrderedPendingList
iterators, as these are implemented efficiently. 

This message was sent by Atlassian JIRA

View raw message