Summary
Currently, NewConn dispatches each incoming request (or batch) in its own goroutine with no upper bound on parallelism. Under high load this can exhaust resources.
Add a WithConcurrency(n int) option that caps the number of handler goroutines running simultaneously, similar to jrpc2's Concurrency server option.
Proposed API
// WithConcurrency limits the number of handler goroutines that can run
// concurrently. A value of 0 (the default) means unlimited.
func WithConcurrency(n int) Option
A semaphore (buffered channel) in conn would gate entry into each handler goroutine. Callers that can't acquire the semaphore block until a slot is available or the connection closes.
Motivation
- Prevents goroutine explosion under high request volume
- Allows resource-bounded deployments (e.g. DB connection pools sized to match)
- Brings parity with
github.com/creachadair/jrpc2
Summary
Currently,
NewConndispatches each incoming request (or batch) in its own goroutine with no upper bound on parallelism. Under high load this can exhaust resources.Add a
WithConcurrency(n int)option that caps the number of handler goroutines running simultaneously, similar tojrpc2'sConcurrencyserver option.Proposed API
A semaphore (buffered channel) in
connwould gate entry into each handler goroutine. Callers that can't acquire the semaphore block until a slot is available or the connection closes.Motivation
github.com/creachadair/jrpc2