Skip to content

feat: concurrency control for handler dispatch #40

Description

@mcriley821

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions