Refactor caching and memory management components
All checks were successful
Release Tag / release (push) Successful in 9s
All checks were successful
Release Tag / release (push) Successful in 9s
- Updated the caching logic to utilize a predictive cache warmer, enhancing content prefetching based on access patterns. - Replaced the legacy warming system with a more efficient predictive approach, allowing for better performance and resource management. - Refactored memory management to integrate dynamic cache size adjustments based on system memory usage, improving overall efficiency. - Simplified the VFS interface and improved concurrency handling with sharded locks for better performance in multi-threaded environments. - Enhanced tests to validate the new caching and memory management behaviors, ensuring reliability and performance improvements.
This commit is contained in:
28
vfs/locks/sharding.go
Normal file
28
vfs/locks/sharding.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package locks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Number of lock shards for reducing contention
|
||||
const NumLockShards = 32
|
||||
|
||||
// GetShardIndex returns the shard index for a given key using FNV-1a hash
|
||||
func GetShardIndex(key string) int {
|
||||
// Use FNV-1a hash for good distribution
|
||||
var h uint32 = 2166136261 // FNV offset basis
|
||||
for i := 0; i < len(key); i++ {
|
||||
h ^= uint32(key[i])
|
||||
h *= 16777619 // FNV prime
|
||||
}
|
||||
return int(h % NumLockShards)
|
||||
}
|
||||
|
||||
// GetKeyLock returns a lock for the given key using sharding
|
||||
func GetKeyLock(keyLocks []sync.Map, key string) *sync.RWMutex {
|
||||
shardIndex := GetShardIndex(key)
|
||||
shard := &keyLocks[shardIndex]
|
||||
|
||||
keyLock, _ := shard.LoadOrStore(key, &sync.RWMutex{})
|
||||
return keyLock.(*sync.RWMutex)
|
||||
}
|
||||
Reference in New Issue
Block a user