Skip to content

Commit cd7cc0c

Browse files
committed
optimize gc
1 parent b393386 commit cd7cc0c

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

cmd/utils/flags.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ import (
2828
"os"
2929
"path/filepath"
3030
"runtime"
31-
godebug "runtime/debug"
3231
"strconv"
3332
"strings"
3433
"text/tabwriter"
3534
"text/template"
3635
"time"
3736

3837
pcsclite "github.com/gballet/go-libpcsclite"
39-
gopsutil "github.com/shirou/gopsutil/mem"
4038
"gopkg.in/urfave/cli.v1"
4139

4240
"github.com/scroll-tech/go-ethereum/accounts"
@@ -1784,26 +1782,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
17841782
log.Info("Shadow fork peers", "ids", cfg.ShadowForkPeerIDs)
17851783
}
17861784

1787-
// Cap the cache allowance and tune the garbage collector
1788-
mem, err := gopsutil.VirtualMemory()
1789-
if err == nil {
1790-
if 32<<(^uintptr(0)>>63) == 32 && mem.Total > 2*1024*1024*1024 {
1791-
log.Warn("Lowering memory allowance on 32bit arch", "available", mem.Total/1024/1024, "addressable", 2*1024)
1792-
mem.Total = 2 * 1024 * 1024 * 1024
1793-
}
1794-
allowance := int(mem.Total / 1024 / 1024 / 3)
1795-
if cache := ctx.GlobalInt(CacheFlag.Name); cache > allowance {
1796-
log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
1797-
ctx.GlobalSet(CacheFlag.Name, strconv.Itoa(allowance))
1798-
}
1799-
}
1800-
// Ensure Go's GC ignores the database cache for trigger percentage
1801-
cache := ctx.GlobalInt(CacheFlag.Name)
1802-
gogc := math.Max(20, math.Min(100, 100/(float64(cache)/1024)))
1803-
1804-
log.Debug("Sanitizing Go's GC trigger", "percent", int(gogc))
1805-
godebug.SetGCPercent(int(gogc))
1806-
18071785
if ctx.GlobalIsSet(SyncModeFlag.Name) {
18081786
cfg.SyncMode = *GlobalTextMarshaler(ctx, SyncModeFlag.Name).(*downloader.SyncMode)
18091787
}

internal/debug/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ func (*HandlerT) SetGCPercent(v int) int {
244244
return debug.SetGCPercent(v)
245245
}
246246

247+
// SetMemoryLimit sets the GOMEMLIMIT for the process. It returns the previous limit.
248+
func (*HandlerT) SetMemoryLimit(limit int64) int64 {
249+
return debug.SetMemoryLimit(limit)
250+
}
251+
247252
func writeProfile(name, file string) error {
248253
p := pprof.Lookup(name)
249254
log.Info("Writing profile records", "count", p.Count(), "type", name, "dump", file)

internal/web3ext/web3ext.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ web3._extend({
308308
call: 'debug_setGCPercent',
309309
params: 1,
310310
}),
311+
new web3._extend.Method({
312+
name: 'SetMemoryLimit',
313+
call: 'debug_SetMemoryLimit',
314+
params: 1,
315+
}),
311316
new web3._extend.Method({
312317
name: 'memStats',
313318
call: 'debug_memStats',

0 commit comments

Comments
 (0)