mount: improve read performance on random reads
This commit is contained in:
31
weed/filer/reader_pattern.go
Normal file
31
weed/filer/reader_pattern.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user