Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

feat: Return full rlimit #301

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions helpers/limit/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ const (
goroutinesPerGB float64 = 250000
)

type Rlimit struct {
Cur uint64
Max uint64
}

func GetMaxGoRoutines() uint64 {
limit := calculateGoRoutines(getMemory())
ulimit, err := getUlimit()
if err != nil || ulimit == 0 {
ulimit, err := GetUlimit()
if err != nil || ulimit.Max == 0 {
return limit
}
if ulimit > limit {
if ulimit.Max > limit {
return limit
}
return ulimit
return ulimit.Max
Comment on lines +20 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a seperate/ related note, instead of going all the way up to the ulimit why not do something like ulimit * 0.8 So then we don't try and take all of the descriptors because we know there are other things that use file descriptors other than our go routines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do that, will do in a separate pr

}

func getMemory() uint64 {
Expand Down
4 changes: 2 additions & 2 deletions helpers/limit/ulimit_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"syscall"
)

func getUlimit() (uint64, error) {
func GetUlimit() (Rlimit, error) {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
return rLimit.Max, err
return Rlimit{rLimit.Cur, rLimit.Max}, err
}
4 changes: 2 additions & 2 deletions helpers/limit/ulimit_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

package limit

func getUlimit() (uint64, error) {
return 0, nil
func GetUlimit() (Rlimit, error) {
return Rlimit{0, 0}, nil
}