-
Notifications
You must be signed in to change notification settings - Fork 79
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
Gzip response bodies #221
Comments
This is an interesting idea. In what situations would we expect the additional latency introduced by compress/decompress to be less than the transmission latency saved? I could imagine this would be most valuable on high-latency and/or low-bandwidth connections. Would you expect dropshot to ignore this for pre-compressed data such as jpg, png or pre-compressed js/css objects? |
Good point about images, it looks like the recommendation is not to gzip images because it doesn't make them smaller, and could in fact make them bigger. Same is true for pre-compressed (not only minified) static text assets. In that case we would need the server to know whether the asset being served is already compressed and pass through compressed files unmodified. Putting right I see people discussing thresholds for whether compression is worth it primarily in terms of response size. I thought of this issue because of potentially large responses like the serial console. Even on a fast connection, I think you're usually going to see a latency benefit from fast server-side compression. Bandwidth savings aside, off the top of my head I'd guess your download speed would have to be consistently faster than compression throughput to come out worse off in terms of latency. I see Google using gzip in GCP with dynamic JSON responses as small as 2 KB, though they may be concerned about bandwidth too. In short, the conventional wisdom seems to be that the latency trade pays off nearly all the time, or at least, even if your very fastest clients are slightly hurt by it, that's far outweighed by the gains for slower clients. This (old) article argues that it doesn't make sense to compress things smaller than a TCP packet, presumably because you're still waiting for the entire packet? (Out of my wheelhouse.) From what I can tell, people seem to like minimum size thresholds of around a few KB. It probably doesn't matter that much unless we expect to have a lot of tiny responses. Some useful links I found while looking around: https://stackoverflow.com/a/32454901/604986 |
Found an example from Tower of a nice way to handle precompressed assets by putting the compressed and uncompressed ones side by side.
Presumably for images you would have to use some kind |
While thinking about oxidecomputer/console#2029, it occurred to me gzip should be very effective at reducing the size of big lists due to all the repetition of keys. And boy is it. This is a real response from dogfood containing 127 disks.
A counterpoint here is that 55k is already so small that there is no point in compressing. However, if we want to be able to scale nicely to fetching 1000 things, we're talking 433k vs. 69k (assuming linear scaling of gzip size savings, which might be conservative), so it gets more plausible. |
I was thinking about this and with the new |
Yeah, the middleware pattern can be a nice fit for something like gzip, but we've explicitly avoided that pattern in Dropshot for the reasons mentioned here: For something like this I'd be tempted to just bake that functionality into Dropshot itself. |
No worries and I actually very much agree with your rationale but maybe there is a difference between a custom logic flow (Auth) and a generic HTTP operation like compression/CORS. I will leave that branch sitting there for anyone who needs to solve this problem as a vendoring + a quick copy-paste solution. |
Just testing with some data from the oxql query endpoint.
Individually not too bad, and we can probably optimise by selecting larger |
Substantially reduce response sizes by gzipping response body and adding
content-encoding: gzip
to headers. Probably simplest to make this configurable server-wide. This issue is inspired by me imagining a multi-MB response containing serial console contents.Potential extra features
accept-encoding: identity
request header by not compressing even if compression feature is turned on server-wideThe text was updated successfully, but these errors were encountered: