[Network] TCP backpressure for streaming LLM responses #31

Open
opened 2026-09-11 01:26:14 +00:00 by poimen · 0 comments
Member

Problem

Fast GPU overwhelms slow client connections, floods gateway RAM.

Investigation

  • Gateway proxy in internal/proxy/ uses Flush() for SSE streaming
  • No backpressure — gateway buffers indefinitely if client reads slowly
  • Tests verify chunk arrival but not backpressure

Resolution

Apply TCP backpressure: bounded buffer in io.Copy, pause upstream on slow client. Add context.WithCancel on client disconnect.

Files

  • internal/proxy/bodydispatch.go
  • internal/proxy/streaming_test.go
## Problem Fast GPU overwhelms slow client connections, floods gateway RAM. ## Investigation - Gateway proxy in `internal/proxy/` uses `Flush()` for SSE streaming - No backpressure — gateway buffers indefinitely if client reads slowly - Tests verify chunk arrival but not backpressure ## Resolution Apply TCP backpressure: bounded buffer in `io.Copy`, pause upstream on slow client. Add `context.WithCancel` on client disconnect. ## Files - `internal/proxy/bodydispatch.go` - `internal/proxy/streaming_test.go`
poimen added this to the LLM Production Hardening milestone 2026-09-11 01:26:14 +00:00
Sign in to join this conversation.