Skip to content

Optimize websocket broadcast fanout#19

Open
naufalfx805-source wants to merge 1 commit into
Dragoon4002:mainfrom
naufalfx805-source:optimize-ws-broadcast
Open

Optimize websocket broadcast fanout#19
naufalfx805-source wants to merge 1 commit into
Dragoon4002:mainfrom
naufalfx805-source:optimize-ws-broadcast

Conversation

@naufalfx805-source

Copy link
Copy Markdown

References #2

Scope

Optimizes the websocket fanout path in hub/ws/manager.py for both agent-specific broadcasts and price broadcasts.

Previously each subscriber was awaited one at a time, so one slow websocket delayed every other subscriber. The new path snapshots subscribers under the existing lock, sends the same payload concurrently with asyncio.gather(..., return_exceptions=True), and still removes sockets whose send fails.

I also replaced the runtime FastAPI WebSocket import with a small Protocol so the manager can be unit-tested without requiring FastAPI just for type annotations.

Benchmark

Synthetic local benchmark with 8 websocket subscribers, each send_text delayed by 30ms:

  • Serial baseline: 0.261s
  • Concurrent broadcast: 0.032s
  • Improvement: 8.1x faster

This reflects the hot path where dashboard/price-feed clients are connected at the same time and one slow socket should not serialize the whole fanout.

Validation

  • python -m pytest tests/test_ws_manager.py -q -> 2 passed
  • git diff --cached --check -> passed

If selected for payout, I can provide a Base USDC address privately after acceptance.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@naufalfx805-source is attempting to deploy a commit to the dragoon4002's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant