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

Tracing keeps entire requests in memory, doesn’t truncate #695

Closed
stapelberg opened this issue May 21, 2016 · 10 comments
Closed

Tracing keeps entire requests in memory, doesn’t truncate #695

stapelberg opened this issue May 21, 2016 · 10 comments
Labels
P3 Type: Performance Performance improvements (CPU, network, memory, etc)

Comments

@stapelberg
Copy link

There’s a corresponding TODO (if I understood it correctly) at

// TODO(dsymonds): add stringifying info to codec, and limit how much we hold here?
, but I wanted to open an issue nevertheless, if only so that people can more easily subscribe to it.

Currently, when sending RPCs which contain lots of data (e.g. a scanned document page in https://github.com/stapelberg/scan2drive), grpc accumulates RAM (looking at the process’s resident set size after calling (runtime/debug).FreeOSMemory().

Looking at the /debug/requests page explains where the RAM goes: the messages are included in full in the trace contexts. This not only makes my browser unusable, but also wastes a lot of memory.

I think we should truncate these messages and retain only the truncated version.

@bdarnell
Copy link
Contributor

bdarnell commented Sep 6, 2016

+1. This is affecting CockroachDB. We occasionally send very large messages, which are getting held in GRPC for a long time if we have tracing enabled (these are the only requests to make it in to the larger time buckets, so they aren't getting flushed out by the more frequent smaller requests). We're going to turn tracing off for now, but I'd like to have finer-grained control of tracing. We've found the connection-level tracing very useful, but the message/stream-level tracing is less useful to us and much more expensive. I'd like to be able to turn off the logging of message bodies. (especially because they're often hidden behind [redacted] - it took me a while to realize that there was this hidden cost).

bdarnell added a commit to bdarnell/cockroach that referenced this issue Sep 6, 2016
This retains a subset of messages for display on /debug/requests, which
is very expensive for snapshots. Until we can be more selective about
what is retained in traces, we must disable tracing entirely.

See grpc/grpc-go#695
@iamqizhao
Copy link
Contributor

We are working with another team in Google on replacing the existing tracing. Stay tuned.

@bdarnell
Copy link
Contributor

Any update on this?

stapelberg added a commit to Debian/dcs that referenced this issue Mar 30, 2017
@hsaliak hsaliak added the Type: Performance Performance improvements (CPU, network, memory, etc) label May 17, 2017
@stapelberg
Copy link
Author

More than a year has passed. What’s the current status? Flying blind is killing one of my biggest motivations to use gRPC in the first place.

@dfawley
Copy link
Member

dfawley commented Sep 7, 2017

We recommend disabling tracing in gRPC (grpc.EnableTracing=false) and using the stats handlers to record this data instead. We would like to implement a library that provides integration with x/net/trace via the stats interface, but don't have the bandwidth to do this any time soon.

@dfawley dfawley added P3 Status: Help Wanted Type: Feature New features or improvements in behavior and removed Type: Performance Performance improvements (CPU, network, memory, etc) labels Sep 7, 2017
@dfawley dfawley removed their assignment Sep 7, 2017
@dfawley dfawley added P2 Type: Performance Performance improvements (CPU, network, memory, etc) and removed P3 Status: Help Wanted Type: Feature New features or improvements in behavior labels Sep 7, 2017
@dfawley
Copy link
Member

dfawley commented Sep 7, 2017

After more deliberation, we decided that truncating the messages should be easy and shouldn't be too controversial, so we will just do that for now and file a separate issue to track the implementation of tracing through the stats API.

@dfawley
Copy link
Member

dfawley commented Sep 8, 2017

...and after the first attempt in #1508, we realized it's very difficult to fix the memory usage problem. To truncate the message before storing it, we must first (s)print it -- but in most cases we'll never display the message, which is why the string method is evaluated lazily. The best I believe we can do without changing what we render in the tracing (e.g. omit the message contents) is to truncate the message when displaying it to protect the browser when it renders them. In theory we could truncate the binary-serialized message when storing it, but I don't believe the Go protobuf library handles truncated messages, so we wouldn't be able to render it in text form later if we did that.

We'll also be disabling tracing by default to prevent this problem from impacting users that don't actually need tracing.

#1509

@stapelberg
Copy link
Author

Thanks for looking into this!

In theory we could truncate the binary-serialized message when storing it, but I don't believe the Go protobuf library handles truncated messages, so we wouldn't be able to render it in text form later if we did that.

This is not what I observe: https://play.golang.org/p/u9xZoYLx6J results in:

2017/09/08 18:06:23 unexpected EOF
2017/09/08 18:06:23 res: {Path:[foo bar baz]}

i.e., proto.Unmarshal returns an error, but as a side-effect it also fills in the message as good as it can.

I think it’s safe to unmarshal a truncated message and display the result textually.

@dfawley
Copy link
Member

dfawley commented Sep 8, 2017

That's encouraging. So maybe the tracing implementation that is based on the stats handler interface can do something a little smarter. #1510

@dfawley
Copy link
Member

dfawley commented May 3, 2021

#1508 adds truncating of messages. #1510 should include reducing total allocations re: the previous 3 comments.

@dfawley dfawley closed this as completed May 3, 2021
@grpc grpc deleted a comment from stale bot May 3, 2021
dfawley pushed a commit to dfawley/grpc-go that referenced this issue Sep 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 Type: Performance Performance improvements (CPU, network, memory, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants