-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dbode] Call syscall.Setrlimit to set num files open hard limit with setcap for DB docker image #1666
[dbode] Call syscall.Setrlimit to set num files open hard limit with setcap for DB docker image #1666
Changes from 1 commit
f9c9d91
d813447
05df35e
791b151
bca7c42
0fb6110
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,15 @@ | |
package server | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
|
||
xos "github.com/m3db/m3/src/x/os" | ||
xerror "github.com/m3db/m3/src/x/errors" | ||
xos "github.com/m3db/m3/src/x/os" | ||
) | ||
|
||
const ( | ||
|
@@ -78,3 +83,75 @@ func validateProcessLimits() error { | |
|
||
return multiErr.FinalError() | ||
} | ||
|
||
func raiseRlimitToNROpen() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought: this maybe should be in a |
||
cmd := exec.Command("sysctl", "-a") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should just be able to check In kube:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah cool, yup I'll change it to this instead. |
||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_stdout_err=%v", err) | ||
} | ||
|
||
defer stdout.Close() | ||
|
||
if err := cmd.Start(); err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_start_err=%v", err) | ||
} | ||
|
||
var ( | ||
scanner = bufio.NewScanner(stdout) | ||
limit uint64 | ||
) | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if !strings.Contains(line, "nr_open") { | ||
continue | ||
} | ||
equalsIdx := strings.LastIndex(line, "=") | ||
if equalsIdx < 0 { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_parse_stdout_err=%v", err) | ||
} | ||
value := strings.TrimSpace(line[equalsIdx+1:]) | ||
n, err := strconv.Atoi(value) | ||
if err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_eval_stdout_err=%v", err) | ||
} | ||
|
||
limit = uint64(n) | ||
break | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_read_stdout_err=%v", err) | ||
} | ||
|
||
if err := cmd.Wait(); err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: sysctl_exec_err=%v", err) | ||
} | ||
|
||
var limits syscall.Rlimit | ||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: rlimit_get_err=%v", err) | ||
} | ||
|
||
if limits.Max >= limit && limits.Cur >= limit { | ||
// Limit already set correctly | ||
return nil | ||
} | ||
|
||
limits.Max = limit | ||
limits.Cur = limit | ||
|
||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limits); err != nil { | ||
return fmt.Errorf( | ||
"unable to raise nofile limits: rlimit_set_err=%v", err) | ||
} | ||
|
||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had not seen this before. Did some reading. Kind of bizarre that the capabilities get set on the file/binary level
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the
+ep
do? Can you just add a comment to this line generally alsoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not opposed to adding a comment, the +e is "effective" and +p is for "permitted".