Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise Soft File Descriptor Limit Up To The Hard Limit #10650

Merged
merged 17 commits into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/beacon-chain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ go_library(
"//io/logs:go_default_library",
"//monitoring/journald:go_default_library",
"//runtime/debug:go_default_library",
"//runtime/fdlimits:go_default_library",
"//runtime/maxprocs:go_default_library",
"//runtime/tos:go_default_library",
"//runtime/version:go_default_library",
Expand Down
4 changes: 4 additions & 0 deletions cmd/beacon-chain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/prysmaticlabs/prysm/io/logs"
"github.com/prysmaticlabs/prysm/monitoring/journald"
"github.com/prysmaticlabs/prysm/runtime/debug"
"github.com/prysmaticlabs/prysm/runtime/fdlimits"
_ "github.com/prysmaticlabs/prysm/runtime/maxprocs"
"github.com/prysmaticlabs/prysm/runtime/tos"
"github.com/prysmaticlabs/prysm/runtime/version"
Expand Down Expand Up @@ -193,6 +194,9 @@ func main() {
if err := debug.Setup(ctx); err != nil {
return err
}
if err := fdlimits.SetMaxFdLimits(); err != nil {
return err
}
return cmd.ValidateNoArgs(ctx)
}

Expand Down
22 changes: 22 additions & 0 deletions runtime/fdlimits/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@prysm//tools/go:def.bzl", "go_library", "go_test")

go_library(
name = "go_default_library",
srcs = ["fdlimits.go"],
importpath = "github.com/prysmaticlabs/prysm/runtime/fdlimits",
visibility = ["//visibility:public"],
deps = [
"@com_github_ethereum_go_ethereum//common/fdlimit:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

go_test(
name = "go_default_test",
srcs = ["fdlimits_test.go"],
deps = [
":go_default_library",
"//testing/assert:go_default_library",
"@com_github_ethereum_go_ethereum//common/fdlimit:go_default_library",
],
)
25 changes: 25 additions & 0 deletions runtime/fdlimits/fdlimits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package fdlimits

import (
"github.com/ethereum/go-ethereum/common/fdlimit"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no downside to doing this by default, so 👍. I looked at the go-ethereum lib because I was curious why we were adding this dependency on them. It looks like the benefit here is that they have the major os-specific variants set up with appropriate build tags, so that we can have this simple Raise(Maximum()) code (including eg Windows where the raise is a no-op). seems fine.

log "github.com/sirupsen/logrus"
)

// SetMaxFdLimits is a wrapper around a few go-ethereum methods to allow prysm to
// set its file descriptor limits at the maximum possible value.
func SetMaxFdLimits() error {
curr, err := fdlimit.Current()
if err != nil {
return err
}
max, err := fdlimit.Maximum()
if err != nil {
return err
}
raisedVal, err := fdlimit.Raise(uint64(max))
if err != nil {
return err
}
log.Infof("Raised fd limit to %d from %d", raisedVal, curr)
return nil
}
22 changes: 22 additions & 0 deletions runtime/fdlimits/fdlimits_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fdlimits_test

import (
"testing"

gethLimit "github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/prysmaticlabs/prysm/runtime/fdlimits"
"github.com/prysmaticlabs/prysm/testing/assert"
)

func TestSetMaxFdLimits(t *testing.T) {
assert.NoError(t, fdlimits.SetMaxFdLimits())

curr, err := gethLimit.Current()
assert.NoError(t, err)

max, err := gethLimit.Maximum()
assert.NoError(t, err)

assert.Equal(t, max, curr, "current and maximum file descriptor limits do not match up.")

}