Skip to content

Commit

Permalink
Merge pull request pingcap#4 from PatrickNicholas/2020-hackathon
Browse files Browse the repository at this point in the history
store: make network cost threshold as a Variable
  • Loading branch information
zhangjinpeng87 authored Jan 16, 2021
2 parents 40d9bf5 + d5aba00 commit 5fc0756
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
15 changes: 10 additions & 5 deletions kv/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ type Variables struct {
// Pointer to SessionVars.Killed
// Killed is a flag to indicate that this query is killed.
Killed *uint32

// AdaptiveFollowerReadCostThreshold specifies the threshold of adpative follower local scan.
AdaptiveFollowerReadCostThreshold int
}

// NewVariables create a new Variables instance with default values.
func NewVariables(killed *uint32) *Variables {
return &Variables{
BackoffLockFast: DefBackoffLockFast,
BackOffWeight: DefBackOffWeight,
Killed: killed,
BackoffLockFast: DefBackoffLockFast,
BackOffWeight: DefBackOffWeight,
Killed: killed,
AdaptiveFollowerReadCostThreshold: DefAdaptiveFollowerReadThreshold,
}
}

Expand All @@ -45,6 +49,7 @@ var DefaultVars = NewVariables(&ignoreKill)

// Default values
const (
DefBackoffLockFast = 100
DefBackOffWeight = 2
DefAdaptiveFollowerReadThreshold = 4096
DefBackoffLockFast = 100
DefBackOffWeight = 2
)
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ var builtinGlobalVariable = []string{
variable.TiDBExecutorConcurrency,
variable.TiDBBackoffLockFast,
variable.TiDBBackOffWeight,
variable.TiDBAdaptiveFollowerReadThreshold,
variable.TiDBConstraintCheckInPlace,
variable.TiDBDDLReorgWorkerCount,
variable.TiDBDDLReorgBatchSize,
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error {
s.KVVars.BackoffLockFast = tidbOptPositiveInt32(val, kv.DefBackoffLockFast)
case TiDBBackOffWeight:
s.KVVars.BackOffWeight = tidbOptPositiveInt32(val, kv.DefBackOffWeight)
case TiDBAdaptiveFollowerReadThreshold:
s.KVVars.AdaptiveFollowerReadCostThreshold = tidbOptPositiveInt32(val, kv.DefAdaptiveFollowerReadThreshold)
case TiDBConstraintCheckInPlace:
s.ConstraintCheckInPlace = TiDBOptOn(val)
case TiDBBatchInsert:
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ var defaultSysVars = []*SysVar{
{Scope: ScopeGlobal | ScopeSession, Name: TiDBMemQuotaApplyCache, Value: strconv.Itoa(DefTiDBMemQuotaApplyCache)},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackoffLockFast, Value: strconv.Itoa(kv.DefBackoffLockFast), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBBackOffWeight, Value: strconv.Itoa(kv.DefBackOffWeight), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBAdaptiveFollowerReadThreshold, Value: strconv.Itoa(kv.DefAdaptiveFollowerReadCostThreshold), Type: TypeUnsigned, MinValue: 1, MaxValue: math.MaxUint64}
{Scope: ScopeGlobal | ScopeSession, Name: TiDBRetryLimit, Value: strconv.Itoa(DefTiDBRetryLimit), Type: TypeInt, MinValue: -1, MaxValue: math.MaxInt64},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBDisableTxnAutoRetry, Value: BoolToOnOff(DefTiDBDisableTxnAutoRetry), Type: TypeBool},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBConstraintCheckInPlace, Value: BoolToOnOff(DefTiDBConstraintCheckInPlace), Type: TypeBool},
Expand Down
3 changes: 3 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ const (
// Only positive integers can be accepted, which means that the maximum back off time can only grow.
TiDBBackOffWeight = "tidb_backoff_weight"

// tidb_adaptive_follower_read_threshold is used to determinate whether a scan request should adaptively read local follower.
TiDBAdaptiveFollowerReadThreshold = "tidb_adaptive_follower_read_threshold"

// tidb_ddl_reorg_worker_cnt defines the count of ddl reorg workers.
TiDBDDLReorgWorkerCount = "tidb_ddl_reorg_worker_cnt"

Expand Down
6 changes: 1 addition & 5 deletions store/tikv/coprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ import (
"go.uber.org/zap"
)

// CostThreshold marks the cost threshold to determine whether given request is
// a large scan request.
const CostThreshold = 64 * 1024 // 64KB

var (
tikvTxnRegionsNumHistogramWithCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("coprocessor")
tikvTxnRegionsNumHistogramWithBatchCoprocessor = metrics.TiKVTxnRegionsNumHistogram.WithLabelValues("batch_coprocessor")
Expand Down Expand Up @@ -884,7 +880,7 @@ func (worker *copIteratorWorker) handleTaskOnce(bo *Backoffer, task *copTask, ch
}
networkCost += worker.req.NetworkCostEstimater(&kvRange, worker.req.KeyRanges)
}
if networkCost > float64(CostThreshold) {
if networkCost > float64(worker.vars.AdaptiveFollowerReadCostThreshold) {
recommendLocalScan = true
}
}
Expand Down

0 comments on commit 5fc0756

Please sign in to comment.