Skip to content

Commit

Permalink
sli: move small read duration metrics to store/tikv (#25343)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored Jun 11, 2021
1 parent 487c08a commit 9505b4b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/store/copr"
"github.com/pingcap/tidb/store/tikv"
tikvmetrics "github.com/pingcap/tidb/store/tikv/metrics"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/types"
Expand All @@ -41,7 +42,6 @@ import (
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/sli"
"github.com/pingcap/tipb/go-tipb"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -346,7 +346,7 @@ func (r *selectResult) updateCopRuntimeStats(ctx context.Context, copStats *copr
if copStats.ScanDetail != nil {
readKeys := copStats.ScanDetail.ProcessedKeys
readTime := copStats.TimeDetail.KvReadWallTimeMs.Seconds()
sli.ObserveReadSLI(uint64(readKeys), readTime)
tikvmetrics.ObserveReadSLI(uint64(readKeys), readTime)
}

if r.stats == nil {
Expand Down
1 change: 0 additions & 1 deletion metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func RegisterMetrics() {
prometheus.MustRegister(TiFlashQueryTotalCounter)
prometheus.MustRegister(SmallTxnWriteDuration)
prometheus.MustRegister(TxnWriteThroughput)
prometheus.MustRegister(TiKVSmallReadDuration)
prometheus.MustRegister(LoadSysVarCacheCounter)

tikvmetrics.InitMetrics(TiDB, TiKVClient)
Expand Down
10 changes: 0 additions & 10 deletions metrics/sli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,4 @@ var (
Help: "Bucketed histogram of transaction write throughput (bytes/second).",
Buckets: prometheus.ExponentialBuckets(64, 1.3, 40), // 64 bytes/s ~ 2.3MB/s
})

// TiKVSmallReadDuration uses to collect small request read duration.
TiKVSmallReadDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "sli",
Name: "tikv_small_read_duration",
Help: "Read time of TiKV small read.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 28), // 0.5ms ~ 74h
})
)
21 changes: 21 additions & 0 deletions store/tikv/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
TiKVRequestRetryTimesHistogram prometheus.Histogram
TiKVTxnCommitBackoffSeconds prometheus.Histogram
TiKVTxnCommitBackoffCount prometheus.Histogram
TiKVSmallReadDuration prometheus.Histogram
)

// Label constants.
Expand Down Expand Up @@ -467,6 +468,16 @@ func initMetrics(namespace, subsystem string) {
Buckets: prometheus.ExponentialBuckets(1, 2, 12), // 1 ~ 2048
})

// TiKVSmallReadDuration uses to collect small request read duration.
TiKVSmallReadDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: "sli", // Always use "sli" to make it compatible with TiDB.
Name: "tikv_small_read_duration",
Help: "Read time of TiKV small read.",
Buckets: prometheus.ExponentialBuckets(0.0005, 2, 28), // 0.5ms ~ 74h
})

initShortcuts()
}

Expand Down Expand Up @@ -527,6 +538,7 @@ func RegisterMetrics() {
prometheus.MustRegister(TiKVRequestRetryTimesHistogram)
prometheus.MustRegister(TiKVTxnCommitBackoffSeconds)
prometheus.MustRegister(TiKVTxnCommitBackoffCount)
prometheus.MustRegister(TiKVSmallReadDuration)
}

// readCounter reads the value of a prometheus.Counter.
Expand Down Expand Up @@ -567,3 +579,12 @@ func GetTxnCommitCounter() TxnCommitCounter {
OnePC: readCounter(OnePCTxnCounterOk),
}
}

const smallTxnAffectRow = 20

// ObserveReadSLI observes the read SLI metric.
func ObserveReadSLI(readKeys uint64, readTime float64) {
if readKeys <= smallTxnAffectRow && readKeys != 0 && readTime != 0 {
TiKVSmallReadDuration.Observe(readTime)
}
}
5 changes: 2 additions & 3 deletions store/tikv/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/pingcap/tidb/store/tikv/tikvrpc"
"github.com/pingcap/tidb/store/tikv/unionstore"
"github.com/pingcap/tidb/store/tikv/util"
"github.com/pingcap/tidb/util/sli"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -406,7 +405,7 @@ func (s *KVSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, collec
if batchGetResp.ExecDetailsV2 != nil {
readKeys := len(batchGetResp.Pairs)
readTime := float64(batchGetResp.ExecDetailsV2.GetTimeDetail().GetKvReadWallTimeMs() / 1000)
sli.ObserveReadSLI(uint64(readKeys), readTime)
metrics.ObserveReadSLI(uint64(readKeys), readTime)
s.mergeExecDetail(batchGetResp.ExecDetailsV2)
}
if len(lockedKeys) > 0 {
Expand Down Expand Up @@ -544,7 +543,7 @@ func (s *KVSnapshot) get(ctx context.Context, bo *Backoffer, k []byte) ([]byte,
if cmdGetResp.ExecDetailsV2 != nil {
readKeys := len(cmdGetResp.Value)
readTime := float64(cmdGetResp.ExecDetailsV2.GetTimeDetail().GetKvReadWallTimeMs() / 1000)
sli.ObserveReadSLI(uint64(readKeys), readTime)
metrics.ObserveReadSLI(uint64(readKeys), readTime)
s.mergeExecDetail(cmdGetResp.ExecDetailsV2)
}
val := cmdGetResp.GetValue()
Expand Down
7 changes: 0 additions & 7 deletions util/sli/sli.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,3 @@ func (t *TxnWriteThroughputSLI) String() string {
return fmt.Sprintf("invalid: %v, affectRow: %v, writeSize: %v, readKeys: %v, writeKeys: %v, writeTime: %v",
t.invalid, t.affectRow, t.writeSize, t.readKeys, t.writeKeys, t.writeTime.String())
}

// ObserveReadSLI observes the read SLI metric.
func ObserveReadSLI(readKeys uint64, readTime float64) {
if readKeys <= smallTxnAffectRow && readKeys != 0 && readTime != 0 {
metrics.TiKVSmallReadDuration.Observe(readTime)
}
}

0 comments on commit 9505b4b

Please sign in to comment.