From 100f53abff0c3aef2e23cd9879d1beff0c5aab86 Mon Sep 17 00:00:00 2001 From: Steven Landers Date: Mon, 25 Mar 2024 15:14:55 -0400 Subject: [PATCH] add more logs for txindex --- debugutil/timer.go | 5 ++++- internal/state/indexer/tx/kv/kv.go | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/debugutil/timer.go b/debugutil/timer.go index 1719440f0..0c4084ba6 100644 --- a/debugutil/timer.go +++ b/debugutil/timer.go @@ -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) + } } diff --git a/internal/state/indexer/tx/kv/kv.go b/internal/state/indexer/tx/kv/kv.go index 2ed1c449b..d8c11f685 100644 --- a/internal/state/indexer/tx/kv/kv.go +++ b/internal/state/indexer/tx/kv/kv.go @@ -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() @@ -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 {