Skip to content

Commit

Permalink
add more logs for txindex
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenlanders committed Mar 25, 2024
1 parent b46ea58 commit 100f53a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion debugutil/timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ func PrintStats(msg string, durations []time.Duration) {
}
}
avg := sum / time.Duration(len(durations))
fmt.Printf("[Debug] %s count=%d sum=%s avg=%s max=%s min=%s\n", msg, len(durations), sum, avg, max, min)
// only show the slow ones
if sum > 500*time.Millisecond {
fmt.Printf("[Debug] %s count=%d sum=%s avg=%s max=%s min=%s\n", msg, len(durations), sum, avg, max, min)
}
}
10 changes: 8 additions & 2 deletions internal/state/indexer/tx/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (txi *TxIndex) Index(results []*abci.TxResult) error {
b := txi.store.NewBatch()
defer b.Close()

var durations []time.Duration
for _, result := range results {
hash := types.Tx(result.Tx).Hash()

Expand All @@ -91,13 +92,18 @@ func (txi *TxIndex) Index(results []*abci.TxResult) error {
return err
}
// index by hash (always)
start := time.Now()
err = b.Set(primaryKey(hash), rawBytes)
durations = append(durations, time.Since(start))
if err != nil {
return err
}
}

return b.WriteSync()
debugutil.PrintStats("TxIndex.Index b.Set(primaryKey(hash), rawBytes)", durations)
t2 := debugutil.NewTimer(fmt.Sprintf("TxIndex.Index WriteSync (txs=%d)", len(results)))
err := b.WriteSync()
t2.Stop()
return err
}

func (txi *TxIndex) indexEvents(result *abci.TxResult, hash []byte, store dbm.Batch) error {
Expand Down

0 comments on commit 100f53a

Please sign in to comment.