Implement bench-cache
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
edf1875e88
commit
96193c2044
33
cmd/lotus-bench/caching_verifier.go
Normal file
33
cmd/lotus-bench/caching_verifier.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
|
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/runtime/proof"
|
||||||
|
"github.com/ipfs/go-datastore"
|
||||||
|
)
|
||||||
|
|
||||||
|
type cachingVerifier struct {
|
||||||
|
ds datastore.Datastore
|
||||||
|
backend ffiwrapper.Verifier
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cv *cachingVerifier) VerifySeal(svi proof.SealVerifyInfo) (bool, error) {
|
||||||
|
svi.MarshalCBOR(nil)
|
||||||
|
return cv.backend.VerifySeal(svi)
|
||||||
|
}
|
||||||
|
func (cv *cachingVerifier) VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) {
|
||||||
|
info.MarshalCBOR(nil)
|
||||||
|
return cv.backend.VerifyWinningPoSt(ctx, info)
|
||||||
|
}
|
||||||
|
func (cv *cachingVerifier) VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) {
|
||||||
|
info.MarshalCBOR(nil)
|
||||||
|
return cv.backend.VerifyWindowPoSt(ctx, info)
|
||||||
|
}
|
||||||
|
func (cv *cachingVerifier) GenerateWinningPoStSectorChallenge(ctx context.Context, proofType abi.RegisteredPoStProof, a abi.ActorID, rnd abi.PoStRandomness, u uint64) ([]uint64, error) {
|
||||||
|
return cv.backend.GenerateWinningPoStSectorChallenge(ctx, proofType, a, rnd, u)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ ffiwrapper.Verifier = (*cachingVerifier)(nil)
|
@ -60,6 +60,15 @@ var importBenchCmd = &cli.Command{
|
|||||||
Name: "repodir",
|
Name: "repodir",
|
||||||
Usage: "set the repo directory for the lotus bench run (defaults to /tmp)",
|
Usage: "set the repo directory for the lotus bench run (defaults to /tmp)",
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "syscall-cache",
|
||||||
|
Usage: "read and write syscall results from datastore",
|
||||||
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "export-traces",
|
||||||
|
Usage: "should we export execution traces",
|
||||||
|
Value: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
vm.BatchSealVerifyParallelism = cctx.Int("batch-seal-verify-threads")
|
vm.BatchSealVerifyParallelism = cctx.Int("batch-seal-verify-threads")
|
||||||
@ -85,7 +94,10 @@ var importBenchCmd = &cli.Command{
|
|||||||
tdir = tmp
|
tdir = tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
bds, err := badger.NewDatastore(tdir, nil)
|
bdgOpt := badger.DefaultOptions
|
||||||
|
bdgOpt.GcInterval = 0
|
||||||
|
|
||||||
|
bds, err := badger.NewDatastore(tdir, &bdgOpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -96,7 +108,21 @@ var importBenchCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
bs = cbs
|
bs = cbs
|
||||||
ds := datastore.NewMapDatastore()
|
ds := datastore.NewMapDatastore()
|
||||||
cs := store.NewChainStore(bs, ds, vm.Syscalls(ffiwrapper.ProofVerifier))
|
|
||||||
|
var verifier ffiwrapper.Verifier = ffiwrapper.ProofVerifier
|
||||||
|
if cctx.IsSet("syscall-cache") {
|
||||||
|
|
||||||
|
scds, err := badger.NewDatastore(cctx.String("syscall-cache"), &bdgOpt)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("opening syscall-cache datastore: %w", err)
|
||||||
|
}
|
||||||
|
verifier = &cachingVerifier{
|
||||||
|
ds: scds,
|
||||||
|
backend: verifier,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cs := store.NewChainStore(bs, ds, vm.Syscalls(verifier))
|
||||||
stm := stmgr.NewStateManager(cs)
|
stm := stmgr.NewStateManager(cs)
|
||||||
|
|
||||||
prof, err := os.Create("import-bench.prof")
|
prof, err := os.Create("import-bench.prof")
|
||||||
@ -144,13 +170,16 @@ var importBenchCmd = &cli.Command{
|
|||||||
ts = next
|
ts = next
|
||||||
}
|
}
|
||||||
|
|
||||||
ibj, err := os.Create("import-bench.json")
|
var enc *json.Encoder
|
||||||
if err != nil {
|
if cctx.Bool("export-traces") {
|
||||||
return err
|
ibj, err := os.Create("import-bench.json")
|
||||||
}
|
if err != nil {
|
||||||
defer ibj.Close() //nolint:errcheck
|
return err
|
||||||
|
}
|
||||||
|
defer ibj.Close() //nolint:errcheck
|
||||||
|
|
||||||
enc := json.NewEncoder(ibj)
|
enc = json.NewEncoder(ibj)
|
||||||
|
}
|
||||||
|
|
||||||
var lastTse *TipSetExec
|
var lastTse *TipSetExec
|
||||||
|
|
||||||
@ -173,17 +202,19 @@ var importBenchCmd = &cli.Command{
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stripCallers(trace)
|
if enc != nil {
|
||||||
|
stripCallers(trace)
|
||||||
|
|
||||||
lastTse = &TipSetExec{
|
lastTse = &TipSetExec{
|
||||||
TipSet: cur.Key(),
|
TipSet: cur.Key(),
|
||||||
Trace: trace,
|
Trace: trace,
|
||||||
Duration: time.Since(start),
|
Duration: time.Since(start),
|
||||||
|
}
|
||||||
|
if err := enc.Encode(lastTse); err != nil {
|
||||||
|
return xerrors.Errorf("failed to write out tipsetexec: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lastState = st
|
lastState = st
|
||||||
if err := enc.Encode(lastTse); err != nil {
|
|
||||||
return xerrors.Errorf("failed to write out tipsetexec: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pprof.StopCPUProfile()
|
pprof.StopCPUProfile()
|
||||||
|
Loading…
Reference in New Issue
Block a user