mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: filter txpool relative request statistic
This commit is contained in:
parent
5510b761d5
commit
e331baa7cc
2 changed files with 47 additions and 29 deletions
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
"github.com/ethereum/go-ethereum/les/flowcontrol"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
const makeCostStats = false // make request cost statistics during operation
|
const makeCostStats = false // make request cost statistics during operation
|
||||||
|
|
@ -87,7 +88,7 @@ const (
|
||||||
gfUsageTC = time.Second
|
gfUsageTC = time.Second
|
||||||
gfRaiseTC = time.Second * 200
|
gfRaiseTC = time.Second * 200
|
||||||
gfDropTC = time.Second * 50
|
gfDropTC = time.Second * 50
|
||||||
gfDbKey = "_globalCostFactorV3"
|
gfDbKey = "_globalCostFactorV4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// costTracker is responsible for calculating costs and cost estimates on the
|
// costTracker is responsible for calculating costs and cost estimates on the
|
||||||
|
|
@ -226,6 +227,8 @@ type reqInfo struct {
|
||||||
// servingTime is the CPU time corresponding to the actual processing of
|
// servingTime is the CPU time corresponding to the actual processing of
|
||||||
// the request.
|
// the request.
|
||||||
servingTime float64
|
servingTime float64
|
||||||
|
|
||||||
|
// msgCode indicates the type of request.
|
||||||
msgCode uint64
|
msgCode uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,13 +273,10 @@ func (ct *costTracker) gfLoop() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case r := <-ct.reqInfoCh:
|
case r := <-ct.reqInfoCh:
|
||||||
requestServedMeter.Mark(int64(r.servingTime))
|
relCost := int64(factor * r.servingTime * 100 / r.avgTimeCost) // Convert the value to a percentage form
|
||||||
requestServedTimer.Update(time.Duration(r.servingTime))
|
|
||||||
requestEstimatedMeter.Mark(int64(r.avgTimeCost / factor))
|
|
||||||
requestEstimatedTimer.Update(time.Duration(r.avgTimeCost / factor))
|
|
||||||
|
|
||||||
relCost := int64(factor * r.servingTime * 10000 / r.avgTimeCost)
|
// Record more metrics if we are debugging
|
||||||
relativeCostHistogram.Update(relCost)
|
if metrics.EnabledExpensive {
|
||||||
switch r.msgCode {
|
switch r.msgCode {
|
||||||
case GetBlockHeadersMsg:
|
case GetBlockHeadersMsg:
|
||||||
relativeCostHeaderHistogram.Update(relCost)
|
relativeCostHeaderHistogram.Update(relCost)
|
||||||
|
|
@ -295,6 +295,21 @@ func (ct *costTracker) gfLoop() {
|
||||||
case GetTxStatusMsg:
|
case GetTxStatusMsg:
|
||||||
relativeCostTxStatusHistogram.Update(relCost)
|
relativeCostTxStatusHistogram.Update(relCost)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// SendTxV2 and GetTxStatus requests are two special cases.
|
||||||
|
// All other requests will only put pressure on the database, and
|
||||||
|
// the corresponding delay is relatively stable. While these two
|
||||||
|
// requests involve txpool query, which is usually unstable.
|
||||||
|
//
|
||||||
|
// TODO(rjl493456442) fixes this.
|
||||||
|
if r.msgCode == SendTxV2Msg || r.msgCode == GetTxStatusMsg {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
requestServedMeter.Mark(int64(r.servingTime))
|
||||||
|
requestServedTimer.Update(time.Duration(r.servingTime))
|
||||||
|
requestEstimatedMeter.Mark(int64(r.avgTimeCost / factor))
|
||||||
|
requestEstimatedTimer.Update(time.Duration(r.avgTimeCost / factor))
|
||||||
|
relativeCostHistogram.Update(relCost)
|
||||||
|
|
||||||
now := mclock.Now()
|
now := mclock.Now()
|
||||||
dt := float64(now - expUpdate)
|
dt := float64(now - expUpdate)
|
||||||
|
|
|
||||||
|
|
@ -867,16 +867,19 @@ func (h *serverHandler) getAuxiliaryHeaders(req HelperTrieReq) []byte {
|
||||||
// txStatus returns the status of a specified transaction.
|
// txStatus returns the status of a specified transaction.
|
||||||
func (h *serverHandler) txStatus(hash common.Hash) light.TxStatus {
|
func (h *serverHandler) txStatus(hash common.Hash) light.TxStatus {
|
||||||
var stat light.TxStatus
|
var stat light.TxStatus
|
||||||
// Looking the transaction in txpool first.
|
|
||||||
stat.Status = h.txpool.Status([]common.Hash{hash})[0]
|
stat.Status = h.txpool.Status([]common.Hash{hash})[0]
|
||||||
|
|
||||||
// If the transaction is unknown to the pool, try looking it up locally.
|
// Looking the transaction in database first.
|
||||||
if stat.Status == core.TxStatusUnknown {
|
// The reason here is usually txpool has a high pressure in the mainnet,
|
||||||
|
// the cost to query the status in pool is even higher than database.
|
||||||
lookup := h.blockchain.GetTransactionLookup(hash)
|
lookup := h.blockchain.GetTransactionLookup(hash)
|
||||||
if lookup != nil {
|
if lookup != nil {
|
||||||
stat.Status = core.TxStatusIncluded
|
stat.Status = core.TxStatusIncluded
|
||||||
stat.Lookup = lookup
|
stat.Lookup = lookup
|
||||||
}
|
}
|
||||||
|
// If the transaction is unknown to the database, try looking it up in txpool.
|
||||||
|
if stat.Status == core.TxStatusUnknown {
|
||||||
|
stat.Status = h.txpool.Status([]common.Hash{hash})[0]
|
||||||
}
|
}
|
||||||
return stat
|
return stat
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue