-
Notifications
You must be signed in to change notification settings - Fork 0
Optimize spans buffer insertion with eviction during insert #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,8 +2,8 @@ | |||||
|
|
||||||
| import logging | ||||||
| import pickle | ||||||
| import threading | ||||||
| from collections.abc import Callable | ||||||
| from dataclasses import dataclass | ||||||
| from datetime import date, datetime, timezone | ||||||
| from enum import Enum | ||||||
| from time import time | ||||||
|
|
@@ -27,12 +27,13 @@ | |||||
| validate_dynamic_cluster, | ||||||
| ) | ||||||
|
|
||||||
| _local_buffers = None | ||||||
| _local_buffers_lock = threading.Lock() | ||||||
|
|
||||||
| logger = logging.getLogger(__name__) | ||||||
|
|
||||||
| T = TypeVar("T", str, bytes) | ||||||
|
|
||||||
|
|
||||||
| def _get_model_key(model: type[models.Model]) -> str: | ||||||
| return str(model._meta) | ||||||
| # Debounce our JSON validation a bit in order to not cause too much additional | ||||||
| # load everywhere | ||||||
| _last_validation_log: float | None = None | ||||||
|
|
@@ -81,6 +82,103 @@ def callback(self, buffer_hook_event: BufferHookEvent) -> bool: | |||||
| redis_buffer_registry = BufferHookRegistry() | ||||||
|
|
||||||
|
|
||||||
| # Callable to get the queue name for the given model_key. | ||||||
| # May return None to not assign a queue for the given model_key. | ||||||
| ChooseQueueFunction = Callable[[str], str | None] | ||||||
|
|
||||||
|
|
||||||
| @dataclass | ||||||
| class PendingBufferValue: | ||||||
| model_key: str | None | ||||||
| pending_buffer: "PendingBuffer" | ||||||
| generate_queue: ChooseQueueFunction | None | ||||||
|
|
||||||
|
|
||||||
| class PendingBufferRouter: | ||||||
| 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 | ||||||
| self.pending_buffer_router: dict[str, PendingBufferValue] = dict() | ||||||
|
||||||
| self.pending_buffer_router: dict[str, PendingBufferValue] = dict() | |
| self.pending_buffer_router: dict[str, PendingBufferValue] = {} |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
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.
| self._routers: dict[str, ChooseQueueFunction] = dict() | |
| self._routers: dict[str, ChooseQueueFunction] = {} |
Copilot
AI
Jul 26, 2025
There was a problem hiding this comment.
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.
| process_incr_kwargs: dict[str, Any] = dict() | |
| process_incr_kwargs: dict[str, Any] = {} |
There was a problem hiding this comment.
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.