-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(all): add CLI flags for gRPC buffer management
This PR introduces new CLI flags to configure buffer management for the gRPC server and client: - `--grpc-server-recv-buffer-pool`: Use the gRPC server's shared buffer pool to parse incoming messages. If not set, the buffer pool will not be used. - `--grpc-server-shared-write-buffer`: Enable sharing the gRPC server's transport write buffer across connections. If not set, each connection will allocate its own write buffer. - `--grpc-client-recv-buffer-pool`: Use the gRPC client's shared buffer pool to parse incoming messages. If not set, the buffer pool will not be used. - `--grpc-client-shared-write-buffer`: Enable sharing the gRPC client's transport write buffer across connections. If not set, each connection will allocate its own write buffer. These flags allow users to fine-tune the memory usage and performance of the gRPC server and client by controlling buffer management. The shared receive buffer pool can reduce memory allocation overhead by reusing the buffer to parse incoming messages across multiple requests or streams. The shared write buffer enables multiple connections to use the same write buffer, reducing memory footprint when handling a large number of connections. By default, these optimizations are disabled to maintain the existing behavior and avoid potential issues in case of improper use. The new flags are added to the following binaries: - varlogsn - varlogmr - varlogadm Notes: - The default values for these flags may need to be adjusted based on performance testing results. - Additional monitoring and metrics for buffer usage could help tune these settings.
- Loading branch information
Showing
6 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
|
||
"github.com/urfave/cli/v2" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/experimental" | ||
|
||
"github.com/kakao/varlog/pkg/util/units" | ||
) | ||
|
@@ -32,6 +33,16 @@ var ( | |
return nil | ||
}, | ||
} | ||
// GRPCServerRecvBufferPool is a flag to use the gRPC server's shared buffer pool for parsing incoming messages. | ||
// | ||
// See: | ||
// - https://pkg.go.dev/google.golang.org/[email protected]/experimental#RecvBufferPool | ||
GRPCServerRecvBufferPool = &cli.BoolFlag{ | ||
Name: "grpc-server-recv-buffer-pool", | ||
Category: CategoryGRPC, | ||
EnvVars: []string{"GRPC_SERVER_RECV_BUFFER_POOL"}, | ||
Usage: "Use the gRPC server's shared buffer pool for parsing incoming messages. If not set, the buffer pool will not be used.", | ||
} | ||
// GRPCServerWriteBufferSize is a flag to set the gRPC server's write | ||
// buffer size for a single write syscall. | ||
// | ||
|
@@ -49,6 +60,17 @@ var ( | |
return nil | ||
}, | ||
} | ||
// GRPCServerSharedWriteBuffer is a flag to enable sharing gRPC server's transport write buffer across connections. | ||
// | ||
// See: | ||
// - https://pkg.go.dev/google.golang.org/grpc#WithSharedWriteBuffer | ||
// - https://github.com/grpc/grpc-go/pull/6309 | ||
GRPCServerSharedWriteBuffer = &cli.BoolFlag{ | ||
Name: "grpc-server-shared-write-buffer", | ||
Category: CategoryGRPC, | ||
EnvVars: []string{"GRPC_SERVER_SHARED_WRITE_BUFFER"}, | ||
Usage: "Enable sharing gRPC server's transport write buffer across connections. If not set, each connection will allocate its own write buffer.", | ||
} | ||
// GRPCServerMaxRecvMsgSize is a flag to set the maximum message size the server can receive. | ||
// | ||
// See: | ||
|
@@ -114,6 +136,16 @@ var ( | |
return nil | ||
}, | ||
} | ||
// GRPCClientRecvBufferPool is a flag to use the gRPC client's shared buffer pool for parsing incoming messages. | ||
// | ||
// See: | ||
// - https://pkg.go.dev/google.golang.org/grpc/experimental#WithRecvBufferPool | ||
GRPCClientRecvBufferPool = &cli.BoolFlag{ | ||
Name: "grpc-client-recv-buffer-pool", | ||
Category: CategoryGRPC, | ||
EnvVars: []string{"GRPC_CLIENT_RECV_BUFFER_POOL"}, | ||
Usage: "Use the gRPC client's shared buffer pool for parsing incoming messages. If not set, the buffer pool will not be used.", | ||
} | ||
// GRPCClientWriteBufferSize is a flag to set the gRPC client's write | ||
// buffer size for a single write syscall. | ||
// | ||
|
@@ -131,6 +163,17 @@ var ( | |
return nil | ||
}, | ||
} | ||
// GRPCClientSharedWriteBuffer is a flag to enable sharing gRPC client's transport write buffer across connections. | ||
// | ||
// See: | ||
// - https://pkg.go.dev/google.golang.org/grpc#WithSharedWriteBuffer | ||
// - https://github.com/grpc/grpc-go/pull/6309 | ||
GRPCClientSharedWriteBuffer = &cli.BoolFlag{ | ||
Name: "grpc-client-shared-write-buffer", | ||
Category: CategoryGRPC, | ||
EnvVars: []string{"GRPC_CLIENT_SHARED_WRITE_BUFFER"}, | ||
Usage: "Enable sharing gRPC client's transport write buffer across connections. If not set, each connection will allocate its own write buffer.", | ||
} | ||
// GRPCClientInitialConnWindowSize is a flag to set the gRPC client's initial window size for a connection. | ||
// | ||
// See: | ||
|
@@ -173,13 +216,17 @@ func ParseGRPCServerOptionFlags(c *cli.Context) (opts []grpc.ServerOption, _ err | |
} | ||
opts = append(opts, grpc.ReadBufferSize(int(readBufferSize))) | ||
} | ||
if c.IsSet(GRPCServerRecvBufferPool.Name) { | ||
opts = append(opts, experimental.RecvBufferPool(grpc.NewSharedBufferPool())) | ||
} | ||
if c.IsSet(GRPCServerWriteBufferSize.Name) { | ||
writeBufferSize, err := units.FromByteSizeString(c.String(GRPCServerWriteBufferSize.Name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
opts = append(opts, grpc.WriteBufferSize(int(writeBufferSize))) | ||
} | ||
opts = append(opts, grpc.SharedWriteBuffer(c.Bool(GRPCServerSharedWriteBuffer.Name))) | ||
if c.IsSet(GRPCServerMaxRecvMsgSize.Name) { | ||
maxRecvMsgSize, err := units.FromByteSizeString(c.String(GRPCServerMaxRecvMsgSize.Name)) | ||
if err != nil { | ||
|
@@ -212,13 +259,17 @@ func ParseGRPCDialOptionFlags(c *cli.Context) (opts []grpc.DialOption, err error | |
} | ||
opts = append(opts, grpc.WithReadBufferSize(int(readBufferSize))) | ||
} | ||
if c.IsSet(GRPCClientRecvBufferPool.Name) { | ||
opts = append(opts, experimental.WithRecvBufferPool(grpc.NewSharedBufferPool())) | ||
} | ||
if c.IsSet(GRPCClientWriteBufferSize.Name) { | ||
writeBufferSize, err := units.FromByteSizeString(c.String(GRPCClientWriteBufferSize.Name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
opts = append(opts, grpc.WithWriteBufferSize(int(writeBufferSize))) | ||
} | ||
opts = append(opts, grpc.WithSharedWriteBuffer(c.Bool(GRPCClientSharedWriteBuffer.Name))) | ||
if c.IsSet(GRPCClientInitialConnWindowSize.Name) { | ||
initialConnWindowSize, err := units.FromByteSizeString(c.String(GRPCClientInitialConnWindowSize.Name), 0, math.MaxInt32) | ||
if err != nil { | ||
|