Skip to content

Commit

Permalink
Merge pull request #2 from yihuang/main
Browse files Browse the repository at this point in the history
make memiavl benchmark logic same as iavl
  • Loading branch information
kocubinski authored Aug 8, 2023
2 parents 0b383fc + 4b9ed18 commit 40dabc9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
8 changes: 8 additions & 0 deletions iavl-v0/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ func treeCommand(c context.Context) *cobra.Command {
Short: "rebuild the tree from changesets",
RunE: func(cmd *cobra.Command, args []string) error {
ctx.IndexDir = cmd.Flag("index-dir").Value.String()

hashLog, err := os.Create(fmt.Sprintf("%s/iavl-v0-hash.log", ctx.IndexDir))
if err != nil {
return err
}
defer hashLog.Close()
ctx.HashLog = hashLog

levelDb, err := dbm.NewGoLevelDBWithOpts(levelDbName, ctx.IndexDir, &opt.Options{})
if err != nil {
return err
Expand Down
48 changes: 21 additions & 27 deletions memiavl/memiavl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ func buildCommand(c *context) *cobra.Command {
SnapshotInterval: 100_000,
AsyncCommitBuffer: 5,
}
miavl, err := memiavl.Load(fmt.Sprintf("%s/memiavl", c.indexDir), memIavlOpts)
dir := fmt.Sprintf("%s/memiavl", c.indexDir)
if err := os.RemoveAll(dir); err != nil {
return err
}
miavl, err := memiavl.Load(dir, memIavlOpts)
if err != nil {
return err
}
Expand All @@ -66,37 +70,34 @@ func buildCommand(c *context) *cobra.Command {
//commitResult := make(chan error)
stream := &compact.StreamingContext{}
itr, err := stream.NewIterator(logDir)
if err != nil {
return err
}
for ; itr.Valid(); err = itr.Next() {
if err != nil {
return err
}
n := itr.Node

// continue building changeset
namedChangeset.Changeset.Pairs = append(namedChangeset.Changeset.Pairs, &iavl_proto.KVPair{
Key: n.Key,
Value: n.Value,
Delete: n.Delete,
})

// block height advanced; flush.
if n.Block > lastVersion {
h, v, commitErr := miavl.Commit([]*memiavl.NamedChangeSet{namedChangeset})
if commitErr != nil {
log.Error().Err(commitErr).Msgf("failed to commit changeset at block %d", n.Block)
return commitErr
_, v, err := miavl.Commit([]*memiavl.NamedChangeSet{namedChangeset})
if err != nil {
return err
}
if v%20_000 == 0 {
_, err = fmt.Fprintf(hashLog, "%d|%x\n", v, h)
_, err = fmt.Fprintf(hashLog, "%d|%x\n", v, miavl.TreeByName("bank").RootHash())
if err != nil {
return err
}
}
// go func() {
// commitResult <- commitErr
// }()
// select {
// case <-time.After(1 * time.Minute):
// log.Fatal().Msgf("commit took longer than 1 minute at block %d", n.Block)
// case err := <-commitResult:
// if err != nil {
// log.Error().Err(err).Msgf("failed to commit changeset at block %d", n.Block)
// return err
// }
// }

namedChangeset = &memiavl.NamedChangeSet{
Name: "bank",
Expand All @@ -105,18 +106,11 @@ func buildCommand(c *context) *cobra.Command {
lastVersion = n.Block
}

// continue building changeset
namedChangeset.Changeset.Pairs = append(namedChangeset.Changeset.Pairs, &iavl_proto.KVPair{
Key: n.Key,
Value: n.Value,
Delete: n.Delete,
})

if cnt%50_000 == 0 {
if cnt%100_000 == 0 {
log.Info().Msgf("processed %s leaves in %s; %s leaves/s",
humanize.Comma(int64(cnt)),
time.Since(since),
humanize.Comma(int64(50_000/time.Since(since).Seconds())))
humanize.Comma(int64(100_000/time.Since(since).Seconds())))
since = time.Now()
}
cnt++
Expand Down

0 comments on commit 40dabc9

Please sign in to comment.