support grpc's shard buffer pool (#1132)

Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
This commit is contained in:
Weizhen Wang 2024-01-24 17:57:47 +08:00 committed by GitHub
parent 99ea0d4d9b
commit f90605363e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -59,6 +59,8 @@ 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"`
// 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:"ggrpc-shared-buffer-pool"`
// 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"`
@ -125,6 +127,7 @@ func DefaultTiKVClient() TiKVClient {
GrpcKeepAliveTime: 10,
GrpcKeepAliveTimeout: 3,
GrpcCompressionType: "none",
GrpcSharedBufferPool: false,
CommitTimeout: "41s",
AsyncCommit: AsyncCommit{
// FIXME: Find an appropriate default limit.

View File

@ -69,6 +69,7 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/experimental"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/metadata"
)
@ -286,7 +287,9 @@ func (a *connArray) Init(addr string, security config.Security, idleNotify *uint
Timeout: time.Duration(keepAliveTimeout) * time.Second,
}),
}, opts...)
if cfg.TiKVClient.GrpcSharedBufferPool {
opts = append(opts, experimental.WithRecvBufferPool(grpc.NewSharedBufferPool()))
}
conn, err := a.monitoredDial(
ctx,
fmt.Sprintf("%s-%d", a.target, i),