Use system fs.max-files as limits instead of hard-coded value
This commit is contained in:
parent
28c67257e3
commit
9ce52c51f1
4 changed files with 23 additions and 1 deletions
|
@ -288,7 +288,12 @@ func (n NGINXController) OnUpdate(cmap *api.ConfigMap, ingressCfg ingress.Config
|
||||||
cfg.ServerNameHashMaxSize = serverNameHashMaxSize
|
cfg.ServerNameHashMaxSize = serverNameHashMaxSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the limit of open files is per worker process
|
||||||
|
// and we leave some room to avoid consuming all the FDs available
|
||||||
|
maxOpenFiles := (sysctlFSFileMax() / cfg.WorkerProcesses) - 1024
|
||||||
|
|
||||||
return n.t.Write(config.TemplateConfig{
|
return n.t.Write(config.TemplateConfig{
|
||||||
|
MaxOpenFiles: maxOpenFiles,
|
||||||
BacklogSize: sysctlSomaxconn(),
|
BacklogSize: sysctlSomaxconn(),
|
||||||
Backends: ingressCfg.Backends,
|
Backends: ingressCfg.Backends,
|
||||||
PassthroughBackends: ingressCfg.PassthroughBackends,
|
PassthroughBackends: ingressCfg.PassthroughBackends,
|
||||||
|
|
|
@ -39,6 +39,19 @@ func sysctlSomaxconn() int {
|
||||||
return maxConns
|
return maxConns
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sysctlFSFileMax returns the value of fs.file-max, i.e.
|
||||||
|
// maximum number of open file descriptors
|
||||||
|
func sysctlFSFileMax() int {
|
||||||
|
maxConns, err := sysctl.New().GetSysctl("fs/file-max")
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("unexpected error reading system maximum number of open file descriptors (fs.file-max): %v", err)
|
||||||
|
// returning 0 means don't render the value
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return maxConns
|
||||||
|
}
|
||||||
|
|
||||||
func diff(b1, b2 []byte) ([]byte, error) {
|
func diff(b1, b2 []byte) ([]byte, error) {
|
||||||
f1, err := ioutil.TempFile("", "a")
|
f1, err := ioutil.TempFile("", "a")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -271,7 +271,9 @@ func NewDefault() Configuration {
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TemplateConfig contains the nginx configuration to render the file nginx.conf
|
||||||
type TemplateConfig struct {
|
type TemplateConfig struct {
|
||||||
|
MaxOpenFiles int
|
||||||
BacklogSize int
|
BacklogSize int
|
||||||
Backends []*ingress.Backend
|
Backends []*ingress.Backend
|
||||||
PassthroughBackends []*ingress.SSLPassthroughBackend
|
PassthroughBackends []*ingress.SSLPassthroughBackend
|
||||||
|
|
|
@ -3,7 +3,9 @@ daemon off;
|
||||||
|
|
||||||
worker_processes {{ $cfg.WorkerProcesses }};
|
worker_processes {{ $cfg.WorkerProcesses }};
|
||||||
pid /run/nginx.pid;
|
pid /run/nginx.pid;
|
||||||
worker_rlimit_nofile 131072;
|
{{ if ne .MaxOpenFiles 0 }}
|
||||||
|
worker_rlimit_nofile {{ .MaxOpenFiles }};
|
||||||
|
{{ end}}
|
||||||
|
|
||||||
events {
|
events {
|
||||||
multi_accept on;
|
multi_accept on;
|
||||||
|
|
Loading…
Reference in a new issue