mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
improve golang gc performance
This commit is contained in:
parent
80b8d7a13c
commit
a4afb37d2d
3 changed files with 12 additions and 26 deletions
|
|
@ -24,13 +24,11 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
godebug "runtime/debug"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -76,7 +74,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/triedb/hashdb"
|
"github.com/ethereum/go-ethereum/triedb/hashdb"
|
||||||
"github.com/ethereum/go-ethereum/triedb/pathdb"
|
"github.com/ethereum/go-ethereum/triedb/pathdb"
|
||||||
pcsclite "github.com/gballet/go-libpcsclite"
|
pcsclite "github.com/gballet/go-libpcsclite"
|
||||||
gopsutil "github.com/shirou/gopsutil/mem"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -494,7 +491,6 @@ var (
|
||||||
Value: "gokzg",
|
Value: "gokzg",
|
||||||
Category: flags.PerfCategory,
|
Category: flags.PerfCategory,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Miner settings
|
// Miner settings
|
||||||
MinerGasLimitFlag = &cli.Uint64Flag{
|
MinerGasLimitFlag = &cli.Uint64Flag{
|
||||||
Name: "miner.gaslimit",
|
Name: "miner.gaslimit",
|
||||||
|
|
@ -1579,38 +1575,18 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
setRequiredBlocks(ctx, cfg)
|
setRequiredBlocks(ctx, cfg)
|
||||||
setLes(ctx, cfg)
|
setLes(ctx, cfg)
|
||||||
|
|
||||||
// Cap the cache allowance and tune the garbage collector
|
|
||||||
mem, err := gopsutil.VirtualMemory()
|
|
||||||
if err == nil {
|
|
||||||
if 32<<(^uintptr(0)>>63) == 32 && mem.Total > 2*1024*1024*1024 {
|
|
||||||
log.Warn("Lowering memory allowance on 32bit arch", "available", mem.Total/1024/1024, "addressable", 2*1024)
|
|
||||||
mem.Total = 2 * 1024 * 1024 * 1024
|
|
||||||
}
|
|
||||||
allowance := int(mem.Total / 1024 / 1024 / 3)
|
|
||||||
if cache := ctx.Int(CacheFlag.Name); cache > allowance {
|
|
||||||
log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
|
|
||||||
ctx.Set(CacheFlag.Name, strconv.Itoa(allowance))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Ensure Go's GC ignores the database cache for trigger percentage
|
|
||||||
cache := ctx.Int(CacheFlag.Name)
|
|
||||||
gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024)))
|
|
||||||
|
|
||||||
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
|
|
||||||
godebug.SetGCPercent(int(gogc))
|
|
||||||
|
|
||||||
if ctx.IsSet(SyncTargetFlag.Name) {
|
if ctx.IsSet(SyncTargetFlag.Name) {
|
||||||
cfg.SyncMode = ethconfig.FullSync // dev sync target forces full sync
|
cfg.SyncMode = ethconfig.FullSync // dev sync target forces full sync
|
||||||
} else if ctx.IsSet(SyncModeFlag.Name) {
|
} else if ctx.IsSet(SyncModeFlag.Name) {
|
||||||
value := ctx.String(SyncModeFlag.Name)
|
value := ctx.String(SyncModeFlag.Name)
|
||||||
if err = cfg.SyncMode.UnmarshalText([]byte(value)); err != nil {
|
if err := cfg.SyncMode.UnmarshalText([]byte(value)); err != nil {
|
||||||
Fatalf("--%v: %v", SyncModeFlag.Name, err)
|
Fatalf("--%v: %v", SyncModeFlag.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.IsSet(ChainHistoryFlag.Name) {
|
if ctx.IsSet(ChainHistoryFlag.Name) {
|
||||||
value := ctx.String(ChainHistoryFlag.Name)
|
value := ctx.String(ChainHistoryFlag.Name)
|
||||||
if err = cfg.HistoryMode.UnmarshalText([]byte(value)); err != nil {
|
if err := cfg.HistoryMode.UnmarshalText([]byte(value)); err != nil {
|
||||||
Fatalf("--%s: %v", ChainHistoryFlag.Name, err)
|
Fatalf("--%s: %v", ChainHistoryFlag.Name, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,11 @@ func (*HandlerT) SetGCPercent(v int) int {
|
||||||
return debug.SetGCPercent(v)
|
return debug.SetGCPercent(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMemoryLimit sets the GOMEMLIMIT for the process. It returns the previous limit.
|
||||||
|
func (*HandlerT) SetMemoryLimit(limit int64) int64 {
|
||||||
|
return debug.SetMemoryLimit(limit)
|
||||||
|
}
|
||||||
|
|
||||||
func writeProfile(name, file string) error {
|
func writeProfile(name, file string) error {
|
||||||
p := pprof.Lookup(name)
|
p := pprof.Lookup(name)
|
||||||
log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file)
|
log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file)
|
||||||
|
|
|
||||||
|
|
@ -269,6 +269,11 @@ web3._extend({
|
||||||
call: 'debug_setGCPercent',
|
call: 'debug_setGCPercent',
|
||||||
params: 1,
|
params: 1,
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'setMemoryLimit',
|
||||||
|
call: 'debug_setMemoryLimit',
|
||||||
|
params: 1,
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'memStats',
|
name: 'memStats',
|
||||||
call: 'debug_memStats',
|
call: 'debug_memStats',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue