-
Notifications
You must be signed in to change notification settings - Fork 803
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
Reuse the byte buffer from GRPC response in the frontend. #4377
Reuse the byte buffer from GRPC response in the frontend. #4377
Conversation
This PR allow to reuse the GRPC byte buffer casted as a `io.Reader` in the http rountripper of the frontend. This way we don't have to copy the content from the reader into another buffer when reading the http response. I've been testing this with in Loki and this shows good memory saving (around 1GB). Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch, but I think it could be made easier to read.
func bodyBuffer(res *http.Response) ([]byte, error) { | ||
if buffer, ok := res.Body.(Buffer); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you put a comment on here, as this cast seems to be the key part.
pkg/querier/queryrange/util.go
Outdated
@@ -70,3 +70,7 @@ func DoRequests(ctx context.Context, downstream Handler, reqs []Request, limits | |||
|
|||
return resps, firstErr | |||
} | |||
|
|||
type Buffer interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is Buffer such a long way away from where it gets used?
Do you even need a type? interface { Bytes() []byte }
is pretty straightforward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can move it but I think it's nice to have the type so, Loki uses this package and can be used as documentation.
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
Thanks @bboreham I've made the change let me know . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
…ect#4377) * Reuse the byte buffer from GRPC response in the frontend. This PR allow to reuse the GRPC byte buffer casted as a `io.Reader` in the http rountripper of the frontend. This way we don't have to copy the content from the reader into another buffer when reading the http response. I've been testing this with in Loki and this shows good memory saving (around 1GB). Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Use safe cast Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> * Review feedback. Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com> Signed-off-by: Alvin Lin <alvinlin@amazon.com>
This PR allow to reuse the GRPC byte buffer casted as a
io.Reader
in the http roundtripper of the frontend.This way we don't have to copy the content from the reader into another buffer when reading the http response.
I've been testing this with in Loki and this shows good memory saving (~ 1.2GB).
Signed-off-by: Cyril Tovena cyril.tovena@gmail.com