Implement bench-cache

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-09-16 16:34:54 +02:00
parent edf1875e88
commit 96193c2044
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
2 changed files with 80 additions and 16 deletions

View 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)

View File

@ -60,6 +60,15 @@ var importBenchCmd = &cli.Command{
Name: "repodir",
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 {
vm.BatchSealVerifyParallelism = cctx.Int("batch-seal-verify-threads")
@ -85,7 +94,10 @@ var importBenchCmd = &cli.Command{
tdir = tmp
}
bds, err := badger.NewDatastore(tdir, nil)
bdgOpt := badger.DefaultOptions
bdgOpt.GcInterval = 0
bds, err := badger.NewDatastore(tdir, &bdgOpt)
if err != nil {
return err
}
@ -96,7 +108,21 @@ var importBenchCmd = &cli.Command{
}
bs = cbs
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)
prof, err := os.Create("import-bench.prof")
@ -144,13 +170,16 @@ var importBenchCmd = &cli.Command{
ts = next
}
ibj, err := os.Create("import-bench.json")
if err != nil {
return err
}
defer ibj.Close() //nolint:errcheck
var enc *json.Encoder
if cctx.Bool("export-traces") {
ibj, err := os.Create("import-bench.json")
if err != nil {
return err
}
defer ibj.Close() //nolint:errcheck
enc := json.NewEncoder(ibj)
enc = json.NewEncoder(ibj)
}
var lastTse *TipSetExec
@ -173,17 +202,19 @@ var importBenchCmd = &cli.Command{
if err != nil {
return err
}
stripCallers(trace)
if enc != nil {
stripCallers(trace)
lastTse = &TipSetExec{
TipSet: cur.Key(),
Trace: trace,
Duration: time.Since(start),
lastTse = &TipSetExec{
TipSet: cur.Key(),
Trace: trace,
Duration: time.Since(start),
}
if err := enc.Encode(lastTse); err != nil {
return xerrors.Errorf("failed to write out tipsetexec: %w", err)
}
}
lastState = st
if err := enc.Encode(lastTse); err != nil {
return xerrors.Errorf("failed to write out tipsetexec: %w", err)
}
}
pprof.StopCPUProfile()