Repository navigation
Gcs resume write - #1322
Gcs resume write#1322aibaars wants to merge 8 commits into
Conversation
Current coverage is
|
|
@aibaars Thanks for the great PR! A few concerns here:
If we can't make the above work, rather than using the resumable upload API, it might be better to use a logical file implementation. Each call to writestream would result in a single file that would be joined during Ultimately, I think we can make this work with resumable API, as the two APIs are somewhat similar (Registry V2 and google resumable upload). |
|
@stevvooe Performing the close operation on the first call to ReadStream would be possible. However, this only works if it is guaranteed that ReadStream is called soon after the last call to WriteStream, otherwise the upload session might expire and the file will simply never exist. In addition the sessions take 256KB of memory each, and having many of them dangling could take quite a bit of memory. As far as I know you cannot query the API for active sessions. Storing the sessions on GCS is a good solution. I thought about that myself, but for an initial version keeping them in memory was easier. Good point about 3. Calling ReadStream on an incomplete file won't work and would cause a 404 error, because the file does not exist until its complete contents is committed. Would be great if the storage driver does not assume that ReadStream can be called on partial uploads. You're right that both resumable API are fairly similar, however, it is quite tricky to make the two work together. Actually even more tricky than I expected. Hopefully you can give me a hand with this. The current implementation using composite objects are in essence quite similar to what you describe as logical files. The problem is that composite objects have some annoying restrictions and are a bit slow to create. |
|
@aibaars It sounds like a combination of a guaranteed call to
Just give the storage package a solid read through. I think we can shore this up to ensure that no reads need to happen on unfinished files. You'll have to dig around in the storage driver unit tests to relax this, but I think it is doable. |
|
@stevvooe I just realised that the |
|
@stevvooe @RichardScothern I always wondered why the test suite insisted on filling gaps with zeros instead of complaining about offsets that are larger than the file's length. Is this to support writing chunks out-of-order, so that if a chunk with a larger offset is written first a gap is made, which is filled by a later chunk with smaller offset? GCS does not support overwriting existing data. Resumable uploads are strictly append only, and normal blobs are completely immutable, so filling in a gap later is not possible. Would it be OK for the GCS driver to return an InvalidOffset error when the offset is larger than the file's length, instead of stupidly creating a gap which can never be filled? |
f4e2e77 to
3d3a348
Compare
|
@stevvooe I updated the PR. Now there is only one tweak to the test suite and no changes to the storage driver interface.
The upload sessions are now automatically closed on Move and ReadStream. I don't think this is a very pretty solution but it works, and does not require any changes to the storage driver interface. An alternative would be to add an extra parameter to the WriteStream function with either the content length of the file that is being uploaded (not sure if that number is know at the start of the upload) or a boolean flag indicating whether a chunk is the last one, so the driver knows whether to expect more calls to WriteStream. I think this would be a less intrusive change to the storage driver interface and does not require closing the streams in slightly surprising places.
I stored the upload sessions as files with a special content-type and the session uri and current offset as metadata. As a result they get automatically picked up by Delete so we get session cleaning for free. I am not sure what to do exactly about point 3. My preference would be to simply disallow creating gaps. |
|
@aibaars : do you have numbers re: this API and the rate-limited current implementation? I like the idea behind the change; I think it is relevant to other drivers (Azure look like it would benefit). |
There was a problem hiding this comment.
Go ahead and use a const block here:
const (
myConst = 1
myOtherConst = 2
)There was a problem hiding this comment.
Ah yes indeed, didn't know that was possible.
|
@aibaars Great work!
We actually designed the API to ensure that the client doesn't need to know the full content length before uploading content. This allows layer generation to be directly piped into the http request. The length is posted at the end of the upload and is part of the call to To fix number 3, you'll have to add or modify a test case to ensure that |
|
I’ll produce some numbers tomorrow or Monday. Good to hear you like the idea. If Azure would benefit too, then perhaps we could convince @stevvooe to accept a small extension to the storage driver interface ;-) For example an extra parameter to WriteStream indicating whether a chunk is the last, or an explicit CloseStream function, instead of having to deal with closing upload sessions in Move and ReadStream/ReadContent.
|
I'm coming around on this 😉. We just need to make sure the other drivers benefit from this change. |
|
cc @BrianBland |
19e3e0e to
3d41086
Compare
|
@RichardScothern I hadn't expected the performance difference to be over a factor 10. I guess Google Cloud Storage gradually degrades the allowed rate if you perform many of them. For example when appending only 100 chunks the difference is 69s for the old versus 33s for the implementation in this PR. A factor 2 is still a nice win though. The nice thing about the performance of the resumable upload is that it is predictable (ie 10 times more chunks takes 10 times longer). |
|
@aibaars I would think a 256KB chunk size would be a little small. Could you experiment with a larger chunksize to see how it affects performance? My guess 1MB-4MB would be optimal. |
|
@stevvooe I tried with chunks of 5MB and results are similar: and |
ebc5914 to
1f48e73
Compare
89b9d77 to
b9c0fcf
Compare
There was a problem hiding this comment.
This could be Sprint(s.offset), or better yet, strconv.FormatInt(s.offset, 10). It's just nice to avoid format strings and reflection when possible.
f183d02 to
9954686
Compare
|
@RichardScothern I improved WriteStream a bit and added comments, hopefully it is more readable now. |
beba424 to
a94e4fe
Compare
|
After reviewing the other storage drivers, it looks like having a In alphabetical order:
|
|
@BrianBland thanks for reviewing the other drivers. I agree I think it would make sense to allow a client to call WriteStream with an offset less than the current file size. In this case I would propose the semantics to be that the already content of the file is left unchanged, simply discarding the first (file_size - offset) of the chunk and only appending the remainder. This avoids having to "rewind" the digester (difficult or impossible to support). The ability to write chunks with a smaller offset make implementing the client easier. For example in case a putChunk operation fails due to network issues the data might actually have arrived on the storage but the client is unaware of that. It would be fine for the client to retry the putChunk call in an attempt to recover; there is no need for this to be considered an error. In case of "eventually consistent" storage, the client might be receive the a smaller file size when Stat is called. I think this PR is getting a bit long, so I'll split it in two. One for the addition of |
uploads are readable Signed-off-by: Arthur Baars <[email protected]>
a94e4fe to
7cea626
Compare
Signed-off-by: Arthur Baars <[email protected]>
…digested bytes is equal to the current file size Signed-off-by: Arthur Baars <[email protected]>
… call ReadStream on partial uploads Signed-off-by: Arthur Baars <[email protected]>
7cea626 to
f757c31
Compare
Signed-off-by: Arthur Baars <[email protected]>
Signed-off-by: Arthur Baars <[email protected]>
Signed-off-by: Arthur Baars <[email protected]>
… in case offset is larger than file size Signed-off-by: Arthur Baars <[email protected]>
f757c31 to
0e60d0b
Compare
|
Closing this for now. Will rebase and re-open when #1395 has been implemented. |
This PR changes the implementation of WriteStream to use Google's resumable upload api instead of using the compose operator to join parts of uploaded content. The problem with using the compose operation is that this operation has several limitations:
The Resumable upload api has some limitations:
The second point required some small changes to the test suite, as it assume in two places that partial data is available for download. The third point is a bit of a problem as there is (as far as I know) no way of telling whether a particular call to WriteStream is the last. This is solved by adding a new function CloseStream to the storage driver interface.
@stevvooe @RichardScothern