github.com/cloudwego/kitex@v0.9.0/client/streamclient/grpc_option.go (about)

     1  /*
     2   * Copyright 2023 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package streamclient
    18  
    19  import (
    20  	"crypto/tls"
    21  
    22  	"github.com/cloudwego/kitex/client"
    23  	"github.com/cloudwego/kitex/pkg/remote/trans/nphttp2/grpc"
    24  )
    25  
    26  // WithGRPCConnPoolSize sets the value for the client connection pool size.
    27  func WithGRPCConnPoolSize(s uint32) Option {
    28  	return ConvertOptionFrom(client.WithGRPCConnPoolSize(s))
    29  }
    30  
    31  // WithGRPCWriteBufferSize determines how much data can be batched before writing
    32  // on the wire. The corresponding memory allocation for this buffer will be twice
    33  // the size to keep syscalls low. The default value for this buffer is 32KB.
    34  func WithGRPCWriteBufferSize(s uint32) Option {
    35  	return ConvertOptionFrom(client.WithGRPCWriteBufferSize(s))
    36  }
    37  
    38  // WithGRPCReadBufferSize lets you set the size of read buffer, this determines how
    39  // much data can be read at most for each read syscall.
    40  func WithGRPCReadBufferSize(s uint32) Option {
    41  	return ConvertOptionFrom(client.WithGRPCReadBufferSize(s))
    42  }
    43  
    44  // WithGRPCInitialWindowSize sets the value for initial window size on a grpc stream.
    45  // The lower bound for window size is 64K and any value smaller than that will be ignored.
    46  // It corresponds to the WithInitialWindowSize DialOption of gRPC.
    47  func WithGRPCInitialWindowSize(s uint32) Option {
    48  	return ConvertOptionFrom(client.WithGRPCInitialWindowSize(s))
    49  }
    50  
    51  // WithGRPCInitialConnWindowSize sets the value for initial window size on a connection of grpc.
    52  // The lower bound for window size is 64K and any value smaller than that will be ignored.
    53  // It corresponds to the WithInitialConnWindowSize DialOption of gRPC.
    54  func WithGRPCInitialConnWindowSize(s uint32) Option {
    55  	return ConvertOptionFrom(client.WithGRPCInitialConnWindowSize(s))
    56  }
    57  
    58  // WithGRPCMaxHeaderListSize returns a DialOption that specifies the maximum
    59  // (uncompressed) size of header list that the client is prepared to accept.
    60  // It corresponds to the WithMaxHeaderListSize DialOption of gRPC.
    61  func WithGRPCMaxHeaderListSize(s uint32) Option {
    62  	return ConvertOptionFrom(client.WithGRPCMaxHeaderListSize(s))
    63  }
    64  
    65  // WithGRPCKeepaliveParams returns a DialOption that specifies keepalive parameters for the
    66  // client transport. It corresponds to the WithKeepaliveParams DialOption of gRPC.
    67  func WithGRPCKeepaliveParams(kp grpc.ClientKeepalive) Option {
    68  	return ConvertOptionFrom(client.WithGRPCKeepaliveParams(kp))
    69  }
    70  
    71  // WithGRPCTLSConfig sets the TLS config for gRPC client.
    72  func WithGRPCTLSConfig(tlsConfig *tls.Config) Option {
    73  	return ConvertOptionFrom(client.WithGRPCTLSConfig(tlsConfig))
    74  }