From 8e2aa47aaaaa92091086d10c53f465c02c870a22 Mon Sep 17 00:00:00 2001 From: Liqi Geng Date: Fri, 22 Mar 2024 00:49:38 +0800 Subject: [PATCH] [Cherry-pick-to-6.1] Add grpc window size config and change the default value (#1247) Signed-off-by: gengliqi --- config/client.go | 20 ++++++++++++++------ internal/client/client.go | 10 ++-------- internal/locate/region_cache.go | 5 ++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/config/client.go b/config/client.go index 9341735035..9214f052c3 100644 --- a/config/client.go +++ b/config/client.go @@ -43,7 +43,9 @@ import ( const ( // 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. @@ -59,6 +61,10 @@ type TiKVClient struct { GrpcKeepAliveTimeout uint `toml:"grpc-keepalive-timeout" json:"grpc-keepalive-timeout"` // GrpcCompressionType is the compression type for gRPC channel: none or gzip. GrpcCompressionType string `toml:"grpc-compression-type" json:"grpc-compression-type"` + // 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 string `toml:"commit-timeout" json:"commit-timeout"` AsyncCommit AsyncCommit `toml:"async-commit" json:"async-commit"` @@ -118,11 +124,13 @@ type CoprocessorCache struct { // DefaultTiKVClient returns default config for TiKVClient. func DefaultTiKVClient() TiKVClient { return TiKVClient{ - GrpcConnectionCount: 4, - GrpcKeepAliveTime: 10, - GrpcKeepAliveTimeout: 3, - GrpcCompressionType: "none", - CommitTimeout: "41s", + GrpcConnectionCount: 4, + GrpcKeepAliveTime: 10, + GrpcKeepAliveTimeout: 3, + GrpcCompressionType: "none", + GrpcInitialWindowSize: DefGrpcInitialWindowSize, + GrpcInitialConnWindowSize: DefGrpcInitialConnWindowSize, + CommitTimeout: "41s", AsyncCommit: AsyncCommit{ // FIXME: Find an appropriate default limit. KeysLimit: 256, diff --git a/internal/client/client.go b/internal/client/client.go index c3e2bca5c7..17a9640709 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -87,12 +87,6 @@ const ( 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. const forwardMetadataKey = "tikv-forwarded-host" @@ -176,8 +170,8 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint ctx, addr, opt, - grpc.WithInitialWindowSize(GrpcInitialWindowSize), - grpc.WithInitialConnWindowSize(GrpcInitialConnWindowSize), + grpc.WithInitialWindowSize(cfg.TiKVClient.GrpcInitialWindowSize), + grpc.WithInitialConnWindowSize(cfg.TiKVClient.GrpcInitialConnWindowSize), grpc.WithUnaryInterceptor(unaryInterceptor), grpc.WithStreamInterceptor(streamInterceptor), grpc.WithDefaultCallOptions(callOptions...), diff --git a/internal/locate/region_cache.go b/internal/locate/region_cache.go index fdda805651..379c8b70c2 100644 --- a/internal/locate/region_cache.go +++ b/internal/locate/region_cache.go @@ -54,7 +54,6 @@ import ( "github.com/pkg/errors" "github.com/tikv/client-go/v2/config" tikverr "github.com/tikv/client-go/v2/error" - "github.com/tikv/client-go/v2/internal/client" "github.com/tikv/client-go/v2/internal/logutil" "github.com/tikv/client-go/v2/internal/retry" "github.com/tikv/client-go/v2/kv" @@ -2527,8 +2526,8 @@ func createKVHealthClient(ctx context.Context, addr string) (*grpc.ClientConn, h ctx, addr, opt, - grpc.WithInitialWindowSize(client.GrpcInitialWindowSize), - grpc.WithInitialConnWindowSize(client.GrpcInitialConnWindowSize), + grpc.WithInitialWindowSize(cfg.TiKVClient.GrpcInitialWindowSize), + grpc.WithInitialConnWindowSize(cfg.TiKVClient.GrpcInitialConnWindowSize), grpc.WithConnectParams(grpc.ConnectParams{ Backoff: backoff.Config{ BaseDelay: 100 * time.Millisecond, // Default was 1s.