Skip to content
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

Some optimizations for uploading to minio #15255

Closed
wants to merge 2 commits into from

Conversation

lunny
Copy link
Member

@lunny lunny commented Apr 2, 2021

A fixed size to minio upload sdk may spend less memory than give it a -1. So let's give the size when possible.

close #15253

@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 2, 2021
@jochenhz
Copy link

jochenhz commented Apr 2, 2021

I can confirm that this PR fixes #15253
Thanks a lot! This was really important :)

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 2, 2021
@lunny lunny force-pushed the lunny/optimization_memory branch from e2c75e0 to a688671 Compare April 3, 2021 01:46
@lunny lunny added this to the 1.15.0 milestone Apr 3, 2021
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 3, 2021
@zeripath
Copy link
Contributor

zeripath commented Apr 3, 2021

I see a number of architectural issues with this approach.

I can understand why an argument polymorphism approach has been chosen instead of an explicit argument approach here and whilst I'm genuinely not sure it's the right thing - I think it's probably OK.

But I absolutely do not think that the ReadSizer interface should be outside of modules/storage - (whether the WithSize constructor function should be is another question.)

The ReadSizer interface should be within modules/storage and the documentation for the storage.Save function should refer to it explaining that if an io.Reader is passed that matches the interface storage.ReadSizer then the Size reported from that will be used.

Thus it's documented in one place and self contained. See https://github.com/golang/go/wiki/CodeReviewComments#interfaces

In terms of the WithSize constructor function - its name is not ideal - ReaderWithSize(...) would be better unless that function is going to end up in a reader specific module, e.g. : modules/ioutil/reader. (In which case the the git.LimitedReadCloser from modules/git/util.go should get moved there with a constructor WithLimitCloser(...)

But further everything that is using a ReadSizer has a direct dependency on storage anyway so you're just adding another module for no great reason. If we genuinely want to use this in places where there isn't a direct dependency on storage later on then we can move the ReaderWithSize(...) function into another module and lightly bind its interface dependence on storage through a test within modules/storage that uses it.

@zeripath
Copy link
Contributor

zeripath commented Apr 3, 2021

Actually this argument polymorphism is really going to be confusing:

Consider what happens if you pass a bufio.Reader into Save... to a cursory glance it looks like it implements ReadSizer but it doesn't - thankfully as its Size function means a very different thing.

We really should be implementing and using the io/fs interfaces but in the meantime just add a size argument to Save

zeripath added a commit to zeripath/gitea that referenced this pull request Apr 3, 2021
This PR proposes an alternative solution to go-gitea#15255 - just add the size to the
save function. Yes it is less apparently clean but it may be more correct.

Close go-gitea#15255
Fix go-gitea#15253

Signed-off-by: Andrew Thornton <[email protected]>
@lunny
Copy link
Member Author

lunny commented Apr 3, 2021

Actually this argument polymorphism is really going to be confusing:

Consider what happens if you pass a bufio.Reader into Save... to a cursory glance it looks like it implements ReadSizer but it doesn't - thankfully as its Size function means a very different thing.

We really should be implementing and using the io/fs interfaces but in the meantime just add a size argument to Save

Please send a PR to replace this one.

@lunny lunny closed this Apr 3, 2021
@lunny lunny deleted the lunny/optimization_memory branch April 3, 2021 12:08
@lunny lunny removed this from the 1.15.0 milestone Apr 3, 2021
zeripath added a commit to zeripath/gitea that referenced this pull request Apr 3, 2021
This PR proposes an alternative solution to go-gitea#15255 - just add the size to the
save function. Yes it is less apparently clean but it may be more correct.

Close go-gitea#15255
Fix go-gitea#15253

Signed-off-by: Andrew Thornton <[email protected]>
zeripath added a commit to zeripath/gitea that referenced this pull request Apr 3, 2021
Backport go-gitea#15264

This PR proposes an alternative solution to go-gitea#15255 - just add the size to the
save function. Yes it is less apparently clean but it may be more correct.

Close go-gitea#15255
Fix go-gitea#15253

Signed-off-by: Andrew Thornton <[email protected]>
techknowlogick pushed a commit that referenced this pull request Apr 4, 2021
Backport #15264

This PR proposes an alternative solution to #15255 - just add the size to the
save function. Yes it is less apparently clean but it may be more correct.

Close #15255
Fix #15253

Signed-off-by: Andrew Thornton <[email protected]>
techknowlogick pushed a commit that referenced this pull request Apr 4, 2021
This PR proposes an alternative solution to #15255 - just add the size to the
save function. Yes it is less apparently clean but it may be more correct.

Close #15255
Fix #15253

Signed-off-by: Andrew Thornton <[email protected]>

Co-authored-by: Lunny Xiao <[email protected]>
@6543 6543 removed backport/v1.13 type/enhancement An improvement of existing functionality lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 7, 2021
@go-gitea go-gitea locked and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

git LFS and storage type minio: Massive memory usage
5 participants