mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
common/fdlimit: Remove FdLimit from functions signature
This commit is contained in:
parent
ac3a0de829
commit
f8c02cad2f
5 changed files with 26 additions and 26 deletions
|
|
@ -722,10 +722,10 @@ func setIPC(ctx *cli.Context, cfg *node.Config) {
|
||||||
// makeDatabaseHandles raises out the number of allowed file handles per process
|
// makeDatabaseHandles raises out the number of allowed file handles per process
|
||||||
// for Geth and returns half of the allowance to assign to the database.
|
// for Geth and returns half of the allowance to assign to the database.
|
||||||
func makeDatabaseHandles() int {
|
func makeDatabaseHandles() int {
|
||||||
if err := fdlimit.RaiseFdLimit(2048); err != nil {
|
if err := fdlimit.Raise(2048); err != nil {
|
||||||
Fatalf("Failed to raise file descriptor allowance: %v", err)
|
Fatalf("Failed to raise file descriptor allowance: %v", err)
|
||||||
}
|
}
|
||||||
limit, err := fdlimit.GetFdLimit()
|
limit, err := fdlimit.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Failed to retrieve file descriptor allowance: %v", err)
|
Fatalf("Failed to retrieve file descriptor allowance: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@ import "syscall"
|
||||||
// but Rlimit fields have type int64 on FreeBSD so it needs
|
// but Rlimit fields have type int64 on FreeBSD so it needs
|
||||||
// an extra conversion.
|
// an extra conversion.
|
||||||
|
|
||||||
// RaiseFdLimit tries to maximize the file descriptor allowance of this process
|
// Raise tries to maximize the file descriptor allowance of this process
|
||||||
// to the maximum hard-limit allowed by the OS.
|
// to the maximum hard-limit allowed by the OS.
|
||||||
func RaiseFdLimit(max uint64) error {
|
func Raise(max uint64) error {
|
||||||
// Get the current limit
|
// Get the current limit
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
|
|
@ -43,9 +43,9 @@ func RaiseFdLimit(max uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdLimit retrieves the number of file descriptors allowed to be opened by this
|
// Get retrieves the number of file descriptors allowed to be opened by this
|
||||||
// process.
|
// process.
|
||||||
func GetFdLimit() (int, error) {
|
func Get() (int, error) {
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
@ -53,9 +53,9 @@ func GetFdLimit() (int, error) {
|
||||||
return int(limit.Cur), nil
|
return int(limit.Cur), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdMaxLimit retrieves the maximum number of file descriptors this process is
|
// GetMax retrieves the maximum number of file descriptors this process is
|
||||||
// allowed to request for itself.
|
// allowed to request for itself.
|
||||||
func GetFdMaxLimit() (int, error) {
|
func GetMax() (int, error) {
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import (
|
||||||
// per this process can be retrieved.
|
// per this process can be retrieved.
|
||||||
func TestFileDescriptorLimits(t *testing.T) {
|
func TestFileDescriptorLimits(t *testing.T) {
|
||||||
target := 4096
|
target := 4096
|
||||||
hardlimit, err := GetFdMaxLimit()
|
hardlimit, err := GetMax()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
@ -33,13 +33,13 @@ func TestFileDescriptorLimits(t *testing.T) {
|
||||||
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
|
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
|
||||||
}
|
}
|
||||||
|
|
||||||
if limit, err := GetFdLimit(); err != nil || limit <= 0 {
|
if limit, err := Get(); err != nil || limit <= 0 {
|
||||||
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
|
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
|
||||||
}
|
}
|
||||||
if err := RaiseFdLimit(uint64(target)); err != nil {
|
if err := Raise(uint64(target)); err != nil {
|
||||||
t.Fatalf("failed to raise file allowance")
|
t.Fatalf("failed to raise file allowance")
|
||||||
}
|
}
|
||||||
if limit, err := GetFdLimit(); err != nil || limit < target {
|
if limit, err := Get(); err != nil || limit < target {
|
||||||
t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
|
t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ package fdlimit
|
||||||
|
|
||||||
import "syscall"
|
import "syscall"
|
||||||
|
|
||||||
// RaiseFdLimit tries to maximize the file descriptor allowance of this process
|
// Raise tries to maximize the file descriptor allowance of this process
|
||||||
// to the maximum hard-limit allowed by the OS.
|
// to the maximum hard-limit allowed by the OS.
|
||||||
func RaiseFdLimit(max uint64) error {
|
func Raise(max uint64) error {
|
||||||
// Get the current limit
|
// Get the current limit
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
|
|
@ -39,9 +39,9 @@ func RaiseFdLimit(max uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdLimit retrieves the number of file descriptors allowed to be opened by this
|
// Get retrieves the number of file descriptors allowed to be opened by this
|
||||||
// process.
|
// process.
|
||||||
func GetFdLimit() (int, error) {
|
func Get() (int, error) {
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
@ -49,9 +49,9 @@ func GetFdLimit() (int, error) {
|
||||||
return int(limit.Cur), nil
|
return int(limit.Cur), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdMaxLimit retrieves the maximum number of file descriptors this process is
|
// GetMax retrieves the maximum number of file descriptors this process is
|
||||||
// allowed to request for itself.
|
// allowed to request for itself.
|
||||||
func GetFdMaxLimit() (int, error) {
|
func GetMax() (int, error) {
|
||||||
var limit syscall.Rlimit
|
var limit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,9 @@ package fdlimit
|
||||||
|
|
||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
// RaiseFdLimit tries to maximize the file descriptor allowance of this process
|
// Raise tries to maximize the file descriptor allowance of this process
|
||||||
// to the maximum hard-limit allowed by the OS.
|
// to the maximum hard-limit allowed by the OS.
|
||||||
func RaiseFdLimit(max uint64) error {
|
func Raise(max uint64) error {
|
||||||
// This method is NOP by design:
|
// This method is NOP by design:
|
||||||
// * Linux/Darwin counterparts need to manually increase per process limits
|
// * Linux/Darwin counterparts need to manually increase per process limits
|
||||||
// * On Windows Go uses the CreateFile API, which is limited to 16K files, non
|
// * On Windows Go uses the CreateFile API, which is limited to 16K files, non
|
||||||
|
|
@ -33,15 +33,15 @@ func RaiseFdLimit(max uint64) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdLimit retrieves the number of file descriptors allowed to be opened by this
|
// Get retrieves the number of file descriptors allowed to be opened by this
|
||||||
// process.
|
// process.
|
||||||
func GetFdLimit() (int, error) {
|
func Get() (int, error) {
|
||||||
// Please see RaiseFdLimit for the reason why we use hard coded 16K as the limit
|
// Please see Raise for the reason why we use hard coded 16K as the limit
|
||||||
return 16384, nil
|
return 16384, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFdMaxLimit retrieves the maximum number of file descriptors this process is
|
// GetMax retrieves the maximum number of file descriptors this process is
|
||||||
// allowed to request for itself.
|
// allowed to request for itself.
|
||||||
func GetFdMaxLimit() (int, error) {
|
func GetMax() (int, error) {
|
||||||
return GetFdLimit()
|
return Get()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue