Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ be interacting with the file system.`)
DummyIOCfg: newConfig.DummyIo,
IsTypeCacheDeprecated: newConfig.EnableTypeCacheDeprecation,
ImplicitDir: newConfig.ImplicitDirs,
EnableOptimizedMetadataCache: newConfig.MetadataCache.ExperimentalEnableOptimizedMetadataCache,
}
bm := gcsx.NewBucketManager(bucketCfg, storageHandle)

Expand Down
15 changes: 14 additions & 1 deletion internal/cache/lru/lru_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,21 @@ func TestMapCacheWorkloads(t *testing.T) {
alloc := getMemStats()
pureMem := alloc - baseMem
runtime.KeepAlive(pureCache)
runtime.KeepAlive(paths)

t.Logf("%-20s Heap Used: %10.2f MB\n", "MapLRU", float64(pureMem)/(1024*1024))

// 2. Pure RadixLRU
baseMemRadix := getMemStats()

radixCache := lru.NewRadixCache(capacity)
for _, p := range paths {
_, _ = radixCache.Insert(p, dummyValue{})
}
allocRadix := getMemStats()
pureMemRadix := allocRadix - baseMemRadix
runtime.KeepAlive(radixCache)
runtime.KeepAlive(paths)

t.Logf("%-20s Heap Used: %10.2f MB\n", "RadixLRU", float64(pureMemRadix)/(1024*1024))
}
}
15 changes: 13 additions & 2 deletions internal/cache/lru/lru_workload_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ func benchmarkErasePrefix(b *testing.B, cache lru.Cache, prefixMap map[string][]
}

i := 0
b.ResetTimer()
Comment thread
vedantdas-source marked this conversation as resolved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

b.Loop() resets the timer automatically on its first call. So we can remove it before b.Loop().

for b.Loop() {
b.StopTimer() // Timer must be running when b.Loop() evaluates, stop it for setup
prefix := prefixes[i%len(prefixes)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since prefix := prefixes[i%len(prefixes)] would take negligible time.

Can we do something like:

	i := 0
	for b.Loop() {
		// 2. TIMED: Erase prefix (Timer is RUNNING from b.Loop)
		prefix := prefixes[i%len(prefixes)]
		cache.EraseEntriesWithGivenPrefix(prefix)
		// 3. UNTIMED: Pause clock, restore erased keys, and restart timer for next iteration
		b.StopTimer()
		for _, key := range prefixMap[prefix] {
			cache.Insert(key, dummyValue{})
		}
		i++
		b.StartTimer() // Timer MUST be running when b.Loop() evaluates next!
	}


b.StartTimer()
cache.EraseEntriesWithGivenPrefix(prefix)
//reset the timer so that we only measure erasure time
b.StopTimer()
b.StopTimer() // Stop timer for cleanup

//restore the map
keysToRestore := prefixMap[prefix]
Expand All @@ -103,6 +104,7 @@ func benchmarkErasePrefix(b *testing.B, cache lru.Cache, prefixMap map[string][]
}

i++
b.StartTimer() // Restart timer before b.Loop() evaluates
}
}

Expand All @@ -116,14 +118,23 @@ func runBenchmarks(b *testing.B, name string, depth int) {
b.Run(name+"_MapLRU_Insert", func(b *testing.B) {
benchmarkInsert(b, lru.NewCache(capacity), keys)
})
b.Run(name+"_RadixLRU_Insert", func(b *testing.B) {
benchmarkInsert(b, lru.NewRadixCache(capacity), keys)
})

b.Run(name+"_MapLRU_Lookup", func(b *testing.B) {
benchmarkLookup(b, lru.NewCache(capacity), keys)
})
b.Run(name+"_RadixLRU_Lookup", func(b *testing.B) {
benchmarkLookup(b, lru.NewRadixCache(capacity), keys)
})

b.Run(name+"_MapLRU_ErasePrefix", func(b *testing.B) {
benchmarkErasePrefix(b, lru.NewCache(capacity), prefixMap, prefixes)
})
b.Run(name+"_RadixLRU_ErasePrefix", func(b *testing.B) {
benchmarkErasePrefix(b, lru.NewRadixCache(capacity), prefixMap, prefixes)
})
}

func BenchmarkLRU_Flat(b *testing.B) {
Expand Down
20 changes: 18 additions & 2 deletions internal/cache/metadata/statcache_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestStatCacheMemoryWorkloads(t *testing.T) {
for _, w := range workloads {
t.Logf("=== WORKLOAD: %s (%d files) ===", w, count)

// 1. StatCache
// 1. StatCache (Map)
paths := generatePaths(w, count)
baseMem := getMemStats()

Expand All @@ -93,8 +93,24 @@ func TestStatCacheMemoryWorkloads(t *testing.T) {
alloc := getMemStats()
pureMem := alloc - baseMem
runtime.KeepAlive(statCache)

t.Logf("%-20s Heap Used: %10.2f MB\n", "Map StatCache", float64(pureMem)/(1024*1024))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See if this can be converted to Table driven test or is it better to create 2 independent tests.
Also use AAA.

// 2. StatCache (Radix)
baseMemRadix := getMemStats()

sharedRadixCache := lru.NewRadixCache(capacity)
statRadixCache := metadata.NewStatCacheBucketView(sharedRadixCache, "")

for _, p := range paths {
statRadixCache.Insert(&gcs.MinObject{Name: p}, expiration)
}

allocRadix := getMemStats()
pureMemRadix := allocRadix - baseMemRadix
runtime.KeepAlive(statRadixCache)
runtime.KeepAlive(paths)

t.Logf("%-20s Heap Used: %10.2f MB\n", "StatCache", float64(pureMem)/(1024*1024))
t.Logf("%-20s Heap Used: %10.2f MB\n", "Radix StatCache", float64(pureMemRadix)/(1024*1024))
}
}
9 changes: 8 additions & 1 deletion internal/gcsx/bucket_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type BucketConfig struct {
IsTypeCacheDeprecated bool

ImplicitDir bool

EnableOptimizedMetadataCache bool
}

// BucketManager manages the lifecycle of buckets.
Expand All @@ -103,7 +105,12 @@ type bucketManager struct {
func NewBucketManager(config BucketConfig, storageHandle storage.StorageHandle) BucketManager {
var c lru.Cache
if config.StatCacheMaxSizeMB > 0 {
c = lru.NewCache(util.MiBsToBytes(config.StatCacheMaxSizeMB))
cacheSize := util.MiBsToBytes(config.StatCacheMaxSizeMB)
if config.EnableOptimizedMetadataCache {
c = lru.NewRadixCache(cacheSize)
} else {
c = lru.NewCache(cacheSize)
}
}

bm := &bucketManager{
Expand Down
Loading