Skip to content

Commit

Permalink
add metrics for bottleneck of txpool: watch the parallel count when r…
Browse files Browse the repository at this point in the history
…eading transactions from p2p network
  • Loading branch information
andyzhang2023 committed Nov 15, 2024
1 parent bb3b209 commit c2ab741
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions eth/handler_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"math/big"
"runtime"
"sync/atomic"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/eth/fetcher"
"github.com/ethereum/go-ethereum/eth/protocols/eth"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p/enode"
)

Expand All @@ -40,14 +42,26 @@ var (
// enqueueTx is a channel to enqueue transactions in parallel.
// It is used to improve the performance of transaction enqueued.
var enqueueTx = make(chan func(), TxQueueSize)
var parallelCounter int32 = 0
var parallelCounterGuage = metrics.NewRegisteredGauge("p2p/enqueue/parallel", nil)

func init() {
log.Info("P2P euqneue parallel thread number", "threadNum", TxQueueSize)
// run the transaction enqueuing loop
for i := 0; i < TxQueueSize; i++ {
go func() {
for enqueue := range enqueueTx {
atomic.AddInt32(&parallelCounter, 1)
enqueue()
atomic.AddInt32(&parallelCounter, -1)
}
}()
}
if metrics.EnabledExpensive {
go func() {
for {
time.Sleep(1 * time.Second)
parallelCounterGuage.Update(int64(atomic.LoadInt32(&parallelCounter)))
}
}()
}
Expand Down

0 comments on commit c2ab741

Please sign in to comment.