lotus-bench: add support for native badger blockstore.

This commit is contained in:
Raúl Kripalani 2020-11-01 18:54:35 +00:00
parent c2355b18f9
commit aece624d1c

View File

@ -24,8 +24,11 @@ import (
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/lib/blockstore" "github.com/filecoin-project/lotus/lib/blockstore"
badgerbs "github.com/filecoin-project/lotus/lib/blockstore/badger"
_ "github.com/filecoin-project/lotus/lib/sigs/bls" _ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp" _ "github.com/filecoin-project/lotus/lib/sigs/secp"
"github.com/filecoin-project/lotus/node/repo"
metricsprometheus "github.com/ipfs/go-metrics-prometheus" metricsprometheus "github.com/ipfs/go-metrics-prometheus"
"github.com/ipld/go-car" "github.com/ipld/go-car"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
@ -95,6 +98,9 @@ var importBenchCmd = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "use-pebble", Name: "use-pebble",
}, },
&cli.BoolFlag{
Name: "use-native-badger",
},
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
metricsprometheus.Inject() //nolint:errcheck metricsprometheus.Inject() //nolint:errcheck
@ -126,17 +132,16 @@ var importBenchCmd = &cli.Command{
tdir = tmp tdir = tmp
} }
bdgOpt := badger.DefaultOptions var (
bdgOpt.GcInterval = 0 ds datastore.Batching
bdgOpt.Options = bdg.DefaultOptions("") bs blockstore.Blockstore
bdgOpt.Options.SyncWrites = false )
bdgOpt.Options.Truncate = true
bdgOpt.Options.DetectConflicts = false
var bds datastore.Batching switch {
if cctx.Bool("use-pebble") { case cctx.Bool("use-pebble"):
cache := 512 cache := 512
bds, err = pebbleds.NewDatastore(tdir, &pebble.Options{
ds, err = pebbleds.NewDatastore(tdir, &pebble.Options{
// Pebble has a single combined cache area and the write // Pebble has a single combined cache area and the write
// buffers are taken from this too. Assign all available // buffers are taken from this too. Assign all available
// memory allowance for cache. // memory allowance for cache.
@ -155,13 +160,38 @@ var importBenchCmd = &cli.Command{
}, },
Logger: log, Logger: log,
}) })
} else {
bds, err = badger.NewDatastore(tdir, &bdgOpt) case cctx.Bool("use-native-badger"):
opts, err := repo.BadgerBlockstoreOptions(repo.BlockstoreChain, tdir, false)
if err != nil {
return err
}
bs, err = badgerbs.Open(opts)
default: // legacy badger via datastore.
bdgOpt := badger.DefaultOptions
bdgOpt.GcInterval = 0
bdgOpt.Options = bdg.DefaultOptions("")
bdgOpt.Options.SyncWrites = false
bdgOpt.Options.Truncate = true
bdgOpt.Options.DetectConflicts = false
ds, err = badger.NewDatastore(tdir, &bdgOpt)
} }
if err != nil { if err != nil {
return err return err
} }
defer bds.Close() //nolint:errcheck
if ds != nil {
ds = measure.New("dsbench", ds)
defer ds.Close() //nolint:errcheck
bs = blockstore.NewBlockstore(ds)
}
if c, ok := bs.(io.Closer); ok {
defer c.Close() //nolint:errcheck
}
start := time.Now().Format(time.RFC3339) start := time.Now().Format(time.RFC3339)
defer func() { defer func() {
@ -182,22 +212,16 @@ var importBenchCmd = &cli.Command{
writeProfile("allocs") writeProfile("allocs")
}() }()
bds = measure.New("dsbench", bds)
bs := blockstore.NewBlockstore(bds)
cacheOpts := blockstore.DefaultCacheOpts() cacheOpts := blockstore.DefaultCacheOpts()
cacheOpts.HasBloomFilterSize = 0 cacheOpts.HasBloomFilterSize = 0
bs, err = blockstore.CachedBlockstore(context.TODO(), bs, cacheOpts)
cbs, err := blockstore.CachedBlockstore(context.TODO(), bs, cacheOpts)
if err != nil { if err != nil {
return err return err
} }
bs = cbs
ds := datastore.NewMapDatastore()
var verifier ffiwrapper.Verifier = ffiwrapper.ProofVerifier var verifier ffiwrapper.Verifier = ffiwrapper.ProofVerifier
if cctx.IsSet("syscall-cache") { if cctx.IsSet("syscall-cache") {
scds, err := badger.NewDatastore(cctx.String("syscall-cache"), &bdgOpt) scds, err := badger.NewDatastore(cctx.String("syscall-cache"), &badger.DefaultOptions)
if err != nil { if err != nil {
return xerrors.Errorf("opening syscall-cache datastore: %w", err) return xerrors.Errorf("opening syscall-cache datastore: %w", err)
} }
@ -212,7 +236,8 @@ var importBenchCmd = &cli.Command{
return nil return nil
} }
cs := store.NewChainStore(bs, ds, vm.Syscalls(verifier), nil) metadataDs := datastore.NewMapDatastore()
cs := store.NewChainStore(bs, metadataDs, vm.Syscalls(verifier), nil)
stm := stmgr.NewStateManager(cs) stm := stmgr.NewStateManager(cs)
if cctx.Bool("global-profile") { if cctx.Bool("global-profile") {
@ -283,6 +308,9 @@ var importBenchCmd = &cli.Command{
ts := head ts := head
tschain := []*types.TipSet{ts} tschain := []*types.TipSet{ts}
for ts.Height() > startEpoch { for ts.Height() > startEpoch {
if h := ts.Height(); h%100 == 0 {
log.Info("walking back the chain; loaded tipset at height %d...", h)
}
next, err := cs.LoadTipSet(ts.Parents()) next, err := cs.LoadTipSet(ts.Parents())
if err != nil { if err != nil {
return err return err