mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
quicker to adapt to pattern change
This commit is contained in:
parent
928d29af9e
commit
0aeec04c31
|
@ -5,6 +5,8 @@ type ReaderPattern struct {
|
||||||
lastReadStopOffset int64
|
lastReadStopOffset int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModeChangeLimit = 3
|
||||||
|
|
||||||
// For streaming read: only cache the first chunk
|
// For streaming read: only cache the first chunk
|
||||||
// For random read: only fetch the requested range, instead of the whole chunk
|
// For random read: only fetch the requested range, instead of the whole chunk
|
||||||
|
|
||||||
|
@ -17,10 +19,14 @@ func NewReaderPattern() *ReaderPattern {
|
||||||
|
|
||||||
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
|
||||||
if rp.lastReadStopOffset == offset {
|
if rp.lastReadStopOffset == offset {
|
||||||
|
if rp.isSequentialCounter < ModeChangeLimit {
|
||||||
rp.isSequentialCounter++
|
rp.isSequentialCounter++
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if rp.isSequentialCounter > -ModeChangeLimit {
|
||||||
rp.isSequentialCounter--
|
rp.isSequentialCounter--
|
||||||
}
|
}
|
||||||
|
}
|
||||||
rp.lastReadStopOffset = offset + int64(size)
|
rp.lastReadStopOffset = offset + int64(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ type WriterPattern struct {
|
||||||
chunkSize int64
|
chunkSize int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModeChangeLimit = 3
|
||||||
|
|
||||||
// For streaming write: only cache the first chunk
|
// For streaming write: only cache the first chunk
|
||||||
// For random write: fall back to temp file approach
|
// For random write: fall back to temp file approach
|
||||||
// writes can only change from streaming mode to non-streaming mode
|
// writes can only change from streaming mode to non-streaming mode
|
||||||
|
@ -20,10 +22,14 @@ func NewWriterPattern(chunkSize int64) *WriterPattern {
|
||||||
|
|
||||||
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
|
||||||
if rp.lastWriteStopOffset == offset {
|
if rp.lastWriteStopOffset == offset {
|
||||||
|
if rp.isSequentialCounter < ModeChangeLimit {
|
||||||
rp.isSequentialCounter++
|
rp.isSequentialCounter++
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if rp.isSequentialCounter > -ModeChangeLimit {
|
||||||
rp.isSequentialCounter--
|
rp.isSequentialCounter--
|
||||||
}
|
}
|
||||||
|
}
|
||||||
rp.lastWriteStopOffset = offset + int64(size)
|
rp.lastWriteStopOffset = offset + int64(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue