-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Avoid materializing uncompressed HTTP response before compression #73719
Comments
Pinging @elastic/es-distributed (Team:Distributed) |
We (the @elastic/es-distributed team) discussed this today and decided that this would be possible and desirable. We're not planning on doing this in the immediate future but hope to get to it eventually. |
This might be more desirable than previously thought #79560 ... at least it would give a bit of an out to make these APIs scale further than they do today by using compressing without any other API changes. |
I expect this doesn't apply to APIs using chunked encoding, right? With #89838 mostly done, I think this is good to close. |
I think it applies a little differently now and it would still be nice to handle this. Especially now that it's rather easy to do since we only have the Netty transport to deal with. It's true that we're not wasting as much memory on materialising a full response now with chunked and I think the memory aspect can be considered solved. |
It doesn't look that easy (to me) because Netty's |
I think you can just do this by manually compressing the content yourself and setting the content encoding header. |
Yeah that's pretty much the best idea I could see too but I would have preferred not to have to duplicate the logic that mucks around with the headers. |
Today when handling an HTTP request with
Accept-encoding: gzip
we will buffer the uncompressed response and then pass that over to Netty which takes responsibility for compressing it as it goes out over the wire. If the response is large and compressible then this means we consume substantially more memory than we theoretically need if we were to materialise the compressed bytes directly during serialisation.I found this when looking for performance differences between internal monitoring vs monitoring with Metricbeat. Internal monitoring sends bulk requests to another cluster over HTTP having streamed the body of each request directly into a compressed buffer (which it then uncompresses during transmission, because reasons). In contrast, when responding to requests made by Metricbeat today we prepare the whole response in an uncompressed buffer first and this would still be true if Metricbeat indicated it would accept a compressed response. This means that serving a large response to Metricbeat will require more memory than pushing the equivalent data out using the HTTP monitoring exporter.
Edit to add: arguably for non-performance-critical APIs that serve large responses we could consider always materializing the response into a compressed buffer and then optionally decompressing it during the transmission, if we felt that the memory savings were worth it. I'm thinking of things like
GET _stats?level=shards
,GET _cluster/state
andGET _mappings
here, I suspect we wouldn't want to do this for high traffic APIs likeGET _search
andPOST _bulk
because of the potential CPU and latency hit.The text was updated successfully, but these errors were encountered: