Skip to content

Commit

Permalink
feat(client): add settings for gRPC client
Browse files Browse the repository at this point in the history
Previously, the client provided WithGRPCDialOptions to configure general gRPC client options.
However, it was challenging to use since there are so many options in gRPC, and hard for users to
know the necessary things.

This PR provides more specific options:

- WithGRPCReadBufferSize
- WithGRPCWriteBufferSize
- WithGRPCInitialConnWindowSize
- WithGRPCInitialWindowSize

It also sets up some options like MaxCallRecvMsgSize and MaxCallSendMsgSize. It uses math.MaxInt32
value for them. Varlog users are not necessarily taken into account the maximum message size limit.
  • Loading branch information
ijsong committed Jun 17, 2023
1 parent 64eae0b commit 917e5fc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 9 deletions.
9 changes: 4 additions & 5 deletions internal/varlogcli/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"

"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/pkg/varlog"
Expand Down Expand Up @@ -102,10 +101,10 @@ func appendInternal(mrAddrs []string, clusterID types.ClusterID, batchSize int,
func open(mrAddrs []string, clusterID types.ClusterID) (varlog.Log, error) {
ctx, cancel := context.WithTimeout(context.Background(), openTimeout)
defer cancel()
return varlog.Open(ctx, clusterID, mrAddrs, varlog.WithGRPCDialOptions(
grpc.WithReadBufferSize(4*1024*1024),
grpc.WithWriteBufferSize(4*1024*1024),
))
return varlog.Open(ctx, clusterID, mrAddrs,
varlog.WithGRPCReadBufferSize(4*1024*1024),
varlog.WithGRPCWriteBufferSize(4*1024*1024),
)
}

func scanLoop(ctx context.Context, vlog varlog.Log, ch chan<- []byte) error {
Expand Down
48 changes: 44 additions & 4 deletions pkg/varlog/options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package varlog

import (
"math"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -40,8 +41,13 @@ func defaultOptions() options {
logger: zap.NewNop(),
grpcDialOptions: []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithReadBufferSize(1 << 20),
grpc.WithWriteBufferSize(1 << 20),
grpc.WithDefaultCallOptions(
// They set the maximum message size the client can read and
// write. We use the `math.MaxInt32` for those values, which
// are the full size possible.
grpc.MaxCallRecvMsgSize(math.MaxInt32),
grpc.MaxCallSendMsgSize(math.MaxInt32),
),
},
}
}
Expand Down Expand Up @@ -134,9 +140,43 @@ func WithLogger(logger *zap.Logger) Option {
})
}

func WithGRPCDialOptions(grpcDialOptions ...grpc.DialOption) Option {
// WithGRPCReadBufferSize sets the size of the gRPC read buffer. Internally, it
// calls `google.golang.org/grpc.WithReadBufferSize`.
func WithGRPCReadBufferSize(bytes int) Option {
return newOption(func(opts *options) {
opts.grpcDialOptions = append(opts.grpcDialOptions, grpcDialOptions...)
opts.grpcDialOptions = append(opts.grpcDialOptions,
grpc.WithReadBufferSize(bytes),
)
})
}

// WithGRPCWriteBufferSize sets the size of the gRPC write buffer. Internally,
// it calls `google.golang.org/grpc.WithWriteBufferSize`.
func WithGRPCWriteBufferSize(bytes int) Option {
return newOption(func(opts *options) {
opts.grpcDialOptions = append(opts.grpcDialOptions,
grpc.WithWriteBufferSize(bytes),
)
})
}

// WithGRPCInitialConnWindowSize sets the initial window size on a connection.
// Internally, it calls `google.golang.org/grpc.WithInitialConnWindowSize`.
func WithGRPCInitialConnWindowSize(bytes int32) Option {
return newOption(func(opts *options) {
opts.grpcDialOptions = append(opts.grpcDialOptions,
grpc.WithInitialConnWindowSize(bytes),
)
})
}

// WithGRPCInitialWindowSize sets the initial window size on a stream.
// Internally, it calls `google.golang.org/grpc.WithInitialWindowSize`.
func WithGRPCInitialWindowSize(bytes int32) Option {
return newOption(func(opts *options) {
opts.grpcDialOptions = append(opts.grpcDialOptions,
grpc.WithInitialWindowSize(bytes),
)
})
}

Expand Down

0 comments on commit 917e5fc

Please sign in to comment.