Merge pull request #16800 from rjl493456442/memory_allowance_warining

cmd: cap cache size if exceeds reasonable range
pull/16869/merge
Péter Szilágyi 7 years ago committed by GitHub
commit ed40767355
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      cmd/geth/main.go

@ -19,12 +19,16 @@ package main
import ( import (
"fmt" "fmt"
"math"
"os" "os"
"runtime" "runtime"
godebug "runtime/debug"
"sort" "sort"
"strconv"
"strings" "strings"
"time" "time"
"github.com/elastic/gosigar"
"github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
@ -188,6 +192,22 @@ func init() {
if err := debug.Setup(ctx); err != nil { if err := debug.Setup(ctx); err != nil {
return err return err
} }
// Cap the cache allowance and tune the garbage colelctor
var mem gosigar.Mem
if err := mem.Get(); err == nil {
allowance := int(mem.Total / 1024 / 1024 / 3)
if cache := ctx.GlobalInt(utils.CacheFlag.Name); cache > allowance {
log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(allowance))
}
}
// Ensure Go's GC ignores the database cache for trigger percentage
cache := ctx.GlobalInt(utils.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))
// Start system runtime metrics collection // Start system runtime metrics collection
go metrics.CollectProcessMetrics(3 * time.Second) go metrics.CollectProcessMetrics(3 * time.Second)

Loading…
Cancel
Save