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
|
|
@ -18,11 +18,11 @@ package search
|
|||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/metamorphosis-dev/samsa/internal/cache"
|
||||
"github.com/metamorphosis-dev/samsa/internal/httpclient"
|
||||
"github.com/metamorphosis-dev/samsa/internal/config"
|
||||
"github.com/metamorphosis-dev/samsa/internal/contracts"
|
||||
"github.com/metamorphosis-dev/samsa/internal/engines"
|
||||
|
|
@ -49,7 +49,7 @@ func NewService(cfg ServiceConfig) *Service {
|
|||
timeout = 10 * time.Second
|
||||
}
|
||||
|
||||
httpClient := &http.Client{Timeout: timeout}
|
||||
httpClient := httpclient.NewClient(timeout)
|
||||
|
||||
var up *upstream.Client
|
||||
if cfg.UpstreamURL != "" {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue