mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
cmd: add gogc flag (#35363)
This PR adds the CLI flag gogc for twisting the garbage collection target. The default value is chosen as the 50, balancing the performance gain and potential memory peak.
This commit is contained in:
parent
a9ca080d7f
commit
c767f825c5
2 changed files with 24 additions and 3 deletions
|
|
@ -103,6 +103,7 @@ var (
|
||||||
utils.CacheLogSizeFlag,
|
utils.CacheLogSizeFlag,
|
||||||
utils.FDLimitFlag,
|
utils.FDLimitFlag,
|
||||||
utils.MemoryLimitFlag,
|
utils.MemoryLimitFlag,
|
||||||
|
utils.GOGCFlag,
|
||||||
utils.CryptoKZGFlag,
|
utils.CryptoKZGFlag,
|
||||||
utils.ListenPortFlag,
|
utils.ListenPortFlag,
|
||||||
utils.DiscoveryPortFlag,
|
utils.DiscoveryPortFlag,
|
||||||
|
|
|
||||||
|
|
@ -566,6 +566,12 @@ var (
|
||||||
Usage: "Soft memory limit for the Go runtime in megabytes (default = no limit)",
|
Usage: "Soft memory limit for the Go runtime in megabytes (default = no limit)",
|
||||||
Category: flags.PerfCategory,
|
Category: flags.PerfCategory,
|
||||||
}
|
}
|
||||||
|
GOGCFlag = &cli.IntFlag{
|
||||||
|
Name: "gogc",
|
||||||
|
Usage: "Go garbage collection target percentage (default = 50, negative disables)",
|
||||||
|
Value: 50,
|
||||||
|
Category: flags.PerfCategory,
|
||||||
|
}
|
||||||
CryptoKZGFlag = &cli.StringFlag{
|
CryptoKZGFlag = &cli.StringFlag{
|
||||||
Name: "crypto.kzg",
|
Name: "crypto.kzg",
|
||||||
Usage: "KZG library implementation to use; gokzg (recommended) or ckzg",
|
Usage: "KZG library implementation to use; gokzg (recommended) or ckzg",
|
||||||
|
|
@ -1778,11 +1784,25 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
godebug.SetGCPercent(100)
|
// Setting go runtime settings
|
||||||
|
gcPercent := ctx.Int(GOGCFlag.Name)
|
||||||
|
if ctx.IsSet(GOGCFlag.Name) {
|
||||||
|
log.Info("Sanitizing Go's GC trigger", "percent", gcPercent)
|
||||||
|
}
|
||||||
|
godebug.SetGCPercent(gcPercent)
|
||||||
|
|
||||||
if ctx.IsSet(MemoryLimitFlag.Name) {
|
if ctx.IsSet(MemoryLimitFlag.Name) {
|
||||||
memLimit := int64(ctx.Int(MemoryLimitFlag.Name)) * 1024 * 1024
|
memLimit := int64(ctx.Int(MemoryLimitFlag.Name)) * 1024 * 1024
|
||||||
log.Debug("Setting Go memory limit", "MB", memLimit/1024/1024)
|
if memLimit > int64(total) {
|
||||||
godebug.SetMemoryLimit(memLimit)
|
log.Info("Sanitizing memory limit", "provided(MB)", memLimit/1024/1024, "updated(MB)", total/1024/1024)
|
||||||
|
memLimit = int64(total)
|
||||||
|
}
|
||||||
|
if memLimit < 0 {
|
||||||
|
log.Warn("Ignoring negative Go memory limit")
|
||||||
|
} else {
|
||||||
|
log.Info("Setting Go memory limit", "MB", memLimit/1024/1024)
|
||||||
|
godebug.SetMemoryLimit(memLimit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(SyncTargetFlag.Name) {
|
if ctx.IsSet(SyncTargetFlag.Name) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue