fix: reduce consumer poll timeout from 2000ms to 100ms

This commit is contained in:
Sreeram Venkatasubramanian 2026-04-07 14:19:59 +05:30 committed by Cyber MacGeddon
parent 4acd853023
commit f0c9039b76
2 changed files with 36 additions and 1 deletions

View file

@ -266,6 +266,41 @@ class TestMetricsIntegration:
mock_metrics.rate_limit.assert_called_once() mock_metrics.rate_limit.assert_called_once()
# ---------------------------------------------------------------------------
# Poll timeout
# ---------------------------------------------------------------------------
class TestPollTimeout:
@pytest.mark.asyncio
async def test_poll_timeout_is_100ms(self):
"""Consumer receive timeout should be 100ms, not the original 2000ms.
A 2000ms poll timeout means every service adds up to 2s of idle
blocking between message bursts. With many sequential hops in a
query pipeline, this compounds into seconds of unnecessary latency.
100ms keeps responsiveness high without significant CPU overhead.
"""
consumer = _make_consumer()
# Wire up a mock Pulsar consumer that records the receive kwargs
mock_pulsar_consumer = MagicMock()
received_kwargs = {}
def capture_receive(**kwargs):
received_kwargs.update(kwargs)
# Stop after one call
consumer.running = False
raise type('Timeout', (Exception,), {})("timeout")
mock_pulsar_consumer.receive = capture_receive
consumer.consumer = mock_pulsar_consumer
await consumer.consume_from_queue()
assert received_kwargs.get("timeout_millis") == 100
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Stop / running flag # Stop / running flag
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View file

@ -165,7 +165,7 @@ class Consumer:
try: try:
msg = await asyncio.to_thread( msg = await asyncio.to_thread(
consumer.receive, consumer.receive,
timeout_millis=2000 timeout_millis=100
) )
except Exception as e: except Exception as e:
# Handle timeout from any backend # Handle timeout from any backend