Skip to content

Commit 4bdb553

Browse files
authored
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
1 parent 8328b53 commit 4bdb553

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

docs/user-guide/nginx-configuration/configmap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ _**default:**_ 16384
454454
## max-worker-open-files
455455

456456
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.
457-
The default of 0 means "max open files (system's limit) / [worker-processes](#worker-processes) - 1024".
457+
The default of 0 means "max open files (system's limit) - 1024".
458458
_**default:**_ 0
459459

460460
## map-hash-bucket-size

internal/ingress/controller/nginx.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -512,12 +512,7 @@ func (n NGINXController) generateTemplate(cfg ngx_config.Configuration, ingressC
512512
if cfg.MaxWorkerOpenFiles == 0 {
513513
// the limit of open files is per worker process
514514
// and we leave some room to avoid consuming all the FDs available
515-
wp, err := strconv.Atoi(cfg.WorkerProcesses)
516-
klog.V(3).InfoS("Worker processes", "count", wp)
517-
if err != nil {
518-
wp = 1
519-
}
520-
maxOpenFiles := (rlimitMaxNumFiles() / wp) - 1024
515+
maxOpenFiles := rlimitMaxNumFiles() - 1024
521516
klog.V(3).InfoS("Maximum number of open file descriptors", "value", maxOpenFiles)
522517
if maxOpenFiles < 1024 {
523518
// this means the value of RLIMIT_NOFILE is too low.

test/e2e/settings/global_options.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package settings
18+
19+
import (
20+
"fmt"
21+
"strings"
22+
"syscall"
23+
24+
"github.com/onsi/ginkgo"
25+
"k8s.io/ingress-nginx/test/e2e/framework"
26+
)
27+
28+
var _ = framework.IngressNginxDescribe("global-options", func() {
29+
f := framework.NewDefaultFramework("global-options")
30+
31+
ginkgo.It("should have worker_rlimit_nofile option", func() {
32+
f.WaitForNginxConfiguration(func(server string) bool {
33+
return strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024))
34+
35+
})
36+
})
37+
38+
ginkgo.It("should have worker_rlimit_nofile option and be independent on amount of worker processes", func() {
39+
f.SetNginxConfigMapData(map[string]string{
40+
"worker-processes": "11",
41+
})
42+
43+
f.WaitForNginxConfiguration(func(server string) bool {
44+
return strings.Contains(server, "worker_processes 11;") &&
45+
strings.Contains(server, fmt.Sprintf("worker_rlimit_nofile %d;", rlimitMaxNumFiles()-1024))
46+
})
47+
})
48+
})
49+
50+
// rlimitMaxNumFiles returns hard limit for RLIMIT_NOFILE
51+
func rlimitMaxNumFiles() int {
52+
var rLimit syscall.Rlimit
53+
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
54+
if err != nil {
55+
return 0
56+
}
57+
return int(rLimit.Max)
58+
}

0 commit comments

Comments
 (0)