fix: reduce API test memory consumption from 8.26GB to 1.57GB (#8263)#9097
Conversation
|
Does this fix #8263? 🕺🏽 |
arielshaqed
left a comment
There was a problem hiding this comment.
Leaving to @nopcoder to review properly. Just preferences about one of the default values - which you should both feel free to ignore.
Overall this is really cool and exciting - looking forward to a faster api.test!!1!
pkg/api/serve_test.go
Outdated
|
|
||
| // Set minimal cache sizes for testing to reduce memory consumption | ||
| // Default production values are too large for test environments | ||
| viper.Set("committed.local_cache.size_bytes", 8*1024*1024) // 8MB instead of 1GB |
There was a problem hiding this comment.
| viper.Set("committed.local_cache.size_bytes", 8*1024*1024) // 8MB instead of 1GB | |
| viper.Set("committed.local_cache.size_bytes", 24*1024*1024) |
- Remove the comment - keeping it means we need to keep this file sync'ed up with defaults.go, and we won't do that.
- We'll anyway probably never hit this in a small test, but if we do - it will slow down the API test.
nopcoder
left a comment
There was a problem hiding this comment.
Thanks for you contribution! I like to merge this change, can you address ariel's comment (removing the comment about the default) and we'll merge it.
nopcoder
left a comment
There was a problem hiding this comment.
looks good - thanks, left a comment related to the lint errors.
pkg/pyramid/eviction.go
Outdated
| numCountersToUse = capacity / (1024 * 10) // ~100 counters per 10KB | ||
| if numCountersToUse < 1000 { | ||
| numCountersToUse = 1000 // Minimum threshold |
There was a problem hiding this comment.
set constants for the numbers with meaningful names, our lint rules don't like magic numbers.
…rse#8263) Addresses excessive memory usage in API tests that consumed >40GB virtual memory and >6GB resident memory, causing slower test execution. Root cause: Tests inherited production cache configurations (1GB local cache, 400MB SSTable cache) and ristretto's fixed 10M counter allocation created massive overhead for small test caches. Changes: - Set test-specific cache sizes (8MB local, 2MB SSTable) in serve_test.go - Scale ristretto counters adaptively based on cache capacity in eviction.go - Maintain full test functionality while reducing memory footprint by 81% Before: 8.26GB total allocation (6.7GB from ristretto caches) After: 1.57GB total allocation (50MB from ristretto caches) Tests: All controller tests pass with identical functionality
3a09dcb to
e2b728d
Compare
|
Thanks for the reviews! I've addressed both comments:
|
Memory Optimization Fix for API Tests - Issue #8263
API tests were consuming excessive memory (>40 GiB virtual, >6 GiB resident), causing slower test execution and reduced developer adoption.
RCA
Memory Profile Findings (Before Optimization)
ristretto.newCmRow: 4.5 GB (54.42%)ristretto.Bloom.Size: 2.2 GB (27.21%)Root Cause
Default Production Configuration in Tests: Tests were using production-level cache sizes:
committed.local_cache.size_bytes: 1 GB (default)committed.sstable.memory.cache_size_bytes: 400 MB (default)Ristretto Cache Overhead: The ristretto cache allocates 10 million counters regardless of actual cache capacity, creating massive memory overhead for test environments.
Multiple Cache Instances: Each test creates two pyramid filesystem caches:
Test Repetition: 50+ controller tests each calling
setupHandler()with fresh cache instances.Results
Memory Allocation Improvement
Ristretto Cache Impact
Testing
Verification
Fixes #8263