Repository navigation
Description
Hi guys, finally finished my LFS implementation, so now comes my feature suggestion (as announced to an issue reply a while back)
Describe the issue
There is a good likelihood that binaries files compress well with gzip, and while the LFS client supports downloading the file gzip'ed (it advertises that to the objects server with the Accept-Encoding HTTP header) -- uploads are currently always done verbatim creating network traffic that could be optimized.
As far I realized, in case of the PUT in an upload there is no HTTP handshake from server to client where the former can tell the client what kind of content encoding it accepts, in case of the PUT the client sends the 'Content-Encoding' of it's choice and the server must either handle it or return an error (like 405). I suppose usually this is assumed to be agreed on between client and server in the context. So let's just do that.
Suggested solution
Since we have already a batch interface, I propose the possibility for the server in the batch answer to an upload to suggest the client other encoding it is cool with than verbatim. I see no reason not to simply reuse https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding as part of the batch answer.
In my demo implementation for a server this looks like this
resObj.actions =
{
upload:
{
href: 'https://' + req.headers.host + '/objects/' + lfData.handle,
header:
{
'Accept': 'application/vnd.git-lfs',
'Accept-Encoding': 'gzip, identity',
'Authorization': req.headers.authorization,
}
}
};
Reasonable requirements are likely:
- for backward compatibility, supporting identity encoding as server is always suggested.
- if 'Accept-Encoding' is missing in the upload answer, identity encoding is supposed to be implicit.
In the actual PUT request the client is suggested to use HTTP as per standardization in which case it can dictate the Content-Encoding (by setting respective HTTP header) which of course should follow the Accepted-Encoding of the server upload reply.
Additional context
Took me a while now to write the issue, since as previously stated I wanted to finish my LFS implementation before suggesting any improvement. It is here https://gitlab.com/csc1/gitengine similar to gitea or gitolite but in node.js instead of perl/go.
I implemented the suggestion already on server side, but couldn't test it out / didn't change the client side.
Having a standalone server in my opinion the most sensible way to store the objects is gzipped, since it likely saves disk space and the most likely down request is gzip supported download in which case I can just stream it directly. (I'm aware though more complicated cloud setups may need to store verbatim)
Activity
KalleOlaviNiemitalo commentedon May 20, 2022
Should that use
Accept-EncodingandContent-Encoding, orTEandTransfer-Encoding? I imagine the difference would matter for range requests.bk2204 commentedon May 20, 2022
Hey,
Thanks for this proposal. Are you suggesting that we overload the
Accept-Encodingheader provided by the server as an indication that it's safe to send encoded data when uploading? If so, that seems like it's not the right place to put that information.KalleOlaviNiemitalo commentedon May 20, 2022
git-lfs/docs/api/batch.md
Lines 146 to 147 in 74c2fca
Right, if the server puts
'Accept-Encoding': 'gzip, identity'in there, then that should mean the server is asking the client to addAccept-Encoding: gzip, identityto the request that the client sends to upload the file.axkibe commentedon May 20, 2022
In my opinion it's obviously Accept-Encoding, because the server is doing just the same, it tells the other side a list of encodings it can handle. Content-Encoding is the actual encoding used (which the client has to set in following the PUT request).
No, not overloading, it puts is as part of the JSON response to the batch API request, for simplicity I would just reuse the HTTP specification, but technically it's not part of HTTP. The client on the other hand when PUT'ing the data has to set the Content-Encoding value to the encoding it chose (or leave it empty when using verbatim like currently).
Oh you are right, it should not be part of the header field.
Sorry for the confusion, it should be part of the standard response header.
You are right, it shouldn't be in the header field but one level up. Then the clients uses that info to set Content-Encoding (and encode the content accordingly. (Setting Content-Encoding in the header field wouldn't be right too, since the client still should have choice from the list provided, while setting it, would give it no freedom, and would break backward compatibility (since older clients would just set it, but not actually encode it.)
KalleOlaviNiemitalo commentedon May 21, 2022
https://gitlab.com/csc1/gitengine does not appear to support https://tus.io/protocols/resumable-upload.html. Although it is not necessary to immediately implement compressed resumable uploads, I would like to have a clear plan for how it can be implemented in the future without making it unnecessarily different from basic uploads.
The tus.io protocol spec does not mention any of
Accept-Encoding,Content-Encoding,TE, orTransfer-Encoding.If
Content-Encodingis used, thenContent-Length,Upload-Length,Upload-Offset,Tus-Max-Size, andUpload-Checksumshould correspond to the compressed data, not the uncompressed data. That seems feasible to implement, provided that the client has compressed the whole file in advance and doesn't try to compress it during the upload.axkibe commentedon May 23, 2022
Thanks, yes to be honest I gave resumeabilty no thought so far. And yes it complicated things.
The basic idea is to mirror the HTTP download as much as possible, since I presume, here it all is pretty much solved. This also answers the question what Content-Length should be, the length of compressed data (as it is in a GET request) or unset in case it isn't known ahead.
Regarding Upload-Length, we don't know, since it's tus specific and they don't define it, maybe we should ask them what they think about encoded uploads.
About resuming with Content-Encoding, in HTTP GET/Download world the answer is as far I searched: one just don't. Here resumes are done with Download Ranges and they don't work with Content-Encoding other than verbatim. However, chunked Transfer-Encoding is used here in which case you can request missing chunks. I don't have an issue to have both as possible server reply, where the server announces in its batch reply what it can do on object upload, and the client picks what it likes.
In case of resuming gzip data, in my implementation it would be hard, as long the the offset is at or below the one received so far (since I store gzip content verbatim to disk) on the other hand I would have a harder time resuming identity uploads, since the storing immediately as gzip I would have to rerun a gzip stream through the data so far to get the compressor in the needed state to resume. (IMO for simplicity I would just write identity to a scratchpad and compress it after the upload is complete).
However to complicate things, and this has been discussed in using stored compressed data on client side #260 and I searched here somewhat as well, the LZ compression family is no bijective -- to use mathematical terms. Meaning different compressed file input data can have the same uncompressed output. (However, most given implentations are deterministic, that is they will always produce the same compressed data for the same uncompressed input as they don't call rand() or have parallel processing race conditions. Thus to be clear to resume a compressed upload, there may be an argument to use a oid/checksum on the compressed file as well, so not to mix up different encodings. On the other hand, in practical terms, as long the client software doesn't change it's not going to change and a server could simply check if the resulting length:oid is correct after the upload finished.
To be honest, I'm quite surprised how much we enter uncharted territory here, for me this was more of a quick and easy fix/addon. Should I open a ticked at "tus" (I guess here https://github.com/tus/tus-resumable-upload-protocol/issues ) to ask them what they opinion is on resumable content-encoding or transfer-encoding (I'm fine with both)
KalleOlaviNiemitalo commentedon May 23, 2022
Related:
axkibe commentedon May 24, 2022
The last point is the most important to me, Upload-Token, this elegantly eliminates all discussions about non bijective compression. One client is deterministic, and as long it uses the same Token to resume an upload everything will be fine.
Content-Length is by HTTP definition always the body length (thus in compressed case, the compressed data, and in resumed case, the remaining, compressed data).
Upload-Length, in the case of LFS in my opinion we don't care, we got the actual uncompressed length from the batch request anyway, I'd argue for compressed length, but since clients implementations may not bother to precalculate it, tus says:
Upload-Offset for any practical means would also be best in compressed data, considering in uncompressed that that could be in the bitstream putting it the middle a byte in compressed data, not practical feasible.
So in this regard, from a practical stand point, I don't see any issues with it, treat the compressed data just like a data object in it's own right. Also I'd suggest in the batch reply to hint to the client, if the server can handle resumes, but follow the tus protocol in the actual object upload (since contrary to my mini-implementation, the object server does not have to be the batch server at the same time)
bk2204 commentedon May 24, 2022
Instead of writing
Accept-Encoding: "gzip, identity"at that level, let's writeencodings: ["gzip", "identity"]there. All the other keys are downcase and that would make more sense, I think.axkibe commentedon May 25, 2022
Fair enough for me. I was thinking something similar. It wouldn't be bad to have it more distinguish that way from the HTTP protocol itself, since I confused it in the wrong part above as well.
However, there is still Content-Encoding vs. (chunked) Transfer-Encoding (which are different ways to do the same thing). While I'm totally okay with only supporting one of these, the API should think forward an object server may only offer one of these, or both to a client.
bk2204 commentedon May 25, 2022
I think I'd prefer that we specified that Transfer-Encoding is to be used in this case, since that's typically supported better here in this client.
KalleOlaviNiemitalo commentedon May 28, 2022
brandzstdhave been registered for Content-Encoding but not for Transfer-Encoding.