mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core, metrics: switch txpool meters to counters
This commit is contained in:
parent
375ec0405f
commit
5a4c214108
2 changed files with 29 additions and 20 deletions
|
|
@ -58,19 +58,19 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Metrics for the pending pool
|
// Metrics for the pending pool
|
||||||
pendingDiscardMeter = metrics.NewMeter("txpool/pending/discard")
|
pendingDiscardCounter = metrics.NewCounter("txpool/pending/discard")
|
||||||
pendingReplaceMeter = metrics.NewMeter("txpool/pending/replace")
|
pendingReplaceCounter = metrics.NewCounter("txpool/pending/replace")
|
||||||
pendingRLMeter = metrics.NewMeter("txpool/pending/ratelimit") // Dropped due to rate limiting
|
pendingRLCounter = metrics.NewCounter("txpool/pending/ratelimit") // Dropped due to rate limiting
|
||||||
pendingNofundsMeter = metrics.NewMeter("txpool/pending/nofunds") // Dropped due to out-of-funds
|
pendingNofundsCounter = metrics.NewCounter("txpool/pending/nofunds") // Dropped due to out-of-funds
|
||||||
|
|
||||||
// Metrics for the queued pool
|
// Metrics for the queued pool
|
||||||
queuedDiscardMeter = metrics.NewMeter("txpool/queued/discard")
|
queuedDiscardCounter = metrics.NewCounter("txpool/queued/discard")
|
||||||
queuedReplaceMeter = metrics.NewMeter("txpool/queued/replace")
|
queuedReplaceCounter = metrics.NewCounter("txpool/queued/replace")
|
||||||
queuedRLMeter = metrics.NewMeter("txpool/queued/ratelimit") // Dropped due to rate limiting
|
queuedRLCounter = metrics.NewCounter("txpool/queued/ratelimit") // Dropped due to rate limiting
|
||||||
queuedNofundsMeter = metrics.NewMeter("txpool/queued/nofunds") // Dropped due to out-of-funds
|
queuedNofundsCounter = metrics.NewCounter("txpool/queued/nofunds") // Dropped due to out-of-funds
|
||||||
|
|
||||||
// General tx metrics
|
// General tx metrics
|
||||||
invalidTxMeter = metrics.NewMeter("txpool/invalid")
|
invalidTxCounter = metrics.NewCounter("txpool/invalid")
|
||||||
)
|
)
|
||||||
|
|
||||||
type stateFn func() (*state.StateDB, error)
|
type stateFn func() (*state.StateDB, error)
|
||||||
|
|
@ -324,7 +324,7 @@ func (pool *TxPool) add(tx *types.Transaction) error {
|
||||||
}
|
}
|
||||||
// Otherwise ensure basic validation passes and queue it up
|
// Otherwise ensure basic validation passes and queue it up
|
||||||
if err := pool.validateTx(tx); err != nil {
|
if err := pool.validateTx(tx); err != nil {
|
||||||
invalidTxMeter.Mark(1)
|
invalidTxCounter.Inc(1)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pool.enqueueTx(hash, tx)
|
pool.enqueueTx(hash, tx)
|
||||||
|
|
@ -352,13 +352,13 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) {
|
||||||
}
|
}
|
||||||
inserted, old := pool.queue[from].Add(tx)
|
inserted, old := pool.queue[from].Add(tx)
|
||||||
if !inserted {
|
if !inserted {
|
||||||
queuedDiscardMeter.Mark(1)
|
queuedDiscardCounter.Inc(1)
|
||||||
return // An older transaction was better, discard this
|
return // An older transaction was better, discard this
|
||||||
}
|
}
|
||||||
// Discard any previous transaction and mark this
|
// Discard any previous transaction and mark this
|
||||||
if old != nil {
|
if old != nil {
|
||||||
delete(pool.all, old.Hash())
|
delete(pool.all, old.Hash())
|
||||||
queuedReplaceMeter.Mark(1)
|
queuedReplaceCounter.Inc(1)
|
||||||
}
|
}
|
||||||
pool.all[hash] = tx
|
pool.all[hash] = tx
|
||||||
}
|
}
|
||||||
|
|
@ -381,13 +381,13 @@ func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.T
|
||||||
if !inserted {
|
if !inserted {
|
||||||
// An older transaction was better, discard this
|
// An older transaction was better, discard this
|
||||||
delete(pool.all, hash)
|
delete(pool.all, hash)
|
||||||
pendingDiscardMeter.Mark(1)
|
pendingDiscardCounter.Inc(1)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Otherwise discard any previous transaction and mark this
|
// Otherwise discard any previous transaction and mark this
|
||||||
if old != nil {
|
if old != nil {
|
||||||
delete(pool.all, old.Hash())
|
delete(pool.all, old.Hash())
|
||||||
pendingReplaceMeter.Mark(1)
|
pendingReplaceCounter.Inc(1)
|
||||||
}
|
}
|
||||||
pool.all[hash] = tx // Failsafe to work around direct pending inserts (tests)
|
pool.all[hash] = tx // Failsafe to work around direct pending inserts (tests)
|
||||||
|
|
||||||
|
|
@ -522,7 +522,7 @@ func (pool *TxPool) promoteExecutables() {
|
||||||
glog.Infof("Removed unpayable queued transaction: %v", tx)
|
glog.Infof("Removed unpayable queued transaction: %v", tx)
|
||||||
}
|
}
|
||||||
delete(pool.all, tx.Hash())
|
delete(pool.all, tx.Hash())
|
||||||
queuedNofundsMeter.Mark(1)
|
queuedNofundsCounter.Inc(1)
|
||||||
}
|
}
|
||||||
// Gather all executable transactions and promote them
|
// Gather all executable transactions and promote them
|
||||||
for _, tx := range list.Ready(pool.pendingState.GetNonce(addr)) {
|
for _, tx := range list.Ready(pool.pendingState.GetNonce(addr)) {
|
||||||
|
|
@ -537,7 +537,7 @@ func (pool *TxPool) promoteExecutables() {
|
||||||
glog.Infof("Removed cap-exceeding queued transaction: %v", tx)
|
glog.Infof("Removed cap-exceeding queued transaction: %v", tx)
|
||||||
}
|
}
|
||||||
delete(pool.all, tx.Hash())
|
delete(pool.all, tx.Hash())
|
||||||
queuedRLMeter.Mark(1)
|
queuedRLCounter.Inc(1)
|
||||||
}
|
}
|
||||||
queued += uint64(list.Len())
|
queued += uint64(list.Len())
|
||||||
|
|
||||||
|
|
@ -599,7 +599,7 @@ func (pool *TxPool) promoteExecutables() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pendingRLMeter.Mark(int64(pendingBeforeCap - pending))
|
pendingRLCounter.Inc(int64(pendingBeforeCap - pending))
|
||||||
}
|
}
|
||||||
// If we've queued more transactions than the hard limit, drop oldest ones
|
// If we've queued more transactions than the hard limit, drop oldest ones
|
||||||
if queued > maxQueuedInTotal {
|
if queued > maxQueuedInTotal {
|
||||||
|
|
@ -623,7 +623,7 @@ func (pool *TxPool) promoteExecutables() {
|
||||||
pool.removeTx(tx.Hash())
|
pool.removeTx(tx.Hash())
|
||||||
}
|
}
|
||||||
drop -= size
|
drop -= size
|
||||||
queuedRLMeter.Mark(int64(size))
|
queuedRLCounter.Inc(int64(size))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Otherwise drop only last few transactions
|
// Otherwise drop only last few transactions
|
||||||
|
|
@ -631,7 +631,7 @@ func (pool *TxPool) promoteExecutables() {
|
||||||
for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
|
for i := len(txs) - 1; i >= 0 && drop > 0; i-- {
|
||||||
pool.removeTx(txs[i].Hash())
|
pool.removeTx(txs[i].Hash())
|
||||||
drop--
|
drop--
|
||||||
queuedRLMeter.Mark(1)
|
queuedRLCounter.Inc(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -665,7 +665,7 @@ func (pool *TxPool) demoteUnexecutables() {
|
||||||
glog.Infof("Removed unpayable pending transaction: %v", tx)
|
glog.Infof("Removed unpayable pending transaction: %v", tx)
|
||||||
}
|
}
|
||||||
delete(pool.all, tx.Hash())
|
delete(pool.all, tx.Hash())
|
||||||
pendingNofundsMeter.Mark(1)
|
pendingNofundsCounter.Inc(1)
|
||||||
}
|
}
|
||||||
for _, tx := range invalids {
|
for _, tx := range invalids {
|
||||||
if glog.V(logger.Core) {
|
if glog.V(logger.Core) {
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,15 @@ func init() {
|
||||||
exp.Exp(metrics.DefaultRegistry)
|
exp.Exp(metrics.DefaultRegistry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCounter create a new metrics Counter, either a real one of a NOP stub depending
|
||||||
|
// on the metrics flag.
|
||||||
|
func NewCounter(name string) metrics.Counter {
|
||||||
|
if !Enabled {
|
||||||
|
return new(metrics.NilCounter)
|
||||||
|
}
|
||||||
|
return metrics.GetOrRegisterCounter(name, metrics.DefaultRegistry)
|
||||||
|
}
|
||||||
|
|
||||||
// NewMeter create a new metrics Meter, either a real one of a NOP stub depending
|
// NewMeter create a new metrics Meter, either a real one of a NOP stub depending
|
||||||
// on the metrics flag.
|
// on the metrics flag.
|
||||||
func NewMeter(name string) metrics.Meter {
|
func NewMeter(name string) metrics.Meter {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue