Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pebble options #322

Draft
wants to merge 2 commits into
base: optimism
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ var (
configFileFlag,
utils.LogDebugFlag,
utils.LogBacktraceAtFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)
}, utils.NetworkFlags, utils.DatabaseFlags,
utils.PebbleFlags,
)

rpcFlags = []cli.Flag{
utils.HTTPEnabledFlag,
Expand Down
5 changes: 4 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setRequiredBlocks(ctx, cfg)
setLes(ctx, cfg)

setPebbleExtraOptions(ctx, cfg)
log.Debug("Set pebble extra options", "pebble_extra_options", cfg.PebbleExtraOptions)

// Cap the cache allowance and tune the garbage collector
mem, err := gopsutil.VirtualMemory()
if err == nil {
Expand Down Expand Up @@ -1947,7 +1950,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
if rawdb.ReadCanonicalHash(chaindb, 0) != (common.Hash{}) {
cfg.Genesis = nil // fallback to db content

//validate genesis has PoS enabled in block 0
// validate genesis has PoS enabled in block 0
genesis, err := core.ReadGenesis(chaindb)
if err != nil {
Fatalf("Could not read genesis from database: %v", err)
Expand Down
176 changes: 176 additions & 0 deletions cmd/utils/pebble_extra.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
package utils

import (
"time"

"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb/pebble"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/urfave/cli/v2"
)

var (
PebbleBytesPerSyncFlag = &cli.IntFlag{
Name: "pebble.bytes-per-sync",
Category: flags.PebbleCategory,
}
PebbleL0CompactionFileThresholdFlag = &cli.IntFlag{
Name: "pebble.l0-compaction-file-threshold",
Category: flags.PebbleCategory,
}
PebbleL0CompactionThresholdFlag = &cli.IntFlag{
Name: "pebble.l0-compaction-threshold",
Category: flags.PebbleCategory,
}
PebbleL0StopWritesThresholdFlag = &cli.IntFlag{
Name: "pebble.l0-stop-writes-threshold",
Category: flags.PebbleCategory,
}
PebbleLBaseMaxBytesFlag = &cli.Int64Flag{
Name: "pebble.l-base-max-bytes",
Category: flags.PebbleCategory,
}
PebbleMemTableStopWritesThresholdFlag = &cli.IntFlag{
Name: "pebble.mem-table-stop-writes-threshold",
Category: flags.PebbleCategory,
}
PebbleMaxConcurrentCompactionsFlag = &cli.IntFlag{
Name: "pebble.max-concurrent-compactions",
Category: flags.PebbleCategory,
}
PebbleDisableAutomaticCompactionsFlag = &cli.BoolFlag{
Name: "pebble.disable-automatic-compactions",
Category: flags.PebbleCategory,
}
PebbleWALBytesPerSyncFlag = &cli.IntFlag{
Name: "pebble.wal-bytes-per-sync",
Category: flags.PebbleCategory,
}
PebbleWALDirFlag = &cli.StringFlag{
Name: "pebble.wal-dir",
Category: flags.PebbleCategory,
}
PebbleWALMinSyncIntervalFlag = &cli.DurationFlag{
Name: "pebble.wal-min-sync-interval",
Category: flags.PebbleCategory,
}
PebbleTargetByteDeletionRateFlag = &cli.IntFlag{
Name: "pebble.target-byte-deletion-rate",
Category: flags.PebbleCategory,
}

// TODO: PebbleLevelOptions

// Experimental

PebbleL0CompactionConcurrencyFlag = &cli.IntFlag{
Name: "pebble.l0-compaction-concurrency",
Category: flags.PebbleCategory,
}
PebbleCompactionDebtConcurrencyFlag = &cli.Uint64Flag{
Name: "pebble.compaction-debt-concurrency",
Category: flags.PebbleCategory,
}
PebbleReadCompactionRateFlag = &cli.Int64Flag{
Name: "pebble.read-compaction-rate",
Category: flags.PebbleCategory,
}
PebbleReadSamplingMultiplierFlag = &cli.Int64Flag{
Name: "pebble.read-sampling-multiplier",
Category: flags.PebbleCategory,
}
PebbleMaxWriterConcurrencyFlag = &cli.IntFlag{
Name: "pebble.max-writer-concurrency",
Category: flags.PebbleCategory,
}
PebbleForceWriterParallelismFlag = &cli.BoolFlag{
Name: "pebble.force-writer-parallelism",
Category: flags.PebbleCategory,
}

PebbleFlags = []cli.Flag{
PebbleBytesPerSyncFlag,
PebbleL0CompactionFileThresholdFlag,
PebbleL0CompactionThresholdFlag,
PebbleL0StopWritesThresholdFlag,
PebbleLBaseMaxBytesFlag,
PebbleMemTableStopWritesThresholdFlag,
PebbleMaxConcurrentCompactionsFlag,
PebbleDisableAutomaticCompactionsFlag,
PebbleWALBytesPerSyncFlag,
PebbleWALDirFlag,
PebbleWALMinSyncIntervalFlag,
PebbleTargetByteDeletionRateFlag,
// Experimental
PebbleL0CompactionConcurrencyFlag,
PebbleCompactionDebtConcurrencyFlag,
PebbleReadCompactionRateFlag,
PebbleReadSamplingMultiplierFlag,
PebbleMaxWriterConcurrencyFlag,
PebbleForceWriterParallelismFlag,
}
)

func setPebbleExtraOptions(ctx *cli.Context, cfg *ethconfig.Config) {
peos := new(pebble.ExtraOptions)

if flag := PebbleBytesPerSyncFlag.Name; ctx.IsSet(flag) {
peos.BytesPerSync = ctx.Int(flag)
}
if flag := PebbleL0CompactionFileThresholdFlag.Name; ctx.IsSet(flag) {
peos.L0CompactionFileThreshold = ctx.Int(flag)
}
if flag := PebbleL0CompactionThresholdFlag.Name; ctx.IsSet(flag) {
peos.L0CompactionThreshold = ctx.Int(flag)
}
if flag := PebbleL0StopWritesThresholdFlag.Name; ctx.IsSet(flag) {
peos.L0StopWritesThreshold = ctx.Int(flag)
}
if flag := PebbleLBaseMaxBytesFlag.Name; ctx.IsSet(flag) {
peos.LBaseMaxBytes = ctx.Int64(flag)
}
if flag := PebbleMemTableStopWritesThresholdFlag.Name; ctx.IsSet(flag) {
peos.MemTableStopWritesThreshold = ctx.Int(flag)
}
if flag := PebbleMaxConcurrentCompactionsFlag.Name; ctx.IsSet(flag) {
peos.MaxConcurrentCompactions = func() int { return ctx.Int(flag) }
}
if flag := PebbleDisableAutomaticCompactionsFlag.Name; ctx.IsSet(flag) {
peos.DisableAutomaticCompactions = ctx.Bool(flag)
}
if flag := PebbleWALBytesPerSyncFlag.Name; ctx.IsSet(flag) {
peos.WALBytesPerSync = ctx.Int(flag)
}
if flag := PebbleWALDirFlag.Name; ctx.IsSet(flag) {
peos.WALDir = ctx.String(flag)
}
if flag := PebbleWALMinSyncIntervalFlag.Name; ctx.IsSet(flag) {
peos.WALMinSyncInterval = func() time.Duration { return ctx.Duration(flag) }
}
if flag := PebbleTargetByteDeletionRateFlag.Name; ctx.IsSet(flag) {
peos.TargetByteDeletionRate = ctx.Int(flag)
}

// Experimental

if flag := PebbleL0CompactionConcurrencyFlag.Name; ctx.IsSet(flag) {
peos.Experimental.L0CompactionConcurrency = ctx.Int(flag)
}
if flag := PebbleCompactionDebtConcurrencyFlag.Name; ctx.IsSet(flag) {
peos.Experimental.CompactionDebtConcurrency = ctx.Uint64(flag)
}
if flag := PebbleReadCompactionRateFlag.Name; ctx.IsSet(flag) {
peos.Experimental.ReadCompactionRate = ctx.Int64(flag)
}
if flag := PebbleReadSamplingMultiplierFlag.Name; ctx.IsSet(flag) {
peos.Experimental.ReadSamplingMultiplier = ctx.Int64(flag)
}
if flag := PebbleMaxWriterConcurrencyFlag.Name; ctx.IsSet(flag) {
peos.Experimental.MaxWriterConcurrency = ctx.Int(flag)
}
if flag := PebbleForceWriterParallelismFlag.Name; ctx.IsSet(flag) {
peos.Experimental.ForceWriterParallelism = ctx.Bool(flag)
}

cfg.PebbleExtraOptions = peos
}
10 changes: 6 additions & 4 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ func NewLevelDBDatabase(file string, cache int, handles int, namespace string, r

// NewPebbleDBDatabase creates a persistent key-value database without a freezer
// moving immutable chain segments into cold storage.
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly, ephemeral bool) (ethdb.Database, error) {
db, err := pebble.New(file, cache, handles, namespace, readonly, ephemeral)
func NewPebbleDBDatabase(file string, cache int, handles int, namespace string, readonly, ephemeral bool, extraOptions *pebble.ExtraOptions) (ethdb.Database, error) {
db, err := pebble.New(file, cache, handles, namespace, readonly, ephemeral, extraOptions)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -366,6 +366,8 @@ type OpenOptions struct {
// Ephemeral means that filesystem sync operations should be avoided: data integrity in the face of
// a crash is not important. This option should typically be used in tests.
Ephemeral bool

PebbleExtraOptions *pebble.ExtraOptions
}

// openKeyValueDatabase opens a disk-based key-value database, e.g. leveldb or pebble.
Expand All @@ -387,15 +389,15 @@ func openKeyValueDatabase(o OpenOptions) (ethdb.Database, error) {
}
if o.Type == dbPebble || existingDb == dbPebble {
log.Info("Using pebble as the backing database")
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral, o.PebbleExtraOptions)
}
if o.Type == dbLeveldb || existingDb == dbLeveldb {
log.Info("Using leveldb as the backing database")
return NewLevelDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly)
}
// No pre-existing database, no user-requested one either. Default to Pebble.
log.Info("Defaulting to pebble as the backing database")
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral)
return NewPebbleDBDatabase(o.Directory, o.Cache, o.Handles, o.Namespace, o.ReadOnly, o.Ephemeral, o.PebbleExtraOptions)
}

// Open opens both a disk-based key-value database such as leveldb or pebble, but also
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
log.Info("Allocated trie memory caches", "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024)

// Assemble the Ethereum object
chainDb, err := stack.OpenDatabaseWithFreezer("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/", false)
chainDb, err := stack.OpenDatabaseWithFreezerWithExtraOptions("chaindata", config.DatabaseCache, config.DatabaseHandles, config.DatabaseFreezer, "eth/db/chaindata/", false, config.PebbleExtraOptions)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb/pebble"
"github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
)
Expand Down Expand Up @@ -178,6 +179,8 @@ type Config struct {
RollupDisableTxPoolGossip bool
RollupDisableTxPoolAdmission bool
RollupHaltOnIncompatibleProtocolVersion string

PebbleExtraOptions *pebble.ExtraOptions
}

// CreateConsensusEngine creates a consensus engine for the given chain config.
Expand Down
35 changes: 35 additions & 0 deletions ethdb/pebble/extraoptions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package pebble

import "time"

type ExtraOptions struct {
BytesPerSync int
L0CompactionFileThreshold int
L0CompactionThreshold int
L0StopWritesThreshold int
LBaseMaxBytes int64
MemTableStopWritesThreshold int
MaxConcurrentCompactions func() int
DisableAutomaticCompactions bool
WALBytesPerSync int
WALDir string
WALMinSyncInterval func() time.Duration
TargetByteDeletionRate int
Experimental ExtraOptionsExperimental
Levels []ExtraLevelOptions
}

type ExtraOptionsExperimental struct {
L0CompactionConcurrency int
CompactionDebtConcurrency uint64
ReadCompactionRate int64
ReadSamplingMultiplier int64
MaxWriterConcurrency int
ForceWriterParallelism bool
}

type ExtraLevelOptions struct {
BlockSize int
IndexBlockSize int
TargetFileSize int64
}
Loading
Loading