Skip to content

Commit

Permalink
eth, cmd: allow FdLimit to be set in config/command line (ethereum#24148
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ohe committed Feb 28, 2022
1 parent 687e4dc commit c6320c9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var (
utils.CacheSnapshotFlag,
utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.FdLimitFlag,
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.CacheSnapshotFlag,
utils.CacheNoPrefetchFlag,
utils.CachePreimagesFlag,
utils.FdLimitFlag,
},
},
{
Expand Down
17 changes: 14 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@ var (
Name: "cache.preimages",
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
}
FdLimitFlag = cli.IntFlag{
Name: "fdlimit",
Usage: "Raise the open file descriptor resource limit (default = system fd limit)",
Value: math.MaxInt32,
}
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
Expand Down Expand Up @@ -1057,11 +1062,14 @@ func setLes(ctx *cli.Context, cfg *ethconfig.Config) {

// MakeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
func MakeDatabaseHandles(userFdLimit int) int {
limit, err := fdlimit.Maximum()
if err != nil {
Fatalf("Failed to retrieve file descriptor allowance: %v", err)
}
if userFdLimit < limit {
limit = userFdLimit
}
raised, err := fdlimit.Raise(uint64(limit))
if err != nil {
Fatalf("Failed to raise file descriptor allowance: %v", err)
Expand Down Expand Up @@ -1522,7 +1530,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheDatabaseFlag.Name) {
cfg.DatabaseCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
}
cfg.DatabaseHandles = MakeDatabaseHandles()
if ctx.GlobalIsSet(FdLimitFlag.Name) {
cfg.FdLimit = ctx.GlobalInt(FdLimitFlag.Name)
}
cfg.DatabaseHandles = MakeDatabaseHandles(cfg.FdLimit)
if ctx.GlobalIsSet(AncientFlag.Name) {
cfg.DatabaseFreezer = ctx.GlobalString(AncientFlag.Name)
}
Expand Down Expand Up @@ -1840,7 +1851,7 @@ func SplitTagsFlag(tagsFlag string) map[string]string {
func MakeChainDatabase(ctx *cli.Context, stack *node.Node, readonly bool) ethdb.Database {
var (
cache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheDatabaseFlag.Name) / 100
handles = MakeDatabaseHandles()
handles = MakeDatabaseHandles(ctx.GlobalInt(FdLimitFlag.Name))

err error
chainDb ethdb.Database
Expand Down
5 changes: 5 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package ethconfig

import (
"math"
"math/big"
"os"
"os/user"
Expand Down Expand Up @@ -83,6 +84,7 @@ var Defaults = Config{
TrieDirtyCache: 256,
TrieTimeout: 60 * time.Minute,
SnapshotCache: 102,
FdLimit: math.MaxInt32,
Miner: miner.Config{
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
Expand Down Expand Up @@ -169,6 +171,9 @@ type Config struct {
SnapshotCache int
Preimages bool

// FdLimit Tuning
FdLimit int

// Mining options
Miner miner.Config

Expand Down
6 changes: 6 additions & 0 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c6320c9

Please sign in to comment.