Reuse the byte buffer from GRPC response in the frontend.#4377
Merged
pracucci merged 3 commits intoAug 26, 2021
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>
bboreham
reviewed
Jul 27, 2021
Contributor
bboreham
left a comment
There was a problem hiding this comment.
Great catch, but I think it could be made easier to read.
Comment on lines
+287
to
+288
| func bodyBuffer(res *http.Response) ([]byte, error) { | ||
| if buffer, ok := res.Body.(Buffer); ok { |
Contributor
There was a problem hiding this comment.
Can you put a comment on here, as this cast seems to be the key part.
| return resps, firstErr | ||
| } | ||
|
|
||
| type Buffer interface { |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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>
Contributor
Author
|
Thanks @bboreham I've made the change let me know . |
alvinlin123
pushed a commit
to ac1214/cortex
that referenced
this pull request
Jan 14, 2022
…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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR allow to reuse the GRPC byte buffer casted as a
io.Readerin 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