Skip to content

Commit

Permalink
store/tikv, config: config for grpc connection. (#5284)
Browse files Browse the repository at this point in the history
  • Loading branch information
disksing authored and coocood committed Dec 4, 2017
1 parent 0604183 commit 6ea7ae5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 7 deletions.
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Config struct {
PreparedPlanCache PreparedPlanCache `toml:"prepared-plan-cache" json:"prepared-plan-cache"`
OpenTracing OpenTracing `toml:"opentracing" json:"opentracing"`
ProxyProtocol ProxyProtocol `toml:"proxy-protocol" json:"proxy-protocol"`
TiKVClient TiKVClient `toml:"tikv-client" json:"tikv-client"`
}

// Log is the log section of config.
Expand Down Expand Up @@ -147,6 +148,13 @@ type ProxyProtocol struct {
HeaderTimeout int `toml:"header-timeout" json:"header-timeout"`
}

// TiKVClient is the config for tikv client.
type TiKVClient struct {
// GrpcConnectionCount is the max gRPC connections that will be established
// with each tikv-server.
GrpcConnectionCount int `toml:"grpc-connection-count" json:"grpc-connection-count"`
}

var defaultConf = Config{
Host: "0.0.0.0",
Port: 4000,
Expand Down Expand Up @@ -203,6 +211,9 @@ var defaultConf = Config{
},
Reporter: OpenTracingReporter{},
},
TiKVClient: TiKVClient{
GrpcConnectionCount: 16,
},
}

var globalConf = defaultConf
Expand Down
4 changes: 4 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,7 @@ log-spans = false

# LocalAgentHostPort instructs reporter to send spans to jaeger-agent at this address
local-agent-host-port = ""

[tikv-client]
# Max gRPC connections that will be established with each tikv-server.
grpc-connection-count = 16
17 changes: 10 additions & 7 deletions store/tikv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ import (
"google.golang.org/grpc"
)

// MaxConnectionCount is the max gRPC connections that will be established with
// each tikv-server.
var MaxConnectionCount = 16

// Timeout durations.
const (
maxConnectionNumber = 16
dialTimeout = 5 * time.Second
readTimeoutShort = 20 * time.Second // For requests that read/write several key-values.
ReadTimeoutMedium = 60 * time.Second // For requests that may need scan region.
ReadTimeoutLong = 150 * time.Second // For requests that may need scan region multiple times.
dialTimeout = 5 * time.Second
readTimeoutShort = 20 * time.Second // For requests that read/write several key-values.
ReadTimeoutMedium = 60 * time.Second // For requests that may need scan region.
ReadTimeoutLong = 150 * time.Second // For requests that may need scan region multiple times.

grpcInitialWindowSize = 1 << 30
grpcInitialConnWindowSize = 1 << 30
Expand All @@ -59,7 +62,7 @@ type connArray struct {
v []*grpc.ClientConn
}

func newConnArray(maxSize uint32, addr string) (*connArray, error) {
func newConnArray(maxSize int, addr string) (*connArray, error) {
a := &connArray{
index: 0,
v: make([]*grpc.ClientConn, maxSize),
Expand Down Expand Up @@ -155,7 +158,7 @@ func (c *rpcClient) createConnArray(addr string) (*connArray, error) {
array, ok := c.conns[addr]
if !ok {
var err error
array, err = newConnArray(maxConnectionNumber, addr)
array, err = newConnArray(MaxConnectionCount, addr)
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ func setGlobalVars() {
if plan.PreparedPlanCacheEnabled {
plan.PreparedPlanCacheCapacity = cfg.PreparedPlanCache.Capacity
}

if cfg.TiKVClient.GrpcConnectionCount > 0 {
tikv.MaxConnectionCount = cfg.TiKVClient.GrpcConnectionCount
}
}

func setupLog() {
Expand Down

0 comments on commit 6ea7ae5

Please sign in to comment.