Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
PBS-632 add max connections per host config setting to general http a… (
Browse files Browse the repository at this point in the history
  • Loading branch information
bsardo authored Jun 24, 2020
1 parent 58e75cc commit e2eb237
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Configuration struct {
const MIN_COOKIE_SIZE_BYTES = 500

type HTTPClient struct {
MaxConnsPerHost int `mapstructure:"max_connections_per_host"`
MaxIdleConns int `mapstructure:"max_idle_connections"`
MaxIdleConnsPerHost int `mapstructure:"max_idle_connections_per_host"`
IdleConnTimeout int `mapstructure:"idle_connection_timeout_seconds"`
Expand Down Expand Up @@ -669,9 +670,11 @@ func SetupViper(v *viper.Viper, filename string) {
v.SetDefault("host_cookie.value", "")
v.SetDefault("host_cookie.ttl_days", 90)
v.SetDefault("host_cookie.max_cookie_size_bytes", 0)
v.SetDefault("http_client.max_connections_per_host", 0) // unlimited
v.SetDefault("http_client.max_idle_connections", 400)
v.SetDefault("http_client.max_idle_connections_per_host", 10)
v.SetDefault("http_client.idle_connection_timeout_seconds", 60)
v.SetDefault("http_client_cache.max_connections_per_host", 0) // unlimited
v.SetDefault("http_client_cache.max_idle_connections", 10)
v.SetDefault("http_client_cache.max_idle_connections_per_host", 2)
v.SetDefault("http_client_cache.idle_connection_timeout_seconds", 60)
Expand Down
4 changes: 4 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ external_cache:
host: www.externalprebidcache.net
path: endpoints/cache
http_client:
max_connections_per_host: 10
max_idle_connections: 500
max_idle_connections_per_host: 20
idle_connection_timeout_seconds: 30
http_client_cache:
max_connections_per_host: 5
max_idle_connections: 1
max_idle_connections_per_host: 2
idle_connection_timeout_seconds: 3
Expand Down Expand Up @@ -217,9 +219,11 @@ func TestFullConfig(t *testing.T) {
cmpStrings(t, "cache.query", cfg.CacheURL.Query, "uuid=%PBS_CACHE_UUID%")
cmpStrings(t, "external_cache.host", cfg.ExtCacheURL.Host, "www.externalprebidcache.net")
cmpStrings(t, "external_cache.path", cfg.ExtCacheURL.Path, "endpoints/cache")
cmpInts(t, "http_client.max_connections_per_host", cfg.Client.MaxConnsPerHost, 10)
cmpInts(t, "http_client.max_idle_connections", cfg.Client.MaxIdleConns, 500)
cmpInts(t, "http_client.max_idle_connections_per_host", cfg.Client.MaxIdleConnsPerHost, 20)
cmpInts(t, "http_client.idle_connection_timeout_seconds", cfg.Client.IdleConnTimeout, 30)
cmpInts(t, "http_client_cache.max_connections_per_host", cfg.CacheClient.MaxConnsPerHost, 5)
cmpInts(t, "http_client_cache.max_idle_connections", cfg.CacheClient.MaxIdleConns, 1)
cmpInts(t, "http_client_cache.max_idle_connections_per_host", cfg.CacheClient.MaxIdleConnsPerHost, 2)
cmpInts(t, "http_client_cache.idle_connection_timeout_seconds", cfg.CacheClient.IdleConnTimeout, 3)
Expand Down
2 changes: 2 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func New(cfg *config.Configuration, rateConvertor *currencies.RateConverter) (r

generalHttpClient := &http.Client{
Transport: &http.Transport{
MaxConnsPerHost: cfg.Client.MaxConnsPerHost,
MaxIdleConns: cfg.Client.MaxIdleConns,
MaxIdleConnsPerHost: cfg.Client.MaxIdleConnsPerHost,
IdleConnTimeout: time.Duration(cfg.Client.IdleConnTimeout) * time.Second,
Expand All @@ -197,6 +198,7 @@ func New(cfg *config.Configuration, rateConvertor *currencies.RateConverter) (r

cacheHttpClient := &http.Client{
Transport: &http.Transport{
MaxConnsPerHost: cfg.CacheClient.MaxConnsPerHost,
MaxIdleConns: cfg.CacheClient.MaxIdleConns,
MaxIdleConnsPerHost: cfg.CacheClient.MaxIdleConnsPerHost,
IdleConnTimeout: time.Duration(cfg.CacheClient.IdleConnTimeout) * time.Second,
Expand Down

0 comments on commit e2eb237

Please sign in to comment.