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

add multi block option for random read ahead #5673

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func dataCacheFlags() []cli.Flag {
Name: "max-readahead",
Usage: "max buffering for read ahead in MiB per read session",
},
&cli.IntFlag{
Name: "multi-block",
Usage: "number of blocks for random read ahead",
},
&cli.IntFlag{
Name: "prefetch",
Value: 1,
Expand Down
1 change: 1 addition & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ func getChunkConf(c *cli.Context, format *meta.Format) *chunk.Config {

GetTimeout: utils.Duration(c.String("get-timeout")),
PutTimeout: utils.Duration(c.String("put-timeout")),
MultiBlock: c.Int("multi-block"),
MaxUpload: c.Int("max-uploads"),
MaxStageWrite: c.Int("max-stage-write"),
MaxRetries: c.Int("io-retries"),
Expand Down
1 change: 1 addition & 0 deletions pkg/chunk/cached_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ type Config struct {
FreeSpace float32
AutoCreate bool
Compress string
MultiBlock int
MaxUpload int
MaxStageWrite int
MaxRetries int
Expand Down
12 changes: 11 additions & 1 deletion pkg/vfs/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,19 @@ func (f *fileReader) release() {
}
}

func (f *fileReader) readMargin(ahead, blklen uint64) uint64 {
if f.r.multiBlock == 0 ||
blklen * f.r.multiBlock > ahead + f.r.blockSize {
return ahead + f.r.blockSize
}
return blklen * f.r.multiBlock
}

func (f *fileReader) guessSession(block *frange) int {
idx := -1
var closestOff uint64
for i, ses := range f.sessions {
if ses.lastOffset > closestOff && ses.lastOffset <= block.off && block.off <= ses.lastOffset+ses.readahead+f.r.blockSize {
if ses.lastOffset > closestOff && ses.lastOffset <= block.off && block.off <= ses.lastOffset+f.readMargin(ses.readahead, block.len) {
idx = i
closestOff = ses.lastOffset
}
Expand Down Expand Up @@ -694,6 +702,7 @@ type dataReader struct {
m meta.Meta
store chunk.ChunkStore
files map[Ino]*fileReader
multiBlock uint64
blockSize uint64
bufferSize int64
readAheadMax uint64
Expand All @@ -715,6 +724,7 @@ func NewDataReader(conf *Config, m meta.Meta, store chunk.ChunkStore) DataReader
m: m,
store: store,
files: make(map[Ino]*fileReader),
multiBlock: uint64(conf.Chunk.MultiBlock),
blockSize: uint64(conf.Chunk.BlockSize),
bufferSize: int64(conf.Chunk.BufferSize),
readAheadTotal: uint64(readAheadTotal),
Expand Down
Loading