perf: shared http.Transport with tuned connection pooling
Add internal/httpclient package as a singleton RoundTripper used by all outbound engine requests (search, engines, autocomplete, upstream). Key Transport settings: - MaxIdleConnsPerHost = 20 (up from Go default of 2) - MaxIdleConns = 100 - IdleConnTimeout = 90s - DialContext timeout = 5s Previously, the default transport limited each host to 2 idle connections, forcing a new TCP+TLS handshake on every search for each engine. With 12 engines hitting the same upstream hosts in parallel, connections were constantly recycled. Now warm connections are reused across all goroutines and requests.
This commit is contained in:
parent
7ea50d3123
commit
9e95ce7b53
6 changed files with 100 additions and 7 deletions
30
internal/httpclient/dial.go
Normal file
30
internal/httpclient/dial.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// samsa — a privacy-respecting metasearch engine
|
||||
// Copyright (C) 2026-present metamorphosis-dev
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package httpclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
// dialWithTimeout returns a DialContext function for http.Transport that
|
||||
// respects the given connection timeout.
|
||||
func dialWithTimeout(timeout time.Duration) func(context.Context, string, string) (net.Conn, error) {
|
||||
d := &net.Dialer{Timeout: timeout}
|
||||
return d.DialContext
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue