Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option for defining concurrency limit per connection #26

Merged
merged 1 commit into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
Loading