Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(bigtable): Use RecvMsg instead of Recv #10674

Merged
merged 7 commits into from
Aug 28, 2024

Conversation

bhshkh
Copy link
Contributor

@bhshkh bhshkh commented Aug 12, 2024

ReadRows is streaming RPC. Currently, for each ReadRows a new message is allocated. This is causing high GCP bills and high memory usage.

m := new(ReadRowsResponse)
if err := x.ClientStream.RecvMsg(m); err != nil {

This PR changes this to use RecvMsg directly instead of Recv

pprof before:
Screenshot 2024-08-20 at 12 23 23 AM

pprof after (about ~13.25 % less memory usage):
Screenshot 2024-08-20 at 12 23 34 AM

RecvMsg uses proto.Unmarshal
Here, Merge is not set and thus unmarshal resets the message everytime before writing to it.

https://github.com/protocolbuffers/protobuf-go/blob/4fd828fdbf4719ded75c6f44681aea87a10968c2/proto/decode.go#L52-L59

https://github.com/protocolbuffers/protobuf-go/blob/4fd828fdbf4719ded75c6f44681aea87a10968c2/proto/decode.go#L89-L91

https://github.com/protocolbuffers/protobuf-go/blob/4fd828fdbf4719ded75c6f44681aea87a10968c2/proto/reset.go#L13-L16

@bhshkh bhshkh requested review from a team as code owners August 12, 2024 20:26
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the Bigtable API. label Aug 12, 2024
@bhshkh bhshkh requested a review from gkevinzheng August 12, 2024 20:28
@bhshkh bhshkh enabled auto-merge (squash) August 28, 2024 14:56
@bhshkh bhshkh merged commit 7e4fbc5 into googleapis:main Aug 28, 2024
8 of 10 checks passed
@bhshkh bhshkh deleted the perf/reuse-readrows branch August 28, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the Bigtable API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants