Skip to content

Optimize consumer poll loop to skip sleep when active#174

Open
anilcan-kara wants to merge 1 commit into
wellle:masterfrom
anilcan-kara:claude/optimize-poll-loop
Open

Optimize consumer poll loop to skip sleep when active#174
anilcan-kara wants to merge 1 commit into
wellle:masterfrom
anilcan-kara:claude/optimize-poll-loop

Conversation

@anilcan-kara

Copy link
Copy Markdown

This PR addresses issue #173 by optimizing the consumer loop to avoid unnecessary sleeps when deliveries are successfully prefetched.

Key Changes:

  • consumeBatch(): Now returns (int, error), representing the count of successfully prefetched deliveries in the batch and any Redis error.
  • consume(): Updated the consumption loop to only execute the time.Sleep wait block when count == 0 (meaning either the queue is empty, or the local prefetch delivery channel is full).

Benefits:

  • Throughput & Latency: When there are active messages in the queue and consumers have capacity, they are prefetched and delivered instantly without the pollDuration sleep delay.
  • Redis Load: When the queue is empty, the consumer loop still sleeps for pollDuration, keeping the polling frequency low and conserving Redis CPU resources.

Copilot AI review requested due to automatic review settings June 19, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants