fix: tweak read buffer size to reduce over-reading (#16338)

This commit is contained in:
Klaus Post 2023-01-01 17:14:20 +01:00 committed by GitHub
parent 49b3908635
commit 6a04067514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -1796,15 +1796,9 @@ func (s *xlStorage) ReadFileStream(ctx context.Context, volume, path string, off
}
or := &xioutil.ODirectReader{
File: file,
SmallFile: false,
}
if length <= smallFileThreshold {
or = &xioutil.ODirectReader{
File: file,
SmallFile: true,
}
File: file,
// Select bigger blocks when reading at least 50% of a big block.
SmallFile: length <= xioutil.BlockSizeLarge/2,
}
r := struct {

View File

@ -81,6 +81,10 @@ func ReadFile(name string) ([]byte, error) {
if err != nil {
return io.ReadAll(r)
}
// Select bigger blocks when reading at least 50% of a big block.
r.SmallFile = st.Size() <= BlockSizeLarge/2
dst := make([]byte, st.Size())
_, err = io.ReadFull(r, dst)
return dst, err