Skip to content

Commit

Permalink
perf(benchmark): use grpc.SharedBufferPool for grpc.DialOption
Browse files Browse the repository at this point in the history
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 committed Feb 28, 2024
1 parent 86a8155 commit d604b6f
Show file tree
Hide file tree
Showing 21 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/admin/mrmanager/manager_mock.go

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

1 change: 1 addition & 0 deletions internal/admin/replica_selector_mock.go

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

1 change: 1 addition & 0 deletions internal/admin/snmanager/manager_mock.go

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

1 change: 1 addition & 0 deletions internal/admin/snwatcher/snwatcher_mock.go

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

1 change: 1 addition & 0 deletions internal/admin/stats/repository_mock.go

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

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()),
))

Check warning on line 61 in internal/benchmark/loader.go

View check run for this annotation

Codecov / codecov/patch

internal/benchmark/loader.go#L59-L61

Added lines #L59 - L61 were not covered by tests
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions internal/reportcommitter/client_mock.go

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

1 change: 1 addition & 0 deletions internal/storagenode/client/management_client_mock.go

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

1 change: 1 addition & 0 deletions pkg/mrc/metadata_repository_client_mock.go

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

1 change: 1 addition & 0 deletions pkg/mrc/metadata_repository_management_client_mock.go

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

1 change: 1 addition & 0 deletions pkg/varlog/admin_mock.go

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

1 change: 1 addition & 0 deletions pkg/varlog/log_mock.go

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

1 change: 1 addition & 0 deletions pkg/varlog/log_stream_appender_mock.go

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

1 change: 1 addition & 0 deletions pkg/varlog/metadata_refresher_mock.go

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

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...)
})

Check warning on line 188 in pkg/varlog/options.go

View check run for this annotation

Codecov / codecov/patch

pkg/varlog/options.go#L185-L188

Added lines #L185 - L188 were not covered by tests
}

const (
defaultRetryCount = 3
)
Expand Down
1 change: 1 addition & 0 deletions pkg/varlog/replicas_retriever_mock.go

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

1 change: 1 addition & 0 deletions proto/admpb/admin_mock.go

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

1 change: 1 addition & 0 deletions proto/mrpb/mock/mrpb_mock.go

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

1 change: 1 addition & 0 deletions proto/snpb/mock/snpb_mock.go

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

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 d604b6f

Please sign in to comment.