feat: implement signature caching to reduce CPU usage#422
Draft
feat: implement signature caching to reduce CPU usage#422
Conversation
Implement a high-performance signature caching system that dramatically reduces CPU utilization by caching expensive ring signature operations. Key features: - LRU cache with 100k entry capacity and 15-minute TTL matching session duration - Thread-safe implementation with in-flight computation tracking - Prevents duplicate work when multiple goroutines request same signature - Comprehensive Prometheus metrics for monitoring cache effectiveness - Expected 70-80% reduction in CPU usage for cryptographic operations The cache is particularly effective for: - Repeated requests within a session (eth_blockNumber, eth_gasPrice, etc.) - High-frequency polling patterns - Retry scenarios Memory usage: ~50-55MB at full capacity (100k entries)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements a signature caching system to address the CPU bottleneck identified in pprof analysis where ring signature operations were consuming 50% of CPU time.
Problem
Solution
Implemented a comprehensive signature caching system with:
Key Components
1. Signature Cache Implementation
protocol/shannon/signature_cache.go: Core caching logicSessionID + SupplierAddr + AppAddr + PayloadHash2. Integration with Signer
protocol/shannon/signer.goto use cache3. Prometheus Metrics
shannon_signature_cache_hits_total: Cache hit countershannon_signature_cache_misses_total: Cache miss counter with reasonsshannon_signature_cache_size: Current cache size gaugeshannon_signature_cache_evictions_total: Eviction counter by reasonshannon_signature_cache_compute_time_seconds: Computation time histogram4. Comprehensive Testing
Memory Usage
Testing
Next Steps (Future PRs)
Review Notes
This is a draft PR for initial review. The implementation is complete and tested. We should monitor cache hit rates in production to determine actual effectiveness.