aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/geth
diff options
context:
space:
mode:
authorrjl493456442 <garyrong0905@gmail.com>2018-05-25 15:48:16 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-06-04 18:46:39 +0800
commita20cc75b4a2982917db83370cadd40e26d1b35b6 (patch)
treed3f9c30196b0a4d4bb0d4f9c624dfb286867b250 /cmd/geth
parentb659718fd0aa19c6b5977eb22cd58449bbb824a0 (diff)
downloaddexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar.gz
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar.bz2
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar.lz
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar.xz
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.tar.zst
dexon-a20cc75b4a2982917db83370cadd40e26d1b35b6.zip
cmd/geth: cap cache allowance
Diffstat (limited to 'cmd/geth')
-rw-r--r--cmd/geth/main.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 09d9c493d..edf2a557a 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -19,12 +19,16 @@ package main
import (
"fmt"
+ "math"
"os"
"runtime"
+ godebug "runtime/debug"
"sort"
+ "strconv"
"strings"
"time"
+ "github.com/elastic/gosigar"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
@@ -188,6 +192,22 @@ func init() {
if err := debug.Setup(ctx); err != nil {
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
go metrics.CollectProcessMetrics(3 * time.Second)