Skip to content
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
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const (

// defaultRequestTimeout is the default per-request timeout (was 6s prior to v4.2.0).
defaultRequestTimeout = 30 * time.Second
// defaultMaxConnsPerHost caps concurrent TCP connections per host.
defaultMaxConnsPerHost = 5
// defaultMaxConnsPerHost caps concurrent TCP connections per host and sizes the idle pool; extra requests wait for a free connection.
defaultMaxConnsPerHost = 100
// defaultIdleTimeout sits below the typical 60s LB idle timeout with a 5s safety margin.
defaultIdleTimeout = 55 * time.Second
// defaultConnectTimeout caps TCP + TLS handshake duration.
Expand Down Expand Up @@ -105,7 +105,7 @@ func WithTimeout(t time.Duration) ClientOption {
}
}

// WithMaxConnsPerHost caps concurrent TCP connections per host. Default: 5.
// WithMaxConnsPerHost caps concurrent TCP connections per host, which is also the number of idle connections kept for reuse. Default: 100.
Comment thread
mogita marked this conversation as resolved.
// Ignored when WithHTTPClient is set.
func WithMaxConnsPerHost(n int) ClientOption {
return func(c *Client) {
Expand Down Expand Up @@ -209,6 +209,7 @@ func buildDefaultHTTPClient(requestTimeout time.Duration, maxConnsPerHost int, i
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.MaxConnsPerHost = maxConnsPerHost
transport.MaxIdleConnsPerHost = maxConnsPerHost
transport.MaxIdleConns = 0 // DefaultTransport's global 100 would otherwise cap the per-host idle pool
transport.IdleConnTimeout = idleTimeout
transport.DialContext = (&net.Dialer{
Timeout: connectTimeout,
Expand Down
7 changes: 4 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ func TestClientDefaultTransportConfig(t *testing.T) {

tr, ok := httpClient.Transport.(*http.Transport)
require.True(t, ok, "default transport must be *http.Transport, not nil")
assert.Equal(t, 5, tr.MaxConnsPerHost, "default MaxConnsPerHost = 5")
assert.Equal(t, 5, tr.MaxIdleConnsPerHost, "default MaxIdleConnsPerHost = 5")
assert.Equal(t, 100, tr.MaxConnsPerHost, "default MaxConnsPerHost = 100")
assert.Equal(t, 100, tr.MaxIdleConnsPerHost, "default MaxIdleConnsPerHost = 100")
assert.Equal(t, 0, tr.MaxIdleConns, "no global idle cap below the per-host one")
assert.Equal(t, 55*time.Second, tr.IdleConnTimeout, "default IdleTimeout = 55s")
assert.False(t, tr.DisableKeepAlives, "KeepAlive invariant")
}
Expand Down Expand Up @@ -257,7 +258,7 @@ func TestClientInfoLogOnConstruction(t *testing.T) {
got := cap.infos[0]
assert.Contains(t, got, "client.initialized")
assert.Contains(t, got, "stream.sdk.name=getstream-go")
assert.Contains(t, got, "stream.client.max_conns_per_host=5")
assert.Contains(t, got, "stream.client.max_conns_per_host=100")
assert.Contains(t, got, "stream.client.idle_timeout_seconds=55")
assert.Contains(t, got, "stream.client.connect_timeout_seconds=10")
assert.Contains(t, got, "stream.client.request_timeout_seconds=30")
Expand Down
Loading