Add grpc window size config and change the default value

Signed-off-by: gengliqi <gengliqiii@gmail.com>
This commit is contained in:
Liqi Geng 2024-03-19 23:01:50 +08:00 committed by GitHub
parent 58ef395164
commit 44b2944b64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 18 deletions

View File

@ -44,7 +44,9 @@ import (
const ( const (
// DefStoreLivenessTimeout is the default value for store liveness timeout. // DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "1s" DefStoreLivenessTimeout = "1s"
DefGrpcInitialWindowSize = 1 << 27 // 128MiB
DefGrpcInitialConnWindowSize = 1 << 27 // 128MiB
) )
// TiKVClient is the config for tikv client. // TiKVClient is the config for tikv client.
@ -62,6 +64,10 @@ type TiKVClient struct {
GrpcCompressionType string `toml:"grpc-compression-type" json:"grpc-compression-type"` GrpcCompressionType string `toml:"grpc-compression-type" json:"grpc-compression-type"`
// GrpcSharedBufferPool is the flag to control whether to share the buffer pool in the TiKV gRPC clients. // GrpcSharedBufferPool is the flag to control whether to share the buffer pool in the TiKV gRPC clients.
GrpcSharedBufferPool bool `toml:"grpc-shared-buffer-pool" json:"grpc-shared-buffer-pool"` GrpcSharedBufferPool bool `toml:"grpc-shared-buffer-pool" json:"grpc-shared-buffer-pool"`
// GrpcInitialWindowSize is the value for initial window size on a stream.
GrpcInitialWindowSize int32 `toml:"grpc-initial-window-size" json:"grpc-initial-window-size"`
// GrpcInitialConnWindowSize is the value for initial window size on a connection.
GrpcInitialConnWindowSize int32 `toml:"grpc-initial-conn-window-size" json:"grpc-initial-conn-window-size"`
// CommitTimeout is the max time which command 'commit' will wait. // CommitTimeout is the max time which command 'commit' will wait.
CommitTimeout string `toml:"commit-timeout" json:"commit-timeout"` CommitTimeout string `toml:"commit-timeout" json:"commit-timeout"`
AsyncCommit AsyncCommit `toml:"async-commit" json:"async-commit"` AsyncCommit AsyncCommit `toml:"async-commit" json:"async-commit"`
@ -130,12 +136,14 @@ type CoprocessorCache struct {
// DefaultTiKVClient returns default config for TiKVClient. // DefaultTiKVClient returns default config for TiKVClient.
func DefaultTiKVClient() TiKVClient { func DefaultTiKVClient() TiKVClient {
return TiKVClient{ return TiKVClient{
GrpcConnectionCount: 4, GrpcConnectionCount: 4,
GrpcKeepAliveTime: 10, GrpcKeepAliveTime: 10,
GrpcKeepAliveTimeout: 3, GrpcKeepAliveTimeout: 3,
GrpcCompressionType: "none", GrpcCompressionType: "none",
GrpcSharedBufferPool: false, GrpcSharedBufferPool: false,
CommitTimeout: "41s", GrpcInitialWindowSize: DefGrpcInitialWindowSize,
GrpcInitialConnWindowSize: DefGrpcInitialConnWindowSize,
CommitTimeout: "41s",
AsyncCommit: AsyncCommit{ AsyncCommit: AsyncCommit{
// FIXME: Find an appropriate default limit. // FIXME: Find an appropriate default limit.
KeysLimit: 256, KeysLimit: 256,

View File

@ -90,12 +90,6 @@ const (
MaxWriteExecutionTime = ReadTimeoutShort - 10*time.Second MaxWriteExecutionTime = ReadTimeoutShort - 10*time.Second
) )
// Grpc window size
const (
GrpcInitialWindowSize = 1 << 30
GrpcInitialConnWindowSize = 1 << 30
)
// forwardMetadataKey is the key of gRPC metadata which represents a forwarded request. // forwardMetadataKey is the key of gRPC metadata which represents a forwarded request.
const forwardMetadataKey = "tikv-forwarded-host" const forwardMetadataKey = "tikv-forwarded-host"
@ -320,8 +314,8 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint
opts = append([]grpc.DialOption{ opts = append([]grpc.DialOption{
opt, opt,
grpc.WithInitialWindowSize(GrpcInitialWindowSize), grpc.WithInitialWindowSize(cfg.TiKVClient.GrpcInitialWindowSize),
grpc.WithInitialConnWindowSize(GrpcInitialConnWindowSize), grpc.WithInitialConnWindowSize(cfg.TiKVClient.GrpcInitialConnWindowSize),
grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithUnaryInterceptor(unaryInterceptor),
grpc.WithStreamInterceptor(streamInterceptor), grpc.WithStreamInterceptor(streamInterceptor),
grpc.WithDefaultCallOptions(callOptions...), grpc.WithDefaultCallOptions(callOptions...),

View File

@ -28,7 +28,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tikv/client-go/v2/config" "github.com/tikv/client-go/v2/config"
"github.com/tikv/client-go/v2/config/retry" "github.com/tikv/client-go/v2/config/retry"
"github.com/tikv/client-go/v2/internal/client"
"github.com/tikv/client-go/v2/internal/logutil" "github.com/tikv/client-go/v2/internal/logutil"
"github.com/tikv/client-go/v2/metrics" "github.com/tikv/client-go/v2/metrics"
"github.com/tikv/client-go/v2/tikvrpc" "github.com/tikv/client-go/v2/tikvrpc"
@ -734,8 +733,8 @@ func createKVHealthClient(ctx context.Context, addr string) (*grpc.ClientConn, h
ctx, ctx,
addr, addr,
opt, opt,
grpc.WithInitialWindowSize(client.GrpcInitialWindowSize), grpc.WithInitialWindowSize(cfg.TiKVClient.GrpcInitialWindowSize),
grpc.WithInitialConnWindowSize(client.GrpcInitialConnWindowSize), grpc.WithInitialConnWindowSize(cfg.TiKVClient.GrpcInitialConnWindowSize),
grpc.WithConnectParams(grpc.ConnectParams{ grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{ Backoff: backoff.Config{
BaseDelay: 100 * time.Millisecond, // Default was 1s. BaseDelay: 100 * time.Millisecond, // Default was 1s.