Merge pull request #187 from emilevauge/add-max-idle-conns-per-host

Add MaxIdleConnsPerHost. Fixes too many open files error.
This commit is contained in:
Vincent Demeester 2016-02-09 22:49:03 +01:00
commit bb3b9f61cd
4 changed files with 75 additions and 56 deletions

4
cmd.go
View file

@ -14,6 +14,7 @@ import (
"github.com/emilevauge/traefik/provider" "github.com/emilevauge/traefik/provider"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
"net/http"
) )
var traefikCmd = &cobra.Command{ var traefikCmd = &cobra.Command{
@ -80,6 +81,7 @@ func init() {
traefikCmd.PersistentFlags().Var(&arguments.Certificates, "certificates", "SSL certificates and keys pair, ie 'tests/traefik.crt,tests/traefik.key'. You may add several certificate/key pairs to terminate HTTPS for multiple domain names using TLS SNI") traefikCmd.PersistentFlags().Var(&arguments.Certificates, "certificates", "SSL certificates and keys pair, ie 'tests/traefik.crt,tests/traefik.key'. You may add several certificate/key pairs to terminate HTTPS for multiple domain names using TLS SNI")
traefikCmd.PersistentFlags().StringP("logLevel", "l", "ERROR", "Log level") traefikCmd.PersistentFlags().StringP("logLevel", "l", "ERROR", "Log level")
traefikCmd.PersistentFlags().DurationVar(&arguments.ProvidersThrottleDuration, "providersThrottleDuration", time.Duration(2*time.Second), "Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time.") traefikCmd.PersistentFlags().DurationVar(&arguments.ProvidersThrottleDuration, "providersThrottleDuration", time.Duration(2*time.Second), "Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time.")
traefikCmd.PersistentFlags().Int("maxIdleConnsPerHost", 0, "If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used")
traefikCmd.PersistentFlags().BoolVar(&arguments.web, "web", false, "Enable Web backend") traefikCmd.PersistentFlags().BoolVar(&arguments.web, "web", false, "Enable Web backend")
traefikCmd.PersistentFlags().StringVar(&arguments.Web.Address, "web.address", ":8080", "Web administration port") traefikCmd.PersistentFlags().StringVar(&arguments.Web.Address, "web.address", ":8080", "Web administration port")
@ -140,6 +142,7 @@ func init() {
viper.BindPFlag("logLevel", traefikCmd.PersistentFlags().Lookup("logLevel")) viper.BindPFlag("logLevel", traefikCmd.PersistentFlags().Lookup("logLevel"))
// TODO: wait for this issue to be corrected: https://github.com/spf13/viper/issues/105 // TODO: wait for this issue to be corrected: https://github.com/spf13/viper/issues/105
viper.BindPFlag("providersThrottleDuration", traefikCmd.PersistentFlags().Lookup("providersThrottleDuration")) viper.BindPFlag("providersThrottleDuration", traefikCmd.PersistentFlags().Lookup("providersThrottleDuration"))
viper.BindPFlag("maxIdleConnsPerHost", traefikCmd.PersistentFlags().Lookup("maxIdleConnsPerHost"))
viper.SetDefault("certificates", &Certificates{}) viper.SetDefault("certificates", &Certificates{})
viper.SetDefault("providersThrottleDuration", time.Duration(2*time.Second)) viper.SetDefault("providersThrottleDuration", time.Duration(2*time.Second))
} }
@ -150,6 +153,7 @@ func run() {
// load global configuration // load global configuration
globalConfiguration := LoadConfiguration() globalConfiguration := LoadConfiguration()
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = globalConfiguration.MaxIdleConnsPerHost
loggerMiddleware := middlewares.NewLogger(globalConfiguration.AccessLogsFile) loggerMiddleware := middlewares.NewLogger(globalConfiguration.AccessLogsFile)
defer loggerMiddleware.Close() defer loggerMiddleware.Close()

View file

@ -23,6 +23,7 @@ type GlobalConfiguration struct {
Certificates Certificates Certificates Certificates
LogLevel string LogLevel string
ProvidersThrottleDuration time.Duration ProvidersThrottleDuration time.Duration
MaxIdleConnsPerHost int
Docker *provider.Docker Docker *provider.Docker
File *provider.File File *provider.File
Web *WebProvider Web *WebProvider

View file

@ -95,65 +95,63 @@ Usage:
Available Commands: Available Commands:
version Print version version Print version
help Help about any command
Flags: Flags:
--accessLogsFile="log/access.log": Access logs file --accessLogsFile string Access logs file (default "log/access.log")
--boltdb=false: Enable Boltdb backend --boltdb Enable Boltdb backend
--boltdb.endpoint="127.0.0.1:4001": Boltdb server endpoint --boltdb.endpoint string Boltdb server endpoint (default "127.0.0.1:4001")
--boltdb.filename="": Override default configuration template. For advanced users :) --boltdb.filename string Override default configuration template. For advanced users :)
--boltdb.prefix="/traefik": Prefix used for KV store --boltdb.prefix string Prefix used for KV store (default "/traefik")
--boltdb.watch=true: Watch provider --boltdb.watch Watch provider (default true)
--certificates=: SSL certificates and keys. You may add several certificate/key pairs to terminate HTTPS for multiple domain names using TLS SNI --certificates value SSL certificates and keys pair, ie 'tests/traefik.crt,tests/traefik.key'. You may add several certificate/key pairs to terminate HTTPS for multiple domain names using TLS SNI
-c, --configFile="": Configuration file to use (TOML, JSON, YAML, HCL). -c, --configFile string Configuration file to use (TOML, JSON, YAML, HCL).
--consul=false: Enable Consul backend --consul Enable Consul backend
--consul.endpoint="127.0.0.1:8500": Consul server endpoint --consul.endpoint string Consul server endpoint (default "127.0.0.1:8500")
--consul.filename="": Override default configuration template. For advanced users :) --consul.filename string Override default configuration template. For advanced users :)
--consul.prefix="/traefik": Prefix used for KV store --consul.prefix string Prefix used for KV store (default "/traefik")
--consul.watch=true: Watch provider --consul.watch Watch provider (default true)
--docker=false: Enable Docker backend --docker Enable Docker backend
--docker.domain="": Default domain used --docker.domain string Default domain used
--docker.endpoint="unix:///var/run/docker.sock": Docker server endpoint. Can be a tcp or a unix socket endpoint --docker.endpoint string Docker server endpoint. Can be a tcp or a unix socket endpoint (default "unix:///var/run/docker.sock")
--docker.filename="": Override default configuration template. For advanced users :) --docker.filename string Override default configuration template. For advanced users :)
--docker.tls=false: Enable Docker TLS support --docker.tls Enable Docker TLS support
--docker.tls.ca="": TLS CA --docker.tls.ca string TLS CA
--docker.tls.cert="": TLS cert --docker.tls.cert string TLS cert
--docker.tls.insecureSkipVerify=false: TLS insecure skip verify --docker.tls.insecureSkipVerify TLS insecure skip verify
--docker.tls.key="": TLS key --docker.tls.key string TLS key
--docker.watch=true: Watch provider --docker.watch Watch provider (default true)
--etcd=false: Enable Etcd backend --etcd Enable Etcd backend
--etcd.endpoint="127.0.0.1:4001": Etcd server endpoint --etcd.endpoint string Etcd server endpoint (default "127.0.0.1:4001")
--etcd.filename="": Override default configuration template. For advanced users :) --etcd.filename string Override default configuration template. For advanced users :)
--etcd.prefix="/traefik": Prefix used for KV store --etcd.prefix string Prefix used for KV store (default "/traefik")
--etcd.watch=true: Watch provider --etcd.watch Watch provider (default true)
--file=false: Enable File backend --file Enable File backend
--file.filename="": Override default configuration template. For advanced users :) --file.filename string Override default configuration template. For advanced users :)
--file.watch=true: Watch provider --file.watch Watch provider (default true)
-g, --graceTimeOut="10": Timeout in seconds. Duration to give active requests a chance to finish during hot-reloads -g, --graceTimeOut string Timeout in seconds. Duration to give active requests a chance to finish during hot-reloads (default "10")
-h, --help=false: help for traefik -l, --logLevel string Log level (default "ERROR")
-l, --logLevel="ERROR": Log level --marathon Enable Marathon backend
--marathon=false: Enable Marathon backend --marathon.domain string Default domain used
--marathon.domain="": Default domain used --marathon.endpoint string Marathon server endpoint. You can also specify multiple endpoint for Marathon (default "http://127.0.0.1:8080")
--marathon.endpoint="http://127.0.0.1:8080": Marathon server endpoint. You can also specify multiple endpoint for Marathon --marathon.filename string Override default configuration template. For advanced users :)
--marathon.filename="": Override default configuration template. For advanced users :) --marathon.networkInterface string Network interface used to call Marathon web services. Needed in case of multiple network interfaces (default "eth0")
--marathon.networkInterface="eth0": Network interface used to call Marathon web services. Needed in case of multiple network interfaces --marathon.watch Watch provider (default true)
--marathon.watch=true: Watch provider --maxIdleConnsPerHost int If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used
-p, --port=":80": Reverse proxy port -p, --port string Reverse proxy port (default ":80")
--providersThrottleDuration=2s: Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time. --providersThrottleDuration duration Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time. (default 2s)
--traefikLogsFile="log/traefik.log": Traefik logs file --traefikLogsFile string Traefik logs file (default "log/traefik.log")
--web=false: Enable Web backend --web Enable Web backend
--web.address=":8080": Web administration port --web.address string Web administration port (default ":8080")
--web.cerFile="": SSL certificate --web.cerFile string SSL certificate
--web.keyFile="": SSL certificate --web.keyFile string SSL certificate
--web.readOnly=false: Enable read only API --web.readOnly Enable read only API
--zookeeper=false: Enable Zookeeper backend --zookeeper Enable Zookeeper backend
--zookeeper.endpoint="127.0.0.1:2181": Zookeeper server endpoint --zookeeper.endpoint string Zookeeper server endpoint (default "127.0.0.1:2181")
--zookeeper.filename="": Override default configuration template. For advanced users :) --zookeeper.filename string Override default configuration template. For advanced users :)
--zookeeper.prefix="/traefik": Prefix used for KV store --zookeeper.prefix string Prefix used for KV store (default "/traefik")
--zookeeper.watch=true: Watch provider --zookeeper.watch Watch provider (default true)
Use "traefik [command] --help" for more information about a command.
Use "traefik help [command]" for more information about a command.
``` ```
## <a id="global"></a> Global configuration ## <a id="global"></a> Global configuration
@ -217,6 +215,14 @@ Use "traefik help [command]" for more information about a command.
# #
# ProvidersThrottleDuration = "5s" # ProvidersThrottleDuration = "5s"
# If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used.
# If you encounter 'too many open files' errors, you can either change this value, or change `ulimit` value.
#
# Optional
# Default: http.DefaultMaxIdleConnsPerHost
#
# MaxIdleConnsPerHost = 200
``` ```

View file

@ -55,6 +55,14 @@
# #
# ProvidersThrottleDuration = "5s" # ProvidersThrottleDuration = "5s"
# If non-zero, controls the maximum idle (keep-alive) to keep per-host. If zero, DefaultMaxIdleConnsPerHost is used.
# If you encounter 'too many open files' errors, you can either change this value, or change `ulimit` value.
#
# Optional
# Default: http.DefaultMaxIdleConnsPerHost
#
# MaxIdleConnsPerHost = 200
################################################################ ################################################################
# Web configuration backend # Web configuration backend