mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 18:50:26 +08:00
阶段性提交
This commit is contained in:
29
internal/utils/rlimit_linux.go
Normal file
29
internal/utils/rlimit_linux.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// +build linux
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// set resource limit
|
||||
func SetRLimit(limit uint64) error {
|
||||
rLimit := &syscall.Rlimit{}
|
||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, rLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if rLimit.Cur < limit {
|
||||
rLimit.Cur = limit
|
||||
}
|
||||
if rLimit.Max < limit {
|
||||
rLimit.Max = limit
|
||||
}
|
||||
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, rLimit)
|
||||
}
|
||||
|
||||
// set best resource limit value
|
||||
func SetSuitableRLimit() {
|
||||
SetRLimit(4096 * 100) // 1M=100Files
|
||||
}
|
||||
Reference in New Issue
Block a user