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

*: Add sysvar tidb_tso_client_rpc_mode for setting TSO RPC concurrency #56292

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ require (
replace (
github.com/go-ldap/ldap/v3 => github.com/YangKeao/ldap/v3 v3.4.5-0.20230421065457-369a3bab1117
github.com/pingcap/tidb/pkg/parser => ./pkg/parser
github.com/tikv/pd/client => github.com/MyonKeminta/pd/client v0.0.0-20240925045805-0bfe9a69293d

// TODO: `sourcegraph.com/sourcegraph/appdash` has been archived, and the original host has been removed.
// Please remove these dependencies.
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8=
github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk=
github.com/MyonKeminta/pd/client v0.0.0-20240925045805-0bfe9a69293d h1:8HHuVEu7PvaTv5wx+m8RqY/X5X/7gd9q79lFb2iU17w=
github.com/MyonKeminta/pd/client v0.0.0-20240925045805-0bfe9a69293d/go.mod h1:uBHhxAM/SPCMabt483gI/pN/+JXIMKYXohK96s+PwT8=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
Expand Down Expand Up @@ -824,8 +826,6 @@ github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tikv/client-go/v2 v2.0.8-0.20240911041506-e7894a7b27ba h1:dwuuYqPYxU0xcv0bnDgT7I4btQ5c3joBG1HmNOhCTdo=
github.com/tikv/client-go/v2 v2.0.8-0.20240911041506-e7894a7b27ba/go.mod h1:4HDOAx8OXAJPtqhCZ03IhChXgaFs4B3+vSrPWmiPxjg=
github.com/tikv/pd/client v0.0.0-20240914083230-71f6f96816e9 h1:J9LChGMzo95eBrjE03NHITDWgxfPgskH+QrCnlW61/Y=
github.com/tikv/pd/client v0.0.0-20240914083230-71f6f96816e9/go.mod h1:uBHhxAM/SPCMabt483gI/pN/+JXIMKYXohK96s+PwT8=
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a h1:A6uKudFIfAEpoPdaal3aSqGxBzLyU8TqyXImLwo6dIo=
github.com/timakin/bodyclose v0.0.0-20240125160201-f835fa56326a/go.mod h1:mkjARE7Yr8qU23YcGMSALbIxTQ9r9QBVahQOBRfU460=
github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs=
Expand Down
18 changes: 18 additions & 0 deletions pkg/domain/domain_sysvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,24 @@ func (do *Domain) setPDClientDynamicOption(name, sVal string) error {
return err
}
variable.EnablePDFollowerHandleRegion.Store(val)
case variable.TiDBTSOClientRPCMode:
var concurrency int

switch sVal {
case variable.TSOClientRPCModeDefault:
concurrency = 1
case variable.TSOClientRPCModeParallel:
concurrency = 2
case variable.TSOClientRPCModeParallelFast:
concurrency = 4
default:
return variable.ErrWrongValueForVar.GenWithStackByArgs(name, sVal)
}

err := do.updatePDClient(pd.TSOClientRPCConcurrency, concurrency)
if err != nil {
return err
}
}
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,11 @@ var defaultSysVars = []*SysVar{
s.SharedLockPromotion = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBTSOClientRPCMode, Value: DefTiDBTSOClientRPCMode, Type: TypeEnum, PossibleValues: []string{TSOClientRPCModeDefault, TSOClientRPCModeParallel, TSOClientRPCModeParallelFast},
SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
return (*SetPDClientDynamicOption.Load())(TiDBTSOClientRPCMode, val)
},
},
}

// GlobalSystemVariableInitialValue gets the default value for a system variable including ones that are dynamically set (e.g. based on the store)
Expand Down
4 changes: 4 additions & 0 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ const (
// TiDBEnableLazyCursorFetch defines whether to enable the lazy cursor fetch. If it's `OFF`, all results of
// of a cursor will be stored in the tidb node in `EXECUTE` command.
TiDBEnableLazyCursorFetch = "tidb_enable_lazy_cursor_fetch"
// TiDBTSOClientRPCMode controls how the TSO client performs the TSO RPC requests. It internally controls the
// concurrency of the RPC. This variable provides an approach to tune the latency of getting timestamps from PD.
TiDBTSOClientRPCMode = "tidb_tso_client_rpc_mode"
)

// TiDB intentional limits
Expand Down Expand Up @@ -1560,6 +1563,7 @@ const (
DefTiDBEnableLazyCursorFetch = false
DefOptEnableProjectionPushDown = true
DefTiDBEnableSharedLockPromotion = false
DefTiDBTSOClientRPCMode = TSOClientRPCModeDefault
)

// Process global variables.
Expand Down
12 changes: 12 additions & 0 deletions pkg/sessionctx/variable/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ const (
OOMActionCancel = "CANCEL"
// OOMActionLog constants represents the valid action configurations for OOMAction "LOG".
OOMActionLog = "LOG"

// TSOClientRPCModeDefault is a choice of variable TiDBTSOClientRPCMode. In this mode, the TSO client sends batched
// TSO requests serially.
TSOClientRPCModeDefault = "DEFAULT"
// TSOClientRPCModeParallel is a choice of variable TiDBTSOClientRPCMode. In this mode, the TSO client tries to
// keep approximately 2 batched TSO requests running in parallel. This option tries to reduce the batch-waiting time
// by half, at the expense of about twice the amount of TSO RPC calls.
TSOClientRPCModeParallel = "PARALLEL"
// TSOClientRPCModeParallelFast is a choice of variable TiDBTSOClientRPCMode. In this mode, the TSO client tries to
// keep approximately 4 batched TSO requests running in parallel. This option tries to reduce the batch-waiting time
// by 3/4, at the expense of about 4 times the amount of TSO RPC calls.
TSOClientRPCModeParallelFast = "PARALLEL-FAST"
)

// Global config name list.
Expand Down