Skip to content

Commit

Permalink
config: Revise SimpleLRUCache Configuration (pingcap#17532)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yisaer authored Jun 18, 2020
1 parent 2293925 commit de6b82e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 5 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ type Status struct {

// Performance is the performance section of the config.
type Performance struct {
MaxProcs uint `toml:"max-procs" json:"max-procs"`
MaxProcs uint `toml:"max-procs" json:"max-procs"`
// Deprecated: use ServerMemoryQuota instead
MaxMemory uint64 `toml:"max-memory" json:"max-memory"`
ServerMemoryQuota uint64 `toml:"server-memory-quota" json:"server-memory-quota"`
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 Down Expand Up @@ -603,6 +605,7 @@ var defaultConf = Config{
},
Performance: Performance{
MaxMemory: 0,
ServerMemoryQuota: 0,
TCPKeepAlive: true,
CrossJoin: true,
StatsLease: "3s",
Expand Down Expand Up @@ -714,6 +717,7 @@ var deprecatedConfig = map[string]struct{}{
"txn-local-latches": {},
"txn-local-latches.enabled": {},
"txn-local-latches.capacity": {},
"performance.max-memory": {},
"max-txn-time-use": {},
}

Expand Down
4 changes: 2 additions & 2 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ record-db-qps = false
# Max CPUs to use, 0 use number of CPUs in the machine.
max-procs = 0

# Max memory size to use, 0 use the total usable memory in the machine.
max-memory = 0
# Memory size quota for tidb server, 0 means unlimited
server-memory-quota = 0

# StmtCountLimit limits the max count of statement inside a transaction.
stmt-count-limit = 5000
Expand Down
2 changes: 1 addition & 1 deletion planner/core/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var (
PreparedPlanCacheCapacity uint = 100
// PreparedPlanCacheMemoryGuardRatio stores the global config "prepared-plan-cache-memory-guard-ratio".
PreparedPlanCacheMemoryGuardRatio = 0.1
// PreparedPlanCacheMaxMemory stores the max memory size defined in the global config "performance-max-memory".
// PreparedPlanCacheMaxMemory stores the max memory size defined in the global config "performance-server-memory-quota".
PreparedPlanCacheMaxMemory = *atomic2.NewUint64(math.MaxUint64)
)

Expand Down
10 changes: 5 additions & 5 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ func reloadConfig(nc, c *config.Config) {
// like config.GetGlobalConfig().OOMAction.
// These config items will become available naturally after the global config pointer
// is updated in function ReloadGlobalConfig.
if nc.Performance.MaxMemory != c.Performance.MaxMemory {
plannercore.PreparedPlanCacheMaxMemory.Store(nc.Performance.MaxMemory)
if nc.Performance.ServerMemoryQuota != c.Performance.ServerMemoryQuota {
plannercore.PreparedPlanCacheMaxMemory.Store(nc.Performance.ServerMemoryQuota)
}
if nc.Performance.CrossJoin != c.Performance.CrossJoin {
plannercore.AllowCartesianProduct.Store(nc.Performance.CrossJoin)
Expand Down Expand Up @@ -598,7 +598,7 @@ func setGlobalVars() {
if plannercore.PreparedPlanCacheMemoryGuardRatio < 0.0 || plannercore.PreparedPlanCacheMemoryGuardRatio > 1.0 {
plannercore.PreparedPlanCacheMemoryGuardRatio = 0.1
}
plannercore.PreparedPlanCacheMaxMemory.Store(cfg.Performance.MaxMemory)
plannercore.PreparedPlanCacheMaxMemory.Store(cfg.Performance.ServerMemoryQuota)
total, err := memory.MemTotal()
terror.MustNil(err)
if plannercore.PreparedPlanCacheMaxMemory.Load() > total || plannercore.PreparedPlanCacheMaxMemory.Load() <= 0 {
Expand All @@ -612,11 +612,11 @@ func setGlobalVars() {
domainutil.RepairInfo.SetRepairTableList(cfg.RepairTableList)
c := config.GetGlobalConfig()
executor.GlobalDiskUsageTracker.SetBytesLimit(c.TempStorageQuota)
if c.Performance.MaxMemory < 1 {
if c.Performance.ServerMemoryQuota < 1 {
// If MaxMemory equals 0, it means unlimited
executor.GlobalMemoryUsageTracker.SetBytesLimit(-1)
} else {
executor.GlobalMemoryUsageTracker.SetBytesLimit(int64(c.Performance.MaxMemory))
executor.GlobalMemoryUsageTracker.SetBytesLimit(int64(c.Performance.ServerMemoryQuota))
}
kvcache.GlobalLRUMemUsageTracker.AttachToGlobalTracker(executor.GlobalMemoryUsageTracker)
}
Expand Down

0 comments on commit de6b82e

Please sign in to comment.