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

Commit

Permalink
feat: Return full rlimit (#301)
Browse files Browse the repository at this point in the history
🎉 Thank you for making CloudQuery awesome by submitting a PR 🎉

#### Summary

Related to https://github.com/cloudquery/cloudquery-issues/issues/372 returns full access to rlimit info on process

Use the following steps to ensure your PR is ready to be reviewed

- [x] Read the [contribution guidelines](../blob/main/.github/CONTRIBUTING.md) 🧑‍🎓
- [x] Run `go fmt` to format your code 🖊
- [x] Lint your changes via `golangci-lint run` 🚨 (install golangci-lint [here](https://golangci-lint.run/usage/install/#local-installation))
- [x] Update or add tests 🧪
- [x] Ensure the status checks below are successful ✅
  • Loading branch information
roneli authored May 31, 2022
1 parent 8e83e6c commit 99b8c5e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
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
}

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
}

0 comments on commit 99b8c5e

Please sign in to comment.