-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement caching syscalls for import-bench #3888
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
96193c2
Implement bench-cache
79ba459
Implement cache
53ab17c
Add no import to import-bench
1f4d1dc
Do not sync
12a0dd3
<3 to linter
108fe78
Add command to trigger gc
7827179
Add logs
3858309
Add http to import bench
01386a2
Update options
f21c5cb
Add start-at
ebc8489
Add global-profile option
35cf69a
Disable bloomcache
242a77b
go mod tidy
b7f18b4
Disable callers
1c6214b
Usage go-bitfield with buffer pool
0771c23
Use pebble
55c6b88
Add toggle for badger, flag out gas tracing
ff8c0af
Add only-import option
76db65b
Update pebble
0d914ac
Switch to badger
7e8c6e5
Remove statediff, fix lint, go mod tidy
247a5e2
Go mod tidy
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"context" | ||
"errors" | ||
|
||
"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" | ||
"github.com/minio/blake2b-simd" | ||
cbg "github.com/whyrusleeping/cbor-gen" | ||
) | ||
|
||
type cachingVerifier struct { | ||
ds datastore.Datastore | ||
backend ffiwrapper.Verifier | ||
} | ||
|
||
const bufsize = 128 | ||
|
||
func (cv cachingVerifier) withCache(execute func() (bool, error), param cbg.CBORMarshaler) (bool, error) { | ||
hasher := blake2b.New256() | ||
wr := bufio.NewWriterSize(hasher, bufsize) | ||
err := param.MarshalCBOR(wr) | ||
if err != nil { | ||
log.Errorf("could not marshal call info: %+v", err) | ||
return execute() | ||
} | ||
err = wr.Flush() | ||
if err != nil { | ||
log.Errorf("could not flush: %+v", err) | ||
return execute() | ||
} | ||
hash := hasher.Sum(nil) | ||
key := datastore.NewKey(string(hash)) | ||
fromDs, err := cv.ds.Get(key) | ||
if err == nil { | ||
switch fromDs[0] { | ||
case 's': | ||
return true, nil | ||
case 'f': | ||
return false, nil | ||
case 'e': | ||
return false, errors.New(string(fromDs[1:])) | ||
default: | ||
log.Errorf("bad cached result in cache %s(%x)", fromDs[0], fromDs[0]) | ||
return execute() | ||
} | ||
} else if errors.Is(err, datastore.ErrNotFound) { | ||
// recalc | ||
ok, err := execute() | ||
var save []byte | ||
if err != nil { | ||
if ok { | ||
log.Errorf("success with an error: %+v", err) | ||
} else { | ||
save = append([]byte{'e'}, []byte(err.Error())...) | ||
} | ||
} else if ok { | ||
save = []byte{'s'} | ||
} else { | ||
save = []byte{'f'} | ||
} | ||
|
||
if len(save) != 0 { | ||
errSave := cv.ds.Put(key, save) | ||
if errSave != nil { | ||
log.Errorf("error saving result: %+v", errSave) | ||
} | ||
} | ||
|
||
return ok, err | ||
} else { | ||
log.Errorf("could not get data from cache: %+v", err) | ||
return execute() | ||
} | ||
} | ||
|
||
func (cv *cachingVerifier) VerifySeal(svi proof.SealVerifyInfo) (bool, error) { | ||
return cv.withCache(func() (bool, error) { | ||
return cv.backend.VerifySeal(svi) | ||
}, &svi) | ||
} | ||
func (cv *cachingVerifier) VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) { | ||
return cv.backend.VerifyWinningPoSt(ctx, info) | ||
} | ||
func (cv *cachingVerifier) VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) { | ||
return cv.withCache(func() (bool, error) { | ||
return cv.backend.VerifyWindowPoSt(ctx, info) | ||
}, &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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably shouldn't default to false
(Ideally we'd set this per VM)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I will work on this in next PR. The performance boost is high enough to justify disabling it until that is done.