Skip to content

Commit

Permalink
Adjust rlimit logic
Browse files Browse the repository at this point in the history
Closes #5821
  • Loading branch information
bep committed Apr 6, 2019
1 parent ed65bda commit 708d4ce
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions commands/limit_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ This is primarily to ensure that Hugo can watch enough files on some OSs`,
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return newSystemError("Error Getting Rlimit ", err)
return newSystemError("Error Getting rlimit ", err)
}

jww.FEEDBACK.Println("Current rLimit:", rLimit)

if rLimit.Cur >= newRlimit {
return nil
}

jww.FEEDBACK.Println("Attempting to increase limit")
rLimit.Max = 999999
rLimit.Cur = 999999
rLimit.Cur = newRlimit
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
return newSystemError("Error Setting rLimit ", err)
Expand All @@ -61,18 +64,21 @@ This is primarily to ensure that Hugo can watch enough files on some OSs`,
return &limitCmd{baseCmd: newBaseCmd(ccmd)}
}

const newRlimit = 10240

func tweakLimit() {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
jww.ERROR.Println("Unable to obtain rLimit", err)
jww.WARN.Println("Unable to get rlimit:", err)
return
}
if rLimit.Cur < rLimit.Max {
rLimit.Max = 64000
rLimit.Cur = 64000
if rLimit.Cur < newRlimit {
rLimit.Cur = newRlimit
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
if err != nil {
jww.WARN.Println("Unable to increase number of open files limit", err)
// This may not succeed, see https://github.com/golang/go/issues/30401
jww.INFO.Println("Unable to increase number of open files limit:", err)
}
}
}

0 comments on commit 708d4ce

Please sign in to comment.