Skip to content

Commit

Permalink
distsql: add metrics for coprocessor cache (pingcap#19979)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored Sep 29, 2020
1 parent fa81ec5 commit f2d4e47
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 2 deletions.
7 changes: 7 additions & 0 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import (

var (
errQueryInterrupted = terror.ClassExecutor.NewStd(errno.ErrQueryInterrupted)

coprCacheHistogramHit = metrics.DistSQLCoprCacheHistogram.WithLabelValues("hit")
coprCacheHistogramMiss = metrics.DistSQLCoprCacheHistogram.WithLabelValues("miss")
)

var (
Expand Down Expand Up @@ -155,6 +158,10 @@ func (r *selectResult) fetchResp(ctx context.Context) error {
break
}
}
if r.stats != nil {
coprCacheHistogramHit.Observe(float64(r.stats.CoprCacheHitNum))
coprCacheHistogramMiss.Observe(float64(len(r.stats.copRespTime) - int(r.stats.CoprCacheHitNum)))
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions executor/inspection_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ var inspectionSummaryRules = map[string][]string{
"tidb_distsql_partial_scan_key_num",
"tidb_distsql_qps",
"tidb_distsql_scan_key_num",
"tidb_distsql_copr_cache",
"tidb_region_cache_ops",
"tidb_batch_client_pending_req_count",
"tidb_batch_client_unavailable_duration",
Expand Down
6 changes: 6 additions & 0 deletions infoschema/metric_table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,12 @@ var MetricTableMap = map[string]MetricTableDef{
Labels: []string{"instance", "type"},
Comment: "The total time of distsql execution(second)",
},
"tidb_distsql_copr_cache": {
Comment: "The quantile of TiDB distsql coprocessor cache",
PromQL: "histogram_quantile($QUANTILE, sum(rate(tidb_distsql_copr_cache_buckets{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (type,instance))",
Labels: []string{"instance", "type"},
Quantile: 0.95,
},
"tidb_execute_total_count": {
PromQL: "sum(increase(tidb_session_execute_duration_seconds_count{$LABEL_CONDITIONS}[$RANGE_DURATION])) by (instance,sql_type)",
Labels: []string{"instance", "sql_type"},
Expand Down
8 changes: 8 additions & 0 deletions metrics/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@ var (
Help: "number of partial results for each query.",
},
)
DistSQLCoprCacheHistogram = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "tidb",
Subsystem: "distsql",
Name: "copr_cache",
Help: "coprocessor cache hit, evict and miss number",
Buckets: prometheus.ExponentialBuckets(1, 2, 16),
}, []string{LblType})
)
95 changes: 95 additions & 0 deletions metrics/grafana/tidb.json
Original file line number Diff line number Diff line change
Expand Up @@ -6161,6 +6161,101 @@
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "${DS_TEST-CLUSTER}",
"description": "TiDB coprocessor cache hit, evict and miss number",
"editable": true,
"error": false,
"fill": 1,
"grid": {},
"gridPos": {
"h": 7,
"w": 8,
"x": 16,
"y": 163
},
"id": 175,
"legend": {
"alignAsTable": true,
"avg": false,
"current": false,
"max": true,
"min": false,
"rightSide": true,
"show": true,
"sort": "avg",
"sortDesc": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"nullPointMode": "null as zero",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "histogram_quantile(1, sum(rate(tidb_distsql_copr_cache_buckets[1m])) by (type))",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{type}}",
"refId": "A",
"step": 40
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Coprocessor Cache",
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 2,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "none",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": false
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
},
{
"aliasColors": {},
"bars": false,
Expand Down
1 change: 1 addition & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func RegisterMetrics() {
prometheus.MustRegister(DDLWorkerHistogram)
prometheus.MustRegister(DeploySyncerHistogram)
prometheus.MustRegister(DistSQLPartialCountHistogram)
prometheus.MustRegister(DistSQLCoprCacheHistogram)
prometheus.MustRegister(DistSQLQueryHistogram)
prometheus.MustRegister(DistSQLScanKeysHistogram)
prometheus.MustRegister(DistSQLScanKeysPartialHistogram)
Expand Down
10 changes: 8 additions & 2 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ import (
"go.uber.org/zap"
)

var tikvTxnRegionsNumHistogramWithCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("coprocessor")
var tikvTxnRegionsNumHistogramWithBatchCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("batch_coprocessor")
var (
tikvTxnRegionsNumHistogramWithCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("coprocessor")
tikvTxnRegionsNumHistogramWithBatchCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("batch_coprocessor")
coprCacheHistogramEvict = metrics.DistSQLCoprCacheHistogram.WithLabelValues("evict")
)

// CopClient is coprocessor client.
type CopClient struct {
Expand Down Expand Up @@ -777,6 +780,9 @@ func (worker *copIteratorWorker) handleTask(ctx context.Context, task *copTask,
remainTasks = remainTasks[1:]
}
}
if worker.store.coprCache != nil && worker.store.coprCache.cache.Metrics != nil {
coprCacheHistogramEvict.Observe(float64(worker.store.coprCache.cache.Metrics.KeysEvicted()))
}
}

// handleTaskOnce handles single copTask, successful results are send to channel.
Expand Down

0 comments on commit f2d4e47

Please sign in to comment.