Skip to content

Commit

Permalink
Adds option for defining concurrency limit per connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ksysoev committed Apr 27, 2024
1 parent 614970b commit 32ead4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions channel/connection_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,12 @@ func WithMaxFrameLimit(limit int64) ConnectionRegistryOption {
r.frameSizeLimit = limit
}
}

// WithConcurrencyLimit sets the maximum number of concurrent requests that can be handled by a connection.
// The default concurrency limit is 25.
// When the concurrency limit is exceeded, the connection stops reading messages until the number of concurrent requests decreases.
func WithConcurrencyLimit(limit uint) ConnectionRegistryOption {
return func(r *ConnectionRegistry) {
r.concurrencyLimit = limit
}
}
13 changes: 13 additions & 0 deletions channel/connection_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,16 @@ func TestConnectionRegistry_Shutdown(t *testing.T) {
t.Error("Expected registry to be closed")
}
}
func TestConnectionRegistry_WithConcurrencyLimit(t *testing.T) {
registry := NewConnectionRegistry()

if registry.concurrencyLimit != concurencyLimitPerConnection {
t.Errorf("Unexpected concurrency limit: got %d, expected %d", registry.concurrencyLimit, concurencyLimitPerConnection)
}

registry = NewConnectionRegistry(WithConcurrencyLimit(10))

if registry.concurrencyLimit != 10 {
t.Errorf("Unexpected concurrency limit: got %d, expected %d", registry.concurrencyLimit, 10)
}
}

0 comments on commit 32ead4d

Please sign in to comment.