Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: provide a option to wait for init stats to finish before providing service during startup (#43381) #43450

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ type Performance struct {
MaxMemory uint64 `toml:"max-memory" json:"max-memory"`
ServerMemoryQuota uint64 `toml:"server-memory-quota" json:"server-memory-quota"`
MemoryUsageAlarmRatio float64 `toml:"memory-usage-alarm-ratio" json:"memory-usage-alarm-ratio"`
<<<<<<< HEAD
StatsLease string `toml:"stats-lease" json:"stats-lease"`
StmtCountLimit uint `toml:"stmt-count-limit" json:"stmt-count-limit"`
FeedbackProbability float64 `toml:"feedback-probability" json:"feedback-probability"`
Expand All @@ -498,6 +499,17 @@ type Performance struct {
EnforceMPP bool `toml:"enforce-mpp" json:"enforce-mpp"`
StatsLoadConcurrency uint `toml:"stats-load-concurrency" json:"stats-load-concurrency"`
StatsLoadQueueSize uint `toml:"stats-load-queue-size" json:"stats-load-queue-size"`
=======

EnableLoadFMSketch bool `toml:"enable-load-fmsketch" json:"enable-load-fmsketch"`

LiteInitStats bool `toml:"lite-init-stats" json:"lite-init-stats"`

// If ForceInitStats is true, when tidb starts up, it doesn't provide service until init stats is finished.
// If ForceInitStats is false, tidb can provide service before init stats is finished. Note that during the period
// of init stats the optimizer may make bad decisions due to pseudo stats.
ForceInitStats bool `toml:"force-init-stats" json:"force-init-stats"`
>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))
}

// PlanCache is the PlanCache section of the config.
Expand Down Expand Up @@ -712,12 +724,28 @@ var defaultConf = Config{
CommitterConcurrency: defTiKVCfg.CommitterConcurrency,
MaxTxnTTL: defTiKVCfg.MaxTxnTTL, // 1hour
// TODO: set indexUsageSyncLease to 60s.
<<<<<<< HEAD
IndexUsageSyncLease: "0s",
GOGC: 100,
EnforceMPP: false,
PlanReplayerGCLease: "10m",
StatsLoadConcurrency: 5,
StatsLoadQueueSize: 1000,
=======
IndexUsageSyncLease: "0s",
GOGC: 100,
EnforceMPP: false,
PlanReplayerGCLease: "10m",
StatsLoadConcurrency: 5,
StatsLoadQueueSize: 1000,
AnalyzePartitionConcurrencyQuota: 16,
PlanReplayerDumpWorkerConcurrency: 1,
EnableStatsCacheMemQuota: false,
RunAutoAnalyze: true,
EnableLoadFMSketch: false,
LiteInitStats: false,
ForceInitStats: false,
>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))
},
ProxyProtocol: ProxyProtocol{
Networks: "",
Expand Down
9 changes: 9 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,15 @@ max-txn-ttl = 3600000
# If you find the CPU used by GC is too high or GC is too frequent and impact your business you can increase this value.
gogc = 100

<<<<<<< HEAD
=======
# Whether to use the lite mode of init stats.
lite-init-stats = false

# Whether to wait for init stats to finish before providing service during startup
force-init-stats = false

>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))
[proxy-protocol]
# PROXY protocol acceptable client networks.
# Empty string means disable PROXY protocol, * means all networks.
Expand Down
13 changes: 13 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ enable-forwarding = true
[performance]
txn-total-size-limit=2000
tcp-no-delay = false
<<<<<<< HEAD
=======
enable-load-fmsketch = true
plan-replayer-dump-worker-concurrency = 1
lite-init-stats = true
force-init-stats = true
>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))
[tikv-client]
commit-timeout="41s"
max-batch-size=128
Expand Down Expand Up @@ -328,6 +335,12 @@ grpc-max-send-msg-size = 40960
require.Equal(t, uint(2048), conf.Status.GRPCConcurrentStreams)
require.Equal(t, 10240, conf.Status.GRPCInitialWindowSize)
require.Equal(t, 40960, conf.Status.GRPCMaxSendMsgSize)
<<<<<<< HEAD
=======
require.True(t, conf.Performance.EnableLoadFMSketch)
require.True(t, conf.Performance.LiteInitStats)
require.True(t, conf.Performance.ForceInitStats)
>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))

err = f.Truncate(0)
require.NoError(t, err)
Expand Down
25 changes: 25 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ func (do *Domain) newOwnerManager(prompt, ownerKey string) owner.Manager {
return statsOwner
}

<<<<<<< HEAD
func (do *Domain) loadStatsWorker() {
defer util.Recover(metrics.LabelDomain, "loadStatsWorker", nil, false)
lease := do.statsLease
Expand All @@ -1337,14 +1338,38 @@ func (do *Domain) loadStatsWorker() {
do.wg.Done()
logutil.BgLogger().Info("loadStatsWorker exited.")
}()
=======
func (do *Domain) initStats() {
>>>>>>> 50dd8b40f1c (*: provide a option to wait for init stats to finish before providing service during startup (#43381))
statsHandle := do.StatsHandle()
defer func() {
close(statsHandle.InitStatsDone)
}()
t := time.Now()
err := statsHandle.InitStats(do.InfoSchema())
if err != nil {
logutil.BgLogger().Debug("init stats info failed", zap.Error(err))
} else {
logutil.BgLogger().Info("init stats info time", zap.Duration("take time", time.Since(t)))
}
}

func (do *Domain) loadStatsWorker() {
defer util.Recover(metrics.LabelDomain, "loadStatsWorker", nil, false)
lease := do.statsLease
if lease == 0 {
lease = 3 * time.Second
}
loadTicker := time.NewTicker(lease)
updStatsHealthyTicker := time.NewTicker(20 * lease)
defer func() {
loadTicker.Stop()
updStatsHealthyTicker.Stop()
logutil.BgLogger().Info("loadStatsWorker exited.")
}()
do.initStats()
statsHandle := do.StatsHandle()
var err error
for {
select {
case <-loadTicker.C:
Expand Down
Loading