mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-19 05:36:58 +00:00
* mount: cache supplementary group IDs to improve non-root access performance * mount: clear supplementary group cache between tests and add cache verification test * mount: add docstrings and benchmarks for supplementary group cache * mount: add performance test demonstrating cache effectiveness * mount: add TTL-based cache expiry for supplementary group IDs (5-minute refresh)
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package mount
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/seaweedfs/go-fuse/v2/fuse"
|
|
)
|
|
|
|
// BenchmarkCachedLookupSupplementaryGroupIDs measures cache hit performance.
|
|
func BenchmarkCachedLookupSupplementaryGroupIDs(b *testing.B) {
|
|
oldLookupSupplementaryGroupIDs := lookupSupplementaryGroupIDs
|
|
lookupSupplementaryGroupIDs = func(uid uint32) ([]string, error) {
|
|
return []string{"456", "789", "1011"}, nil
|
|
}
|
|
clearSupplementaryGroupCache()
|
|
defer func() {
|
|
lookupSupplementaryGroupIDs = oldLookupSupplementaryGroupIDs
|
|
clearSupplementaryGroupCache()
|
|
}()
|
|
|
|
cachedLookupSupplementaryGroupIDs(999)
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
cachedLookupSupplementaryGroupIDs(999)
|
|
}
|
|
}
|
|
|
|
// BenchmarkHasAccessPermissionCheck measures permission checks with the cache.
|
|
// Simulates repeated permission checks for the same user against different files.
|
|
func BenchmarkHasAccessPermissionCheck(b *testing.B) {
|
|
oldLookupSupplementaryGroupIDs := lookupSupplementaryGroupIDs
|
|
lookupSupplementaryGroupIDs = func(uid uint32) ([]string, error) {
|
|
return []string{"456", "789", "1011"}, nil
|
|
}
|
|
clearSupplementaryGroupCache()
|
|
defer func() {
|
|
lookupSupplementaryGroupIDs = oldLookupSupplementaryGroupIDs
|
|
clearSupplementaryGroupCache()
|
|
}()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
hasAccess(999, 999, 123, uint32(i%10), 0o040, fuse.R_OK|fuse.W_OK)
|
|
}
|
|
}
|