Update metrics tracking and enhance cache eviction strategies
Release Tag / release (push) Successful in 34s
Release Tag / release (push) Successful in 34s
- Added metrics for bytes saved from cache to improve performance insights. - Updated cache eviction strategies in MemoryFS and DiskFS to include metrics tracking for hits and evictions. - Enhanced README.md with updated garbage collection algorithm descriptions and recommendations for cache usage. - Introduced new madviseSequential functionality for improved memory access hints on Unix systems. - Adjusted validation configuration in examples to better reflect realistic usage scenarios.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"s1d3sw1ped/steamcache2/steamcache/metrics"
|
||||
"s1d3sw1ped/steamcache2/vfs"
|
||||
"s1d3sw1ped/steamcache2/vfs/locks"
|
||||
"s1d3sw1ped/steamcache2/vfs/lru"
|
||||
@@ -33,6 +34,7 @@ type MemoryFS struct {
|
||||
keyLocks []sync.Map // Sharded lock pools for better concurrency
|
||||
LRU *lru.LRUList[*types.FileInfo]
|
||||
timeUpdater *types.BatchedTimeUpdate // Batched time updates for better performance
|
||||
metrics *metrics.Metrics
|
||||
}
|
||||
|
||||
// New creates a new MemoryFS
|
||||
@@ -55,6 +57,12 @@ func New(capacity int64) (*MemoryFS, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetMetrics allows the owner (SteamCache) to inject the metrics collector
|
||||
// so that per-tier hit and eviction counters can be recorded.
|
||||
func (m *MemoryFS) SetMetrics(met *metrics.Metrics) {
|
||||
m.metrics = met
|
||||
}
|
||||
|
||||
// Name returns the name of this VFS
|
||||
func (m *MemoryFS) Name() string {
|
||||
return "MemoryFS"
|
||||
@@ -209,6 +217,10 @@ func (m *MemoryFS) Open(key string) (io.ReadCloser, error) {
|
||||
// Use zero-copy approach - return reader that reads directly from buffer
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil {
|
||||
m.metrics.IncrementMemoryCacheHits()
|
||||
}
|
||||
|
||||
return &memoryReadCloser{
|
||||
buffer: buffer,
|
||||
offset: 0,
|
||||
@@ -344,6 +356,10 @@ func (m *MemoryFS) EvictLRU(bytesNeeded uint) uint {
|
||||
}
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil && evicted > 0 {
|
||||
m.metrics.IncrementEvictions()
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
@@ -395,6 +411,10 @@ func (m *MemoryFS) EvictBySize(bytesNeeded uint, ascending bool) uint {
|
||||
}
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil && evicted > 0 {
|
||||
m.metrics.IncrementEvictions()
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
@@ -442,6 +462,10 @@ func (m *MemoryFS) EvictFIFO(bytesNeeded uint) uint {
|
||||
}
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil && evicted > 0 {
|
||||
m.metrics.IncrementEvictions()
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
@@ -494,6 +518,10 @@ func (m *MemoryFS) EvictLFU(bytesNeeded uint) uint {
|
||||
}
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil && evicted > 0 {
|
||||
m.metrics.IncrementEvictions()
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
@@ -548,5 +576,9 @@ func (m *MemoryFS) EvictHybrid(bytesNeeded uint) uint {
|
||||
}
|
||||
}
|
||||
m.mu.Unlock()
|
||||
|
||||
if m.metrics != nil && evicted > 0 {
|
||||
m.metrics.IncrementEvictions()
|
||||
}
|
||||
return evicted
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user