mount: improve read performance on random reads

This commit is contained in:
chrislu
2021-12-19 22:43:14 -08:00
parent 85c526c583
commit a152f17937
5 changed files with 66 additions and 7 deletions

View File

@@ -0,0 +1,31 @@
package filer
type ReaderPattern struct {
isStreaming bool
lastReadOffset int64
}
// For streaming read: only cache the first chunk
// For random read: only fetch the requested range, instead of the whole chunk
func NewReaderPattern() *ReaderPattern {
return &ReaderPattern{
isStreaming: true,
lastReadOffset: 0,
}
}
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
if rp.lastReadOffset > offset {
rp.isStreaming = false
}
rp.lastReadOffset = offset
}
func (rp *ReaderPattern) IsStreamingMode() bool {
return rp.isStreaming
}
func (rp *ReaderPattern) IsRandomMode() bool {
return !rp.isStreaming
}