Skip to content

Conversation

@everettbu
Copy link
Contributor

@everettbu everettbu commented Jul 26, 2025

Test 2

Enhance the Redis buffer system to support dedicated queue routing
for different models, improving performance isolation and reducing
buffer processing contention across high-volume models.

Key improvements:
- Add PendingBufferRouter for per-model queue assignment
- Implement RedisBufferRouter with customizable queue functions
- Extract model metadata from Redis keys for routing decisions
- Add comprehensive test coverage for custom queue assignments

This optimization allows critical models like Group to use dedicated
processing queues while maintaining backward compatibility for
models without custom queue assignments.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copilot AI review requested due to automatic review settings July 26, 2025 19:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the Redis buffer system by implementing a router-based approach that allows different models to use dedicated queues for processing buffer increments. This prevents backlog issues with one model from affecting others.

  • Introduces RedisBufferRouter and PendingBufferRouter classes to manage model-specific buffer routing
  • Replaces single shared PendingBuffer with multiple model-specific buffers
  • Adds queue assignment functionality for models to use dedicated processing queues

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/sentry/buffer/redis.py Core implementation of buffer routing system with new router classes and model key extraction
tests/sentry/buffer/test_redis.py Updates imports to include new router functionality and helper functions
sentry-repo Adds subproject commit reference

def __init__(self, incr_batch_size: int) -> None:
self.incr_batch_size = incr_batch_size
self.default_pending_buffer = PendingBuffer(self.incr_batch_size)
# map of model_key to PendingBufferValue
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

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

There is an extra trailing space at the end of the comment line.

Suggested change
# map of model_key to PendingBufferValue
# map of model_key to PendingBufferValue

Copilot uses AI. Check for mistakes.
self.incr_batch_size = incr_batch_size
self.default_pending_buffer = PendingBuffer(self.incr_batch_size)
# map of model_key to PendingBufferValue
self.pending_buffer_router: dict[str, PendingBufferValue] = dict()
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Use {} instead of dict() for better performance and readability when creating empty dictionaries.

Suggested change
self.pending_buffer_router: dict[str, PendingBufferValue] = dict()
self.pending_buffer_router: dict[str, PendingBufferValue] = {}

Copilot uses AI. Check for mistakes.
class RedisBufferRouter:
def __init__(self) -> None:
# map of model_key (generated from _get_model_key function) to queue name
self._routers: dict[str, ChooseQueueFunction] = dict()
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Use {} instead of dict() for better performance and readability when creating empty dictionaries.

Suggested change
self._routers: dict[str, ChooseQueueFunction] = dict()
self._routers: dict[str, ChooseQueueFunction] = {}

Copilot uses AI. Check for mistakes.
#
# Hence, we override the default queue of the process_incr task by passing in the assigned queue for the
# model associated with the model_key.
process_incr_kwargs: dict[str, Any] = dict()
Copy link

Copilot AI Jul 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Use {} instead of dict() for better performance and readability when creating empty dictionaries.

Suggested change
process_incr_kwargs: dict[str, Any] = dict()
process_incr_kwargs: dict[str, Any] = {}

Copilot uses AI. Check for mistakes.
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