Skip to content

Commit

Permalink
debug add block speed
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Dec 7, 2020
1 parent 60c852e commit 4ab1412
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/btcsuite/btcd v0.21.0-beta
github.com/btcsuite/btcutil v1.0.2
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201206160637-6155702fc1d7
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201207152233-89b1075cef44
github.com/dgraph-io/badger/v2 v2.2007.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2
github.com/stretchr/testify v1.6.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201205202626-20e9956fc386 h1:Y7JTS
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201205202626-20e9956fc386/go.mod h1:MvQfsL2KlJ5786OdDviRIJE3agui2YcvS1CaQPDl1Yo=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201206160637-6155702fc1d7 h1:53EVYPuXEXL/3/OuGtWy0gtz/2HSiMhKMSWrgEEoudY=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201206160637-6155702fc1d7/go.mod h1:MvQfsL2KlJ5786OdDviRIJE3agui2YcvS1CaQPDl1Yo=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201207145242-fffc69dd8208 h1:arGGiIscN+E1kWi+nX31DftCfktR3d3bOC8ONRuPyko=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201207145242-fffc69dd8208/go.mod h1:MvQfsL2KlJ5786OdDviRIJE3agui2YcvS1CaQPDl1Yo=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201207152233-89b1075cef44 h1:jyV+DlKYbB2Vsz0PfdwoasnAITasdwcirUezOkSkrtM=
github.com/coinbase/rosetta-sdk-go v0.6.5-0.20201207152233-89b1075cef44/go.mod h1:MvQfsL2KlJ5786OdDviRIJE3agui2YcvS1CaQPDl1Yo=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down
12 changes: 12 additions & 0 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ func (i *Indexer) Prune(ctx context.Context) error {
func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error {
logger := utils.ExtractLogger(ctx, "indexer")

start := time.Now()

err := i.blockStorage.AddBlock(ctx, block)
if err != nil {
return fmt.Errorf(
Expand All @@ -339,6 +341,8 @@ func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error {
)
}

addBlockTime := time.Since(start)

ops := 0
for _, transaction := range block.Transactions {
ops += len(transaction.Operations)
Expand All @@ -361,6 +365,8 @@ func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error {
}
i.coinCacheMutex.Unlock()

cleanCacheTime := time.Since(start) - addBlockTime

// Look for all remaining waiting transactions associated
// with the next block that have not yet been closed. We should
// abort these waits as they will never be closed by a new transaction.
Expand All @@ -380,12 +386,18 @@ func (i *Indexer) BlockAdded(ctx context.Context, block *types.Block) error {
}
i.waiter.Unlock()

waiterIteration := time.Since(start) - addBlockTime - cleanCacheTime

logger.Debugw(
"block added",
"hash", block.BlockIdentifier.Hash,
"index", block.BlockIdentifier.Index,
"transactions", len(block.Transactions),
"ops", ops,
"total add time", time.Since(start),
"add time", addBlockTime,
"clean cache time", cleanCacheTime,
"waiter iteration", waiterIteration,
)

return nil
Expand Down

0 comments on commit 4ab1412

Please sign in to comment.