mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix(proxy): remove per-chunk debug log in async_data_generator
Remove verbose_proxy_logger.debug that formatted every streaming chunk, which triggered expensive Pydantic serialization on the hot path.
This commit is contained in:
parent
437d504ef0
commit
7a233d5f06
2 changed files with 27 additions and 8 deletions
|
|
@ -1955,15 +1955,10 @@ class CustomStreamWrapper:
|
|||
hasattr(processed_chunk, "usage")
|
||||
and getattr(processed_chunk, "usage", None) is not None
|
||||
):
|
||||
# Strip usage from the outgoing chunk so
|
||||
# model_dump_json(exclude_none=True) drops it.
|
||||
# The copy in self.chunks retains usage for
|
||||
# calculate_total_usage().
|
||||
# Set usage to None so model_dump_json(exclude_none=True)
|
||||
# drops it. The original usage is already preserved in
|
||||
# self.chunks (appended above) for calculate_total_usage().
|
||||
processed_chunk.usage = None # type: ignore
|
||||
# After nullifying usage, check if the chunk has any
|
||||
# remaining content (delta, finish_reason, etc.).
|
||||
# is_model_response_stream_empty sees usage=None and
|
||||
# correctly skips it, only checking meaningful fields.
|
||||
is_empty = is_model_response_stream_empty(
|
||||
model_response=cast(ModelResponseStream, processed_chunk)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
"""
|
||||
Tests that PrometheusAuthMiddleware is a pure ASGI middleware (not BaseHTTPMiddleware).
|
||||
|
||||
BaseHTTPMiddleware wraps streaming responses with receive_or_disconnect per chunk,
|
||||
which blocks the event loop and causes severe throughput degradation.
|
||||
"""
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from litellm.proxy.middleware.prometheus_auth_middleware import PrometheusAuthMiddleware
|
||||
|
||||
|
||||
def test_is_not_base_http_middleware():
|
||||
"""PrometheusAuthMiddleware must NOT inherit from BaseHTTPMiddleware."""
|
||||
assert not issubclass(PrometheusAuthMiddleware, BaseHTTPMiddleware), (
|
||||
"PrometheusAuthMiddleware should be a pure ASGI middleware, not BaseHTTPMiddleware. "
|
||||
"BaseHTTPMiddleware causes severe streaming performance degradation."
|
||||
)
|
||||
|
||||
|
||||
def test_has_asgi_call_protocol():
|
||||
"""PrometheusAuthMiddleware must implement the ASGI __call__ protocol."""
|
||||
assert "__call__" in PrometheusAuthMiddleware.__dict__, (
|
||||
"PrometheusAuthMiddleware must define __call__(self, scope, receive, send)"
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue