mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-10 01:05:14 +00:00
Reduce memory usage for chunked artifact uploads to MinIO (#31325)
When using the MinIO storage driver for Actions Artifacts, we found that the chunked artifact required significantly more memory usage to both upload and merge than the local storage driver. This seems to be related to hardcoding a value of `-1` for the size to the MinIO client [which has a warning about memory usage in the respective docs](https://pkg.go.dev/github.com/minio/minio-go/v7#Client.PutObject). Specifying the size in both the upload and merge case reduces memory usage of the MinIO client. Co-authored-by: Kyle D <kdumontnu@gmail.com> (cherry picked from commit 45dbeb5600d1f552c0134721fe49e8fd1099b5a4)
This commit is contained in:
parent
80357bbcb3
commit
1627d3a53f
|
@ -39,7 +39,7 @@ func saveUploadChunkBase(st storage.ObjectStorage, ctx *ArtifactContext,
|
||||||
r = io.TeeReader(r, hasher)
|
r = io.TeeReader(r, hasher)
|
||||||
}
|
}
|
||||||
// save chunk to storage
|
// save chunk to storage
|
||||||
writtenSize, err := st.Save(storagePath, r, -1)
|
writtenSize, err := st.Save(storagePath, r, contentSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, fmt.Errorf("save chunk to storage error: %v", err)
|
return -1, fmt.Errorf("save chunk to storage error: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -208,7 +208,7 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st
|
||||||
|
|
||||||
// save merged file
|
// save merged file
|
||||||
storagePath := fmt.Sprintf("%d/%d/%d.%s", artifact.RunID%255, artifact.ID%255, time.Now().UnixNano(), extension)
|
storagePath := fmt.Sprintf("%d/%d/%d.%s", artifact.RunID%255, artifact.ID%255, time.Now().UnixNano(), extension)
|
||||||
written, err := st.Save(storagePath, mergedReader, -1)
|
written, err := st.Save(storagePath, mergedReader, artifact.FileCompressedSize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("save merged file error: %v", err)
|
return fmt.Errorf("save merged file error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue