Skip to content

Commit 7335cd2

Browse files
authored
Merge pull request #4247 from balajiv113/grpc-optimise
Improve GPRC performance with optimised configs for client and server
2 parents 638f426 + 6190ed4 commit 7335cd2

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

pkg/guestagent/api/client/client.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ type GuestAgentClient struct {
2121

2222
func NewGuestAgentClient(dialFn func(ctx context.Context) (net.Conn, error)) (*GuestAgentClient, error) {
2323
opts := []grpc.DialOption{
24+
grpc.WithTransportCredentials(NewCredentials()),
25+
grpc.WithInitialWindowSize(512 << 20),
26+
grpc.WithInitialConnWindowSize(512 << 20),
27+
grpc.WithReadBufferSize(8 << 20),
28+
grpc.WithWriteBufferSize(8 << 20),
2429
grpc.WithDefaultCallOptions(
25-
grpc.MaxCallRecvMsgSize(math.MaxInt64),
26-
grpc.MaxCallSendMsgSize(math.MaxInt64),
30+
grpc.MaxCallRecvMsgSize(math.MaxInt32),
31+
grpc.MaxCallSendMsgSize(math.MaxInt32),
2732
),
2833
grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) {
2934
return dialFn(ctx)
3035
}),
31-
grpc.WithTransportCredentials(NewCredentials()),
3236
}
3337

3438
resolver.SetDefaultScheme("passthrough")

pkg/guestagent/api/server/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net"
99

1010
"google.golang.org/grpc"
11+
"google.golang.org/grpc/keepalive"
1112
"google.golang.org/protobuf/types/known/emptypb"
1213

1314
"github.com/lima-vm/lima/v2/pkg/guestagent"
@@ -16,7 +17,14 @@ import (
1617
)
1718

1819
func StartServer(lis net.Listener, guest *GuestServer) error {
19-
server := grpc.NewServer()
20+
server := grpc.NewServer(
21+
grpc.InitialWindowSize(512<<20),
22+
grpc.InitialConnWindowSize(512<<20),
23+
grpc.ReadBufferSize(8<<20),
24+
grpc.WriteBufferSize(8<<20),
25+
grpc.MaxConcurrentStreams(2048),
26+
grpc.KeepaliveParams(keepalive.ServerParameters{Time: 0, Timeout: 0, MaxConnectionIdle: 0}),
27+
)
2028
api.RegisterGuestServiceServer(server, guest)
2129
return server.Serve(lis)
2230
}

0 commit comments

Comments
 (0)