Skip to content

Commit

Permalink
Added config options for proxy max idle connections
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Sep 12, 2024
1 parent 477aebc commit dd09dcb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/app/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path"
"strconv"
"strings"
"time"

"github.com/claceio/clace/internal/app/appfs"
"github.com/claceio/clace/internal/app/apptype"
Expand Down Expand Up @@ -655,6 +656,16 @@ func (a *App) addProxyConfig(count int, router *chi.Mux, proxyDef *starlarkstruc
}

proxy := httputil.NewSingleHostReverseProxy(url)

customTransport := http.DefaultTransport.(*http.Transport).Clone()
maxIdleConnCount := a.appConfig.Proxy.MaxIdleConns
customTransport.MaxConnsPerHost = maxIdleConnCount * 2
customTransport.MaxIdleConns = maxIdleConnCount
customTransport.MaxIdleConnsPerHost = maxIdleConnCount
customTransport.IdleConnTimeout = time.Duration(a.appConfig.Proxy.IdleConnTimeoutSecs) * time.Second
customTransport.DisableCompression = a.appConfig.Proxy.DisableCompression
proxy.Transport = customTransport

defaultDirector := proxy.Director
proxy.Director = func(req *http.Request) {
defaultDirector(req)
Expand Down
5 changes: 5 additions & 0 deletions internal/system/clace.default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ container.idle_shutdown_dev_apps = false
# Status check Config
container.status_check_interval_secs = 5
container.status_health_attempts = 3

# Proxy related settings
proxy.max_idle_conns = 250
proxy.idle_conn_timeout_secs = 15
proxy.disable_compression = true
4 changes: 4 additions & 0 deletions internal/system/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ func TestServerConfig(t *testing.T) {
testutil.AssertEqualsInt(t, "idle", 180, c.AppConfig.Container.IdleShutdownSecs)
testutil.AssertEqualsInt(t, "status interval", 5, c.AppConfig.Container.StatusCheckIntervalSecs)
testutil.AssertEqualsInt(t, "status attempts", 3, c.AppConfig.Container.StatusHealthAttempts)

testutil.AssertEqualsInt(t, "proxy max idle", 250, c.AppConfig.Proxy.MaxIdleConns)
testutil.AssertEqualsInt(t, "proxy idle timeout", 15, c.AppConfig.Proxy.IdleConnTimeoutSecs)
testutil.AssertEqualsBool(t, "proxy disable compression", true, c.AppConfig.Proxy.DisableCompression)
}

func TestClientConfig(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions internal/system/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func NewHttpClient(serverUri, user, password string, skipCertCheck bool) *HttpCl
} else {
customTransport := http.DefaultTransport.(*http.Transport).Clone()
customTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: skipCertCheck}
customTransport.MaxIdleConns = 500
customTransport.MaxIdleConnsPerHost = 500
client = &http.Client{
Transport: customTransport,
Timeout: time.Duration(180) * time.Second,
Expand Down
8 changes: 8 additions & 0 deletions internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type SecretConfig map[string]any
type AppConfig struct {
CORS CORS `toml:"cors"`
Container Container `toml:"container"`
Proxy Proxy `toml:"proxy"`
}

type CORS struct {
Expand All @@ -94,6 +95,13 @@ type Container struct {
StatusHealthAttempts int `toml:"status_health_attempts"`
}

type Proxy struct {
// Proxy related config
MaxIdleConns int `toml:"max_idle_conns"`
IdleConnTimeoutSecs int `toml:"idle_conn_timeout_secs"`
DisableCompression bool `toml:"disable_compression"`
}

type PluginContext struct {
Logger *Logger
AppId AppId
Expand Down

0 comments on commit dd09dcb

Please sign in to comment.