Skip to content

Commit

Permalink
perf(benchmark): use grpc.SharedBufferPool for grpc.DialOption (#718)
Browse files Browse the repository at this point in the history
### What this PR does

When a client library parses incoming gRPC messages, it allocates new buffers
frequently. This can result in the creation of a large number of heap objects.
However, gRPC offers an experimental feature called the shared buffer pool that
can be used to address this issue.

This pull request (PR) aims to optimize the gRPC receiving path using the shared
buffer pool. Various experiments have shown that this optimization leads to a
decrease in CPU time of runtime.gcBgMarkWorkers, depending on the workload.

Since the shared buffer pool is experimental, it is applied only to the
benchmark.

Refs:

- <https://pkg.go.dev/google.golang.org/[email protected]/experimental#WithRecvBufferPool>
- <https://pkg.go.dev/google.golang.org/[email protected]#SharedBufferPool>
  • Loading branch information
ijsong authored Mar 5, 2024
2 parents 31dfe88 + 8014ece commit fbf0c17
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/benchmark/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"go.uber.org/multierr"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/experimental"

"github.com/kakao/varlog/pkg/types"
"github.com/kakao/varlog/pkg/varlog"
Expand Down Expand Up @@ -54,7 +56,9 @@ func NewLoader(cfg loaderConfig) (loader *Loader, err error) {
if scli != nil {
return scli, nil
}
cli, err := varlog.Open(context.TODO(), loader.cid, loader.mraddrs)
cli, err := varlog.Open(context.TODO(), loader.cid, loader.mraddrs, varlog.WithGRPCDialOptions(
experimental.WithRecvBufferPool(grpc.NewSharedBufferPool()),
))
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/varlog/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ func WithGRPCInitialWindowSize(bytes int32) Option {
})
}

// WithGRPCDialOptions sets the grpc dial options.
// See `google.golang.org/grpc.DialOption`.
func WithGRPCDialOptions(grpcDialOptions ...grpc.DialOption) Option {
return newOption(func(opts *options) {
opts.grpcDialOptions = append(opts.grpcDialOptions, grpcDialOptions...)
})
}

const (
defaultRetryCount = 3
)
Expand Down
65 changes: 65 additions & 0 deletions vendor/google.golang.org/grpc/experimental/experimental.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ google.golang.org/grpc/credentials/insecure
google.golang.org/grpc/encoding
google.golang.org/grpc/encoding/gzip
google.golang.org/grpc/encoding/proto
google.golang.org/grpc/experimental
google.golang.org/grpc/grpclog
google.golang.org/grpc/health
google.golang.org/grpc/health/grpc_health_v1
Expand Down

0 comments on commit fbf0c17

Please sign in to comment.