From dbf8b32fc823016767e8f8ab7abf18a3217797af Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Thu, 1 Oct 2026 14:09:55 +0200 Subject: [PATCH 1/2] perf: raise the default connection pool size from 5 to 100 The default of 5 capped each client at 5 concurrent requests, so busy servers queued behind the pool. 100 matches httpx's default and stream-py. --- client.go | 6 +++--- client_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 23eb318..6941742 100644 --- a/client.go +++ b/client.go @@ -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. @@ -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. // Ignored when WithHTTPClient is set. func WithMaxConnsPerHost(n int) ClientOption { return func(c *Client) { diff --git a/client_test.go b/client_test.go index 08cc864..27a86bd 100644 --- a/client_test.go +++ b/client_test.go @@ -212,8 +212,8 @@ 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, 55*time.Second, tr.IdleConnTimeout, "default IdleTimeout = 55s") assert.False(t, tr.DisableKeepAlives, "KeepAlive invariant") } @@ -257,7 +257,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") From 6d5f31bce97c339b48eac2c1b51c15d3a64e615a Mon Sep 17 00:00:00 2001 From: Yun Wang Date: Thu, 1 Oct 2026 14:39:13 +0200 Subject: [PATCH 2/2] perf: drop the global idle cap so the per-host idle pool is honored --- client.go | 1 + client_test.go | 1 + 2 files changed, 2 insertions(+) diff --git a/client.go b/client.go index 6941742..a4b11c8 100644 --- a/client.go +++ b/client.go @@ -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, diff --git a/client_test.go b/client_test.go index 27a86bd..48e2b45 100644 --- a/client_test.go +++ b/client_test.go @@ -214,6 +214,7 @@ func TestClientDefaultTransportConfig(t *testing.T) { require.True(t, ok, "default transport must be *http.Transport, not nil") 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") }