Skip to content

Commit 02d0a6f

Browse files
authored
statistics: increase batchInsertSize from 10 to 8192 for improved performance (#60405) (#60414)
close #60183
1 parent 5902fb6 commit 02d0a6f

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

pkg/metrics/grafana/tidb.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17911,16 +17911,24 @@
1791117911
"expr": "histogram_quantile(0.99, sum(rate(tidb_statistics_stats_delta_update_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le))",
1791217912
"interval": "",
1791317913
"intervalFactor": 2,
17914-
"legendFormat": "99",
17914+
"legendFormat": "stats-meta-99",
1791517915
"queryType": "randomWalk",
1791617916
"refId": "A"
17917+
},
17918+
{
17919+
"exemplar": true,
17920+
"expr": "histogram_quantile(0.99, sum(rate(tidb_statistics_stats_usage_update_duration_seconds_bucket{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (le))",
17921+
"hide": false,
17922+
"interval": "",
17923+
"legendFormat": "stats-usage-99",
17924+
"refId": "B"
1791717925
}
1791817926
],
1791917927
"thresholds": [],
1792017928
"timeFrom": null,
1792117929
"timeRegions": [],
1792217930
"timeShift": null,
17923-
"title": "Stats Meta Updating Duration",
17931+
"title": "Stats Meta/Usage Updating Duration",
1792417932
"tooltip": {
1792517933
"shared": true,
1792617934
"sort": 0,

pkg/metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func RegisterMetrics() {
240240
prometheus.MustRegister(StatsHealthyGauge)
241241
prometheus.MustRegister(StatsDeltaLoadHistogram)
242242
prometheus.MustRegister(StatsDeltaUpdateHistogram)
243+
prometheus.MustRegister(StatsUsageUpdateHistogram)
243244
prometheus.MustRegister(TxnStatusEnteringCounter)
244245
prometheus.MustRegister(TxnDurationHistogram)
245246
prometheus.MustRegister(LastCheckpoint)

pkg/metrics/stats.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
StatsHealthyGauge *prometheus.GaugeVec
3535
StatsDeltaLoadHistogram prometheus.Histogram
3636
StatsDeltaUpdateHistogram prometheus.Histogram
37+
StatsUsageUpdateHistogram prometheus.Histogram
3738

3839
HistoricalStatsCounter *prometheus.CounterVec
3940
PlanReplayerTaskCounter *prometheus.CounterVec
@@ -162,4 +163,13 @@ func InitStatsMetrics() {
162163
Buckets: prometheus.ExponentialBuckets(0.01, 2, 24), // 10ms ~ 24h
163164
},
164165
)
166+
StatsUsageUpdateHistogram = NewHistogram(
167+
prometheus.HistogramOpts{
168+
Namespace: "tidb",
169+
Subsystem: "statistics",
170+
Name: "stats_usage_update_duration_seconds",
171+
Help: "Bucketed histogram of processing time for the background stats usage update job",
172+
Buckets: prometheus.ExponentialBuckets(0.01, 2, 24), // 10ms ~ 24h
173+
},
174+
)
165175
}

pkg/statistics/handle/usage/session_stats_collect.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ var (
4545
// dumpStatsMaxDuration is the max duration since last update.
4646
dumpStatsMaxDuration = 5 * time.Minute
4747

48-
// batchInsertSize is the batch size used by internal SQL to insert values to some system table.
49-
batchInsertSize = 10
48+
// batchInsertSize is the batch size used by internal SQL to insert values to stats usage table.
49+
batchInsertSize = 8192
5050
)
5151

5252
// needDumpStatsDelta checks whether to dump stats delta.
@@ -314,6 +314,11 @@ func (s *statsUsageImpl) dumpStatsDeltaToKV(
314314
// DumpColStatsUsageToKV sweeps the whole list, updates the column stats usage map and dumps it to KV.
315315
func (s *statsUsageImpl) DumpColStatsUsageToKV() error {
316316
defer util.Recover(metrics.LabelStats, "DumpColStatsUsageToKV", nil, false)
317+
start := time.Now()
318+
defer func() {
319+
dur := time.Since(start)
320+
metrics.StatsUsageUpdateHistogram.Observe(dur.Seconds())
321+
}()
317322
s.SweepSessionStatsList()
318323
colMap := s.SessionStatsUsage().GetUsageAndReset()
319324
defer func() {

0 commit comments

Comments
 (0)