Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#43381
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
xuyifangreeneyes authored and ti-chi-bot committed Apr 26, 2023
1 parent 3aa7f7e commit 5c799a0
Show file tree
Hide file tree
Showing 6 changed files with 436 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,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 @@ -423,6 +424,17 @@ type Performance struct {
IndexUsageSyncLease string `toml:"index-usage-sync-lease" json:"index-usage-sync-lease"`
GOGC int `toml:"gogc" json:"gogc"`
EnforceMPP bool `toml:"enforce-mpp" json:"enforce-mpp"`
=======

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 @@ -617,9 +629,25 @@ var defaultConf = Config{
MaxTxnTTL: defTiKVCfg.MaxTxnTTL, // 1hour
MemProfileInterval: "1m",
// TODO: set indexUsageSyncLease to 60s.
<<<<<<< HEAD
IndexUsageSyncLease: "0s",
GOGC: 100,
EnforceMPP: false,
=======
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 @@ -299,6 +299,15 @@ mem-profile-interval = "1m"
# 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
54 changes: 54 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ stores-refresh-interval = 30
enable-forwarding = true
[performance]
txn-total-size-limit=2000
<<<<<<< HEAD
=======
tcp-no-delay = false
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 @@ -246,6 +254,7 @@ spilled-file-encryption-method = "plaintext"
c.Assert(conf.Performance.TxnTotalSizeLimit, Equals, uint64(2000))
c.Assert(conf.AlterPrimaryKey, Equals, true)

<<<<<<< HEAD
c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
c.Assert(conf.TiKVClient.AsyncCommit.KeysLimit, Equals, uint(123))
c.Assert(conf.TiKVClient.AsyncCommit.TotalKeySizeLimit, Equals, uint64(1024))
Expand Down Expand Up @@ -282,6 +291,51 @@ spilled-file-encryption-method = "plaintext"
c.Assert(conf.EnableEnumLengthLimit, Equals, false)
c.Assert(conf.EnableForwarding, Equals, true)
c.Assert(conf.StoresRefreshInterval, Equals, uint64(30))
=======
require.Equal(t, "41s", conf.TiKVClient.CommitTimeout)
require.Equal(t, uint(123), conf.TiKVClient.AsyncCommit.KeysLimit)
require.Equal(t, uint64(1024), conf.TiKVClient.AsyncCommit.TotalKeySizeLimit)
require.Equal(t, uint(128), conf.TiKVClient.MaxBatchSize)
require.Equal(t, uint(6000), conf.TiKVClient.RegionCacheTTL)
require.Equal(t, int64(0), conf.TiKVClient.StoreLimit)
require.Equal(t, int64(8192), conf.TiKVClient.TTLRefreshedTxnSize)
require.Equal(t, uint(1000), conf.TokenLimit)
require.True(t, conf.EnableTableLock)
require.Equal(t, uint64(5), conf.DelayCleanTableLock)
require.Equal(t, uint64(10000), conf.SplitRegionMaxNum)
require.True(t, conf.RepairMode)
require.Equal(t, uint64(16), conf.TiKVClient.ResolveLockLiteThreshold)
require.Equal(t, uint32(200), conf.Instance.MaxConnections)
require.Equal(t, uint32(10), conf.TiDBMaxReuseChunk)
require.Equal(t, uint32(20), conf.TiDBMaxReuseColumn)
require.Equal(t, []string{"tiflash"}, conf.IsolationRead.Engines)
require.Equal(t, 3080, conf.MaxIndexLength)
require.Equal(t, 70, conf.IndexLimit)
require.Equal(t, uint32(4000), conf.TableColumnCountLimit)
require.True(t, conf.SkipRegisterToDashboard)
require.Equal(t, 3, len(conf.Labels))
require.Equal(t, "bar", conf.Labels["foo"])
require.Equal(t, "abc", conf.Labels["group"])
require.Equal(t, "dc-1", conf.Labels["zone"])
require.Equal(t, SpilledFileEncryptionMethodPlaintext, conf.Security.SpilledFileEncryptionMethod)
require.True(t, conf.DeprecateIntegerDisplayWidth)
require.False(t, conf.EnableEnumLengthLimit)
require.True(t, conf.EnableForwarding)
require.Equal(t, uint64(30), conf.StoresRefreshInterval)
require.Equal(t, uint(123), conf.PessimisticTxn.DeadlockHistoryCapacity)
require.True(t, conf.PessimisticTxn.DeadlockHistoryCollectRetryable)
require.True(t, conf.PessimisticTxn.PessimisticAutoCommit.Load())
require.Equal(t, "127.0.0.1:10100", conf.TopSQL.ReceiverAddress)
require.True(t, conf.Experimental.AllowsExpressionIndex)
require.Equal(t, uint(20), conf.Status.GRPCKeepAliveTime)
require.Equal(t, uint(10), conf.Status.GRPCKeepAliveTimeout)
require.Equal(t, uint(2048), conf.Status.GRPCConcurrentStreams)
require.Equal(t, 10240, conf.Status.GRPCInitialWindowSize)
require.Equal(t, 40960, conf.Status.GRPCMaxSendMsgSize)
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.WriteString(`
[log.file]
Expand Down
25 changes: 25 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,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 @@ -1172,14 +1173,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

0 comments on commit 5c799a0

Please sign in to comment.