Commit 28a8766
authored
[dynamic Instrumentation] DEBUG-2336 Add Concurrent Adaptive Cache (#6093)
## Summary of changes
This PR introduces a thread-safe, adaptive caching system that
automatically adjusts to system resources and usage patterns. The cache
implements both LRU (Least Recently Used) and LFU (Least Frequently
Used) eviction policies and features dynamic cleanup intervals based on
expiration patterns.
### Key Features
- Sliding Expiration: Items expire after a configurable period of
inactivity
- Adaptive Cleanup: Cleanup interval adjusts between 5-60 minutes based
on expiration patterns
- Resource Awareness: Automatically reduces capacity in low-resource
environments
- Thread Safety: All operations are protected by reader-writer locks for
concurrent access
## Implementation
#### Main cache implementation with:
- Automatic capacity adjustment (2048 default, 512 for low-resource
environments)
- Dynamic cleanup interval (300s-3600s) that adjusts based on expiration
patterns
- Thread-safe operations using reader-writer locks
- Hit rate tracking and monitoring
#### Eviction Policies:
- LRU: Uses LinkedList + Dictionary for O(1) access and eviction
- LFU: Implements frequency tracking with SortedDictionary for efficient
eviction
#### Environment Detection:
- Serverless environment detection (AWS Lambda, Azure Functions)
- Memory availability checking (Windows and Unix systems)
- Automatic capacity adjustment based on system resources
## Testing
- Basic operations (Add, TryGet, GetOrAdd)
- Eviction policy behavior (LRU and LFU)
- Thread safety with parallel operations
- Sliding expiration functionality
- Cleanup interval adaptation
- Resource-based capacity adjustment
- Hit rate calculation
- Proper disposal of resources1 parent 57b76ff commit 28a8766
File tree
16 files changed
+1896
-0
lines changed- tracer
- src
- Datadog.Trace.Trimming/build
- Datadog.Trace
- Debugger/Caching
- Util
- test/Datadog.Trace.Tests/Debugger/CacheTests
16 files changed
+1896
-0
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
589 | 589 | | |
590 | 590 | | |
591 | 591 | | |
| 592 | + | |
592 | 593 | | |
593 | 594 | | |
594 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
0 commit comments