Skip to content

Commit

Permalink
fix: use shared gRPC buffers, lower buffer size
Browse files Browse the repository at this point in the history
As Discovery Service handles lots of connections with relatively low
traffic on each connection, lower the buffer size and re-use the
read/write buffers.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira committed May 28, 2024
1 parent a2217bd commit 196c609
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/discovery-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/experimental"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -192,6 +193,10 @@ func run(ctx context.Context, logger *zap.Logger) error {
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
MinTime: 10 * time.Second,
}),
grpc.SharedWriteBuffer(true),
experimental.RecvBufferPool(grpc.NewSharedBufferPool()),
grpc.ReadBufferSize(16 * 1024),
grpc.WriteBufferSize(16 * 1024),
}

state := state.NewState(logger)
Expand Down
5 changes: 5 additions & 0 deletions pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/experimental"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -98,6 +99,10 @@ func setupServer(t *testing.T, rateLimit rate.Limit, redirectEndpoint string) *t
server.AddLoggingFieldsStreamServerInterceptor(),
server.RateLimitStreamServerInterceptor(limiter),
),
grpc.SharedWriteBuffer(true),
experimental.RecvBufferPool(grpc.NewSharedBufferPool()),
grpc.ReadBufferSize(16 * 1024),
grpc.WriteBufferSize(16 * 1024),
}

testServer.s = grpc.NewServer(testServer.serverOptions...)
Expand Down

0 comments on commit 196c609

Please sign in to comment.