aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-08-07 10:14:01 -0700
committerchrislu <chris.lu@gmail.com>2022-08-07 10:14:01 -0700
commit0aeec04c31ca8b559382eb7dfbdc09ccea6b9fe5 (patch)
tree6a2ca00dfabeb81deae77c5cac22d54af245076a
parent928d29af9ec56a7ddbc574d7127814433140b5f9 (diff)
downloadseaweedfs-0aeec04c31ca8b559382eb7dfbdc09ccea6b9fe5.tar.xz
seaweedfs-0aeec04c31ca8b559382eb7dfbdc09ccea6b9fe5.zip
quicker to adapt to pattern change
-rw-r--r--weed/filer/reader_pattern.go10
-rw-r--r--weed/mount/page_writer_pattern.go10
2 files changed, 16 insertions, 4 deletions
diff --git a/weed/filer/reader_pattern.go b/weed/filer/reader_pattern.go
index 38a51d788..e32f7fc2d 100644
--- a/weed/filer/reader_pattern.go
+++ b/weed/filer/reader_pattern.go
@@ -5,6 +5,8 @@ type ReaderPattern struct {
lastReadStopOffset int64
}
+const ModeChangeLimit = 3
+
// For streaming read: only cache the first chunk
// For random read: only fetch the requested range, instead of the whole chunk
@@ -17,9 +19,13 @@ func NewReaderPattern() *ReaderPattern {
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
if rp.lastReadStopOffset == offset {
- rp.isSequentialCounter++
+ if rp.isSequentialCounter < ModeChangeLimit {
+ rp.isSequentialCounter++
+ }
} else {
- rp.isSequentialCounter--
+ if rp.isSequentialCounter > -ModeChangeLimit {
+ rp.isSequentialCounter--
+ }
}
rp.lastReadStopOffset = offset + int64(size)
}
diff --git a/weed/mount/page_writer_pattern.go b/weed/mount/page_writer_pattern.go
index 1ec9c9d4c..1ebcc19eb 100644
--- a/weed/mount/page_writer_pattern.go
+++ b/weed/mount/page_writer_pattern.go
@@ -6,6 +6,8 @@ type WriterPattern struct {
chunkSize int64
}
+const ModeChangeLimit = 3
+
// For streaming write: only cache the first chunk
// For random write: fall back to temp file approach
// writes can only change from streaming mode to non-streaming mode
@@ -20,9 +22,13 @@ func NewWriterPattern(chunkSize int64) *WriterPattern {
func (rp *WriterPattern) MonitorWriteAt(offset int64, size int) {
if rp.lastWriteStopOffset == offset {
- rp.isSequentialCounter++
+ if rp.isSequentialCounter < ModeChangeLimit {
+ rp.isSequentialCounter++
+ }
} else {
- rp.isSequentialCounter--
+ if rp.isSequentialCounter > -ModeChangeLimit {
+ rp.isSequentialCounter--
+ }
}
rp.lastWriteStopOffset = offset + int64(size)
}