You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: reduce CPU usage by making poll interval configurable
The _process_batch() method was using a hardcoded 10ms (0.01s) timeout
in its polling loop, causing ~100 polls/second per handler when idle.
With OptimizedRealtimeHandler creating 3 handlers per symbol, this
resulted in 1200%+ CPU usage with 4 symbols.
Changes:
- Add DEFAULT_POLL_INTERVAL class constant (50ms instead of 10ms)
- Add poll_interval parameter to BatchedWebSocketHandler.__init__()
- Use self.poll_interval instead of hardcoded value in _process_batch()
- Update OptimizedRealtimeHandler to pass poll_interval to child handlers
- Add poll_interval_ms to stats output
Benchmark results:
- Before: 1200%+ CPU with 4 symbols
- After: ~700% CPU with 4 symbols (42% reduction)
The 50ms default provides good balance between responsiveness and
CPU efficiency. Users can still configure lower values if needed.
Fixes#82
0 commit comments