-
Notifications
You must be signed in to change notification settings - Fork 104
/
Syscall_posix.go
38 lines (31 loc) · 1.08 KB
/
Syscall_posix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build !windows
package main
import (
"syscall"
"github.com/golang/glog"
)
func IncreaseFDLimit() {
var rlm syscall.Rlimit
// Try to increase the soft limit
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlm)
if rlm.Cur < 65535 && rlm.Cur < rlm.Max {
rlm.Cur = rlm.Max
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlm)
}
// Try to increase the hard limit
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlm)
if rlm.Cur < 65535 || rlm.Max < 65535 {
rlm.Cur = 65535
rlm.Max = 65535
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlm)
}
// checking
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlm)
glog.Info("[OPTION] File descriptor limits: ", rlm.Cur, " / ", rlm.Max)
if rlm.Max < 5000 {
glog.Error("[OPTION] File descriptor hard limit is too small: ", rlm.Max, "! The problem may be solved by executing the following command before launching BTCAgent: ulimit -Hn 65535")
}
if rlm.Cur < 5000 {
glog.Error("[OPTION] File descriptor soft limit is too small: ", rlm.Cur, "! The problem may be solved by executing the following command before launching BTCAgent: ulimit -Sn 65535")
}
}