From 50f7c731012edbb455b7ccfd24bb8d20fd5915c5 Mon Sep 17 00:00:00 2001 From: Javier de la Torre Date: Mon, 30 Nov 2026 21:53:24 +0100 Subject: [PATCH] s3 backend: HTTP/1.1 client defaults for disable_http2 (#13126) * s3 backend: HTTP/1.1 client defaults for disable_http2 ## Problem `disable_http2` (#11897) keeps the cloud tier's S3 client on HTTP/1.1, so every tier upload and range read gets a connection of its own. The rest of the client still has the defaults sized for one multiplexed HTTP/2 connection: - Go's idle pool keeps only 2 connections per host, so a burst of concurrent range reads redials TLS for almost every request once the burst is over and the next one starts; - the wait for response headers is the 60 s bound every tier client has; - the SDK retries 3 times. On a Ceph RGW-based S3 service, HTTP/2's small flow-control window held tier uploads at 18 MB/s and made 24 concurrent cold scans take 52 s each; on HTTP/1.1 they took 3.7 s each, but only with a larger idle pool, a shorter header bound and more retries for the 503 SlowDown answers that the extra parallelism draws. ## Fix With `disable_http2 = true` the tier client also gets: - an idle pool of 100 (`MaxIdleConns` and `MaxIdleConnsPerHost`); - `ResponseHeaderTimeout` of 30 s; - `MaxRetries` 5, so the SDK's retryer backs off on 5xx, SlowDown and throttling. `max_connections` and `idle_connection_timeout_seconds` apply as before. Without `disable_http2` the client is unchanged. The scaffold `master.toml` mentions the defaults. ## Tests `TestS3BackendHTTP1ClientDefaults` in `weed/storage/backend/s3_backend/s3_sessions_test.go`: with `disable_http2` the transport has the idle pool and the 30 s header bound, and the client 5 retries; without it (and with `max_connections` set) the client keeps the SDK's retries, the default idle pool and `s3ReadTimeout`. It fails without the change. `go vet ./weed/storage/backend/s3_backend/` and `go test ./weed/storage/backend/s3_backend/`: ok. `go build ./weed`: ok. * s3 backend: keep the larger idle pool for every tier client A tier client on a plain http:// endpoint, or on a TLS service that offers no HTTP/2, speaks HTTP/1.1 without disable_http2 and had the same 2 idle connections per host, so each burst of concurrent reads redialed. HTTP/2 keeps one connection, so the pool size does not change it. The header bound and retries stay with disable_http2. Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Chris Lu Co-authored-by: Claude Opus 5.5 --- weed/command/scaffold/master.toml | 3 +- .../storage/backend/s3_backend/s3_sessions.go | 17 ++++++++ .../backend/s3_backend/s3_sessions_test.go | 40 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/weed/command/scaffold/master.toml b/weed/command/scaffold/master.toml index cfca8826fc..edc4ea5694 100644 --- a/weed/command/scaffold/master.toml +++ b/weed/command/scaffold/master.toml @@ -45,7 +45,8 @@ bucket = "your_bucket_name" # an existing bucket endpoint = "" storage_class = "STANDARD_IA" # optional HTTP client tuning for S3-compatible services: -# disable_http2 = false # true keeps the client on HTTP/1.1, one connection per concurrent request +# disable_http2 = false # true keeps the client on HTTP/1.1, one connection per concurrent request, +# # with a 30s response header timeout and 5 retries # max_connections = 0 # cap on connections to the endpoint, 0 = no cap # idle_connection_timeout_seconds = 0 # close idle connections sooner, 0 = Go default (90s) diff --git a/weed/storage/backend/s3_backend/s3_sessions.go b/weed/storage/backend/s3_backend/s3_sessions.go index bf9f3af5f0..9e6310314e 100644 --- a/weed/storage/backend/s3_backend/s3_sessions.go +++ b/weed/storage/backend/s3_backend/s3_sessions.go @@ -43,13 +43,27 @@ type httpOptions struct { idleConnTimeout time.Duration } +// Over HTTP/1.1 every concurrent request needs a connection of its own, so +// every client keeps more idle connections than Go's default of 2 per host; +// HTTP/2 holds one connection and is not affected. With disable_http2 the +// client also gets a shorter bound on the wait for response headers, and more +// retries with back-off for 5xx, 503 SlowDown and throttling. +const ( + http1MaxIdleConns = 100 + http1ResponseHeaderTimeout = 30 * time.Second + http1MaxRetries = 5 +) + func (o httpOptions) newTransport() *http.Transport { t := http.DefaultTransport.(*http.Transport).Clone() t.DialContext = (&net.Dialer{Timeout: s3ConnectTimeout, KeepAlive: 30 * time.Second}).DialContext t.ResponseHeaderTimeout = s3ReadTimeout + t.MaxIdleConns = http1MaxIdleConns + t.MaxIdleConnsPerHost = http1MaxIdleConns if o.disableHTTP2 { t.ForceAttemptHTTP2 = false t.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{} + t.ResponseHeaderTimeout = http1ResponseHeaderTimeout } if o.maxConnsPerHost > 0 { t.MaxConnsPerHost = o.maxConnsPerHost @@ -80,6 +94,9 @@ func createSession(awsAccessKeyId, awsSecretAccessKey, region, endpoint string, S3DisableContentMD5Validation: aws.Bool(true), HTTPClient: &http.Client{Transport: httpOpts.newTransport()}, } + if httpOpts.disableHTTP2 { + config.MaxRetries = aws.Int(http1MaxRetries) + } if awsAccessKeyId != "" && awsSecretAccessKey != "" { config.Credentials = credentials.NewStaticCredentials(awsAccessKeyId, awsSecretAccessKey, "") } diff --git a/weed/storage/backend/s3_backend/s3_sessions_test.go b/weed/storage/backend/s3_backend/s3_sessions_test.go index eb5699259c..454b3d4423 100644 --- a/weed/storage/backend/s3_backend/s3_sessions_test.go +++ b/weed/storage/backend/s3_backend/s3_sessions_test.go @@ -218,3 +218,43 @@ func TestS3BackendIdleTimeoutOverflowFallsBackToDefault(t *testing.T) { } } } + +// With disable_http2 each request needs its own connection, so the client +// gets a 30 s bound on response headers and 5 retries. The idle pool of 100 +// applies to every client: a plain http:// endpoint is HTTP/1.1 without the flag. +func TestS3BackendHTTP1ClientDefaults(t *testing.T) { + s, err := newS3BackendStorage(testProperties{"endpoint": "http://127.0.0.1:11", "disable_http2": "true"}, "", "http1-defaults") + if err != nil { + t.Fatal(err) + } + tr := backendTransport(t, s) + if tr == nil { + t.Fatal("disable_http2 set, yet the client has no transport of its own") + } + if tr.MaxIdleConns != http1MaxIdleConns || tr.MaxIdleConnsPerHost != http1MaxIdleConns { + t.Errorf("idle pool %d/%d per host, want %d/%d", tr.MaxIdleConns, tr.MaxIdleConnsPerHost, http1MaxIdleConns, http1MaxIdleConns) + } + if tr.ResponseHeaderTimeout != http1ResponseHeaderTimeout { + t.Errorf("response header timeout %v, want %v", tr.ResponseHeaderTimeout, http1ResponseHeaderTimeout) + } + if got := s.conn.(*s3.S3).Client.Config.MaxRetries; got == nil || *got != http1MaxRetries { + t.Errorf("MaxRetries %v, want %d", got, http1MaxRetries) + } + + // without disable_http2 the client keeps the SDK's retries and the + // s3ReadTimeout header bound, but still gets the idle pool + plain, err := newS3BackendStorage(testProperties{"endpoint": "http://127.0.0.1:12", "max_connections": "8"}, "", "http1-plain") + if err != nil { + t.Fatal(err) + } + if got := plain.conn.(*s3.S3).Client.Config.MaxRetries; got != nil && *got == http1MaxRetries { + t.Error("MaxRetries raised without disable_http2") + } + tr = backendTransport(t, plain) + if tr == nil || tr.ResponseHeaderTimeout != s3ReadTimeout { + t.Error("disable_http2 header bound applied to a client without disable_http2") + } + if tr != nil && (tr.MaxIdleConns != http1MaxIdleConns || tr.MaxIdleConnsPerHost != http1MaxIdleConns) { + t.Errorf("idle pool %d/%d per host without disable_http2, want %d/%d", tr.MaxIdleConns, tr.MaxIdleConnsPerHost, http1MaxIdleConns, http1MaxIdleConns) + } +}