Fix MaxWorkerOpenFiles calculation on high cores nodes (#7107)
* Fix MaxWorkerOpenFiles calculation on high cores nodes * Add e2e test for rlimit_nofile * Fix doc for max-worker-open-files
This commit is contained in:
parent
8328b532f7
commit
4bdb5538a4
3 changed files with 60 additions and 7 deletions
|
@ -454,7 +454,7 @@ _**default:**_ 16384
|
||||||
## max-worker-open-files
|
## max-worker-open-files
|
||||||
|
|
||||||
Sets the [maximum number of files](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile) that can be opened by each worker process.
|
Sets the [maximum number of files](http://nginx.org/en/docs/ngx_core_module.html#worker_rlimit_nofile) that can be opened by each worker process.
|
||||||
The default of 0 means "max open files (system's limit) / [worker-processes](#worker-processes) - 1024".
|
The default of 0 means "max open files (system's limit) - 1024".
|
||||||
_**default:**_ 0
|
_**default:**_ 0
|
||||||
|
|
||||||
## map-hash-bucket-size
|
## map-hash-bucket-size
|
||||||
|
|
|
@ -512,12 +512,7 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC
|
||||||
if cfg.MaxWorkerOpenFiles == 0 {
|
if cfg.MaxWorkerOpenFiles == 0 {
|
||||||
// the limit of open files is per worker process
|
// the limit of open files is per worker process
|
||||||
// and we leave some room to avoid consuming all the FDs available
|
// and we leave some room to avoid consuming all the FDs available
|
||||||
wp, err := strconv.Atoi(cfg.WorkerProcesses)
|
maxOpenFiles := rlimitMaxNumFiles() - 1024
|
||||||
klog.V(3).InfoS("Worker processes", "count", wp)
|
|
||||||
if err != nil {
|
|
||||||
wp = 1
|
|
||||||
}
|
|
||||||
maxOpenFiles := (rlimitMaxNumFiles() / wp) - 1024
|
|
||||||
klog.V(3).InfoS("Maximum number of open file descriptors", "value", maxOpenFiles)
|
klog.V(3).InfoS("Maximum number of open file descriptors", "value", maxOpenFiles)
|
||||||
if maxOpenFiles < 1024 {
|
if maxOpenFiles < 1024 {
|
||||||
// this means the value of RLIMIT_NOFILE is too low.
|
// this means the value of RLIMIT_NOFILE is too low.
|
||||||
|
|
58
test/e2e/settings/global_options.go
Normal file
58
test/e2e/settings/global_options.go
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
Copyright 2020 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package settings
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/onsi/ginkgo"
|
||||||
|
"k8s.io/ingress-nginx/test/e2e/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = framework.IngressNginxDescribe("global-options", func() {
|
||||||
|
f := framework.NewDefaultFramework("global-options")
|
||||||
|
|
||||||
|
ginkgo.It("should have worker_rlimit_nofile option", func() {
|
||||||
|
f.WaitForNginxConfiguration(func(server string) bool {
|
||||||
|
return strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024))
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ginkgo.It("should have worker_rlimit_nofile option and be independent on amount of worker processes", func() {
|
||||||
|
f.SetNginxConfigMapData(map[string]string{
|
||||||
|
"worker-processes": "11",
|
||||||
|
})
|
||||||
|
|
||||||
|
f.WaitForNginxConfiguration(func(server string) bool {
|
||||||
|
return strings.Contains(server, "worker_processes 11;") &&
|
||||||
|
strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// rlimitMaxNumFiles returns hard limit for RLIMIT_NOFILE
|
||||||
|
func rlimitMaxNumFiles() int {
|
||||||
|
var rLimit syscall.Rlimit
|
||||||
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||||
|
if err != nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return int(rLimit.Max)
|
||||||
|
}
|
Loading…
Reference in a new issue