les: filter txpool relative request statistic

This commit is contained in:
rjl493456442 2019-09-11 19:58:03 +08:00 committed by Zsolt Felfoldi
parent d1c62b7f42
commit 1a6aa2fd40

View file

@ -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)