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:
Franz Kafka 2026-03-23 14:26:26 +00:00
parent 7ea50d3123
commit 9e95ce7b53
6 changed files with 100 additions and 7 deletions

View file

@ -22,13 +22,14 @@ import (
"time"
"github.com/metamorphosis-dev/samsa/internal/config"
"github.com/metamorphosis-dev/samsa/internal/httpclient"
)
// NewDefaultPortedEngines returns the Go-native engine registry.
// If cfg is nil, API keys fall back to environment variables.
func NewDefaultPortedEngines(client *http.Client, cfg *config.Config) map[string]Engine {
if client == nil {
client = &http.Client{Timeout: 10 * time.Second}
client = httpclient.NewClient(10 * time.Second)
}
var braveAPIKey, braveAccessToken, youtubeAPIKey string