Skip to content

[Java] feat: add empty-queue skip scheduling for SimpleConsumer long-polling#1213

Open
crazywen wants to merge 1 commit intoapache:masterfrom
crazywen:feature/empty-queue-skip-scheduling
Open

[Java] feat: add empty-queue skip scheduling for SimpleConsumer long-polling#1213
crazywen wants to merge 1 commit intoapache:masterfrom
crazywen:feature/empty-queue-skip-scheduling

Conversation

@crazywen
Copy link
Copy Markdown

Motivation

When using SimpleConsumer with long-polling, if message distribution across queues
is uneven (some queues empty, others with messages), the consumer gets blocked by
long-polling on empty queues, causing significant delay in receiving messages from
queues that actually have data.

This is especially problematic in production with multiple queues where message
traffic is bursty.

Modification

Enhanced SubscriptionLoadBalancer with empty-queue skip scheduling:

  • After each receiveMessage call, the result (empty or not) is fed back to the
    SubscriptionLoadBalancer via markEmptyResult()/markNonEmptyResult()
  • Queues that consecutively return empty are temporarily skipped in takeMessageQueue()
  • Skip duration is proportional to consecutive empty count (capped at 1000 rounds)
  • When a queue returns messages again, its empty counter resets immediately
  • Uses AtomicIntegerFieldUpdater for thread-safe state updates
  • Fully backward-compatible: no API changes, no configuration required

Result

  • Queues with messages are polled more frequently
  • Overall message reception latency reduced in uneven-distribution scenarios
  • Zero overhead when all queues have messages (skip map stays empty)
  • Added unit tests for SubscriptionLoadBalancer

Type

  • Enhancement

…polling

When using SimpleConsumer with long-polling, if message distribution across
queues is uneven (some queues empty, others with messages), the consumer gets
blocked by long-polling on empty queues, causing significant delay in receiving
messages from queues that actually have data.

Enhanced SubscriptionLoadBalancer with empty-queue skip scheduling:
- After each receiveMessage call, the result is fed back to the load balancer
- Queues that consecutively return empty are temporarily skipped in takeMessageQueue()
- Skip duration is proportional to consecutive empty count (capped at 1000 rounds)
- When a queue returns messages again, its empty counter resets immediately
- Fully backward-compatible: without feedback, behavior is identical to round-robin

Co-Authored-By: crazywen <xnxxljw@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant