Skip to content

Commit

Permalink
feat: make zero-copy GetObject possible via sendfile
Browse files Browse the repository at this point in the history
From #919, This provides the *os.File handle to io.Copy() for the
case where the full file range is requested. This prevents hiding
the *os.File type for io.Copy() optimizations.

This still requires the change to valyala/fasthttp#1889 to expose
the net.Conn similarly to enable the linux sendfile optimization.
  • Loading branch information
lunixbochs authored and benmcclelland committed Oct 28, 2024
1 parent a53667c commit e7a6ce2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/posix/posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2931,7 +2931,12 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
return nil, fmt.Errorf("open object: %w", err)
}

rdr := io.NewSectionReader(f, startOffset, length)
// using an os.File allows zero-copy sendfile via io.Copy(os.File, net.Conn)
var body io.ReadCloser = f
if startOffset != 0 || length != objSize {
rdr := io.NewSectionReader(f, startOffset, length)
body = &backend.FileSectionReadCloser{R: rdr, F: f}
}

return &s3.GetObjectOutput{
AcceptRanges: &acceptRange,
Expand All @@ -2945,7 +2950,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
ContentRange: &contentRange,
StorageClass: types.StorageClassStandard,
VersionId: &versionId,
Body: &backend.FileSectionReadCloser{R: rdr, F: f},
Body: body,
}, nil
}

Expand Down

0 comments on commit e7a6ce2

Please sign in to comment.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy