-
Notifications
You must be signed in to change notification settings - Fork 73
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
Small buffer in io.Copy()
causes extremely slow S3 media download
#516
Comments
Even weirder, I cannot seem to reproduce this issue if I just write a simple Go program that package main
import (
"net/http"
"io"
)
func get(w http.ResponseWriter, r *http.Request) {
resp, _ := http.Get("<redacted>")
defer resp.Body.Close()
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", "11447735")
io.Copy(w, resp.Body)
}
func main() {
http.HandleFunc("/", get)
http.ListenAndServe("127.0.0.1:1234", nil)
} |
After some more digging around, it looks like this might actually be a It might take some refactoring upstream to avoid this behavior, but in the mean time maybe downstream can expose a larger / configurable buffer size as a workaround? |
io.Copy()
causes extremely slow S3 media downloadio.Copy()
causes extremely slow S3 media download
I have similar experience with matrix-media-repo on master and MinIO On master, download a relatively large image (1.7MB) estimated at around 40s:
After applying the provided patch it takes less than a sec:
|
Would be good to get a minimal test case set up using the minio library to demonstrate the issue. If that also has problems then this might be best to start upstream before engaging the relatively slower release process on MMR's end. |
I am currently looking into |
MMR does a pretty boring request to s3: |
@turt2live The culprit seems to be https://github.com/t2bot/go-singleflight-streams/blob/main/seeker.go#L70 It keeps calling https://github.com/minio/minio-go/blob/master/api-get-object.go#L591 Avoiding the |
Upstream fix minio/minio-go#1908 has been merged. Simply upgrading minio-go after the next release tag should resolve this issue. |
* Update compiled libheif version * Update dependencies * Update minio to fix stream performance Fixes #516 * Update Actions dependencies * Update Docker dependencies * Pin Alpine version throughout
Since a while back, I have been experiencing extremely poor download performance from my
matrix-media-repo
deployment. The download speed is so slow that most larger media files are barely viewable at all through most Matrix clients. I would see something likeOriginally I was blaming my own ad-hoc S3 cluster based on SeaweedFS, but after finally deciding to take a look into this issue, it seems that SeaweedFS itself was performing just fine. If I download the file directly from the S3 backend, from the server running
matrix-media-repo
itself,After some debugging, what I eventually concluded is that the problem seems to be
io.Copy()
. By simply increasing the size of the buffer, I was able to significantly increase the download speed. It looks like every call toRead
orWrite
involves some sort of high latency overhead that results in such a behavior. Note that my S3 server itself does have some access latency to thematrix-media-repo
server, but I wouldn't expect the latency to matter once the TCP stream is started.The patch I used to temporarily "fix" the issue is attached below.
The text was updated successfully, but these errors were encountered: