Skip to content

Commit a5b8ef9

Browse files
committed
[#2160] Fix dispatch starvation when network consumers have full prefetch
Queue.doPageInForDispatch() used pagedInPendingSize < maxPageSize as the sole gate for paging in messages from the store. When low-priority network consumers had saturated prefetch (not acking), their undispatched messages accumulated in dispatchPendingList, counting against maxPageSize and blocking page-in for all consumers — including higher-priority app consumers with available prefetch capacity. Two changes: 1. When pagedInPendingSize >= maxPageSize, cap toPageIn to what consumers can actually accept (getConsumerMessageCountBeforeFull) 2. Allow page-in when any consumer has available prefetch capacity, even if pagedInPendingSize >= maxPageSize
1 parent f3acdd8 commit a5b8ef9

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

  • activemq-broker/src/main/java/org/apache/activemq/broker/region

activemq-broker/src/main/java/org/apache/activemq/broker/region/Queue.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2113,8 +2113,13 @@ private PendingList doPageInForDispatch(boolean force, boolean processExpired, i
21132113
pagedInPendingDispatchLock.readLock().unlock();
21142114
}
21152115
if (isLazyDispatch() && !force) {
2116-
// Only page in the minimum number of messages which can be
2117-
// dispatched immediately.
2116+
toPageIn = Math.min(toPageIn, getConsumerMessageCountBeforeFull());
2117+
}
2118+
if (pagedInPendingSize >= maxPageSize && !force) {
2119+
// When the pending dispatch list is full, only page in what
2120+
// consumers can actually accept. This prevents unbounded growth
2121+
// while still allowing consumers with available prefetch capacity
2122+
// to receive messages even when other consumers are full.
21182123
toPageIn = Math.min(toPageIn, getConsumerMessageCountBeforeFull());
21192124
}
21202125

@@ -2132,7 +2137,8 @@ private PendingList doPageInForDispatch(boolean force, boolean processExpired, i
21322137
maxPageSize);
21332138
}
21342139

2135-
if (toPageIn > 0 && (force || (haveRealConsumer() && pagedInPendingSize < maxPageSize))) {
2140+
if (toPageIn > 0 && (force || (haveRealConsumer() && (pagedInPendingSize < maxPageSize
2141+
|| getConsumerMessageCountBeforeFull() > 0)))) {
21362142
int count = 0;
21372143
result = new ArrayList<QueueMessageReference>(toPageIn);
21382144
messagesLock.writeLock().lock();

0 commit comments

Comments
 (0)