Skip to content

Commit 8e6443f

Browse files
committed
fix full tree bug and add cpu profile
1 parent 02e6130 commit 8e6443f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

v2/cmd/bench/bench.go

+18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package bench
22

33
import (
44
"net/http"
5+
"os"
6+
"runtime/pprof"
57
"testing"
68
"time"
79

@@ -30,6 +32,7 @@ func benchCommand() *cobra.Command {
3032
changelogPath string
3133
loadSnapshot bool
3234
usePrometheus bool
35+
cpuProfile string
3336
)
3437
cmd := &cobra.Command{
3538
Use: "std",
@@ -44,12 +47,26 @@ $ go run ./cmd snapshot --db /tmp/iavl-v2 --version 1
4447
`,
4548

4649
RunE: func(_ *cobra.Command, _ []string) error {
50+
if cpuProfile != "" {
51+
f, err := os.Create(cpuProfile)
52+
if err != nil {
53+
return err
54+
}
55+
if err := pprof.StartCPUProfile(f); err != nil {
56+
return err
57+
}
58+
defer func() {
59+
pprof.StopCPUProfile()
60+
f.Close()
61+
}()
62+
}
4763
t := &testing.T{}
4864
treeOpts := iavl.DefaultTreeOptions()
4965
treeOpts.CheckpointInterval = 80
5066
treeOpts.StateStorage = true
5167
treeOpts.HeightFilter = 1
5268
treeOpts.EvictionDepth = 22
69+
treeOpts.PruneRatio = 0
5370
treeOpts.MetricsProxy = metrics.NewStructMetrics()
5471
if usePrometheus {
5572
treeOpts.MetricsProxy = newPrometheusMetricsProxy()
@@ -84,6 +101,7 @@ $ go run ./cmd snapshot --db /tmp/iavl-v2 --version 1
84101
cmd.Flags().StringVar(&changelogPath, "changelog", "/tmp/osmo-like-many/v2", "the path to the changelog")
85102
cmd.Flags().BoolVar(&loadSnapshot, "snapshot", false, "load the snapshot at version 1 before running the benchmarks (loads full tree into memory)")
86103
cmd.Flags().BoolVar(&usePrometheus, "prometheus", false, "enable prometheus metrics")
104+
cmd.Flags().StringVar(&cpuProfile, "cpu-profile", "", "write cpu profile to file")
87105

88106
if err := cmd.MarkFlagRequired("changelog"); err != nil {
89107
panic(err)

v2/sqlite.go

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ func NewSqliteDb(pool *NodePool, opts SqliteDbOptions) (*SqliteDb, error) {
165165
if err != nil {
166166
return nil, err
167167
}
168+
err = hubConn.Exec("PRAGMA journal_mode=WAL;")
169+
if err != nil {
170+
return nil, err
171+
}
168172
sql := &SqliteDb{
169173
shards: &VersionRange{},
170174
hotConnectionFactory: newHotConnectionFactory(hubConn, opts),

v2/tree.go

+1
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ func (tree *Tree) deepHash(node *Node, depth int8) (evict bool) {
417417
node.evict = 1
418418
return true
419419
}
420+
return false
420421
}
421422

422423
var evictLeft, evictRight bool

0 commit comments

Comments
 (0)