From 769901187abd2d65b606f2f4b75ee21256e9542d Mon Sep 17 00:00:00 2001 From: roneli <38083777+roneli@users.noreply.github.com> Date: Tue, 31 May 2022 19:05:14 +0300 Subject: [PATCH] feat: Return full rlimit --- helpers/limit/limits.go | 13 +++++++++---- helpers/limit/ulimit_unix.go | 4 ++-- helpers/limit/ulimit_win.go | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/helpers/limit/limits.go b/helpers/limit/limits.go index 527d67f9..d36e4991 100644 --- a/helpers/limit/limits.go +++ b/helpers/limit/limits.go @@ -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 { diff --git a/helpers/limit/ulimit_unix.go b/helpers/limit/ulimit_unix.go index 441b2872..a6548656 100644 --- a/helpers/limit/ulimit_unix.go +++ b/helpers/limit/ulimit_unix.go @@ -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 } diff --git a/helpers/limit/ulimit_win.go b/helpers/limit/ulimit_win.go index 619bffcf..bbf9279e 100644 --- a/helpers/limit/ulimit_win.go +++ b/helpers/limit/ulimit_win.go @@ -2,6 +2,6 @@ package limit -func getUlimit() (uint64, error) { - return 0, nil +func GetUlimit() (Rlimit, error) { + return Rlimit{0, 0}, nil }