refactor: eliminate powermetrics temp file growth with in-memory buffer#4
Merged
Merged
Conversation
…lar buffer This refactoring eliminates the unbounded growth of temporary files at /tmp/all-smi_powermetrics_* by using a pipe-based approach with an in-memory circular buffer. Key changes: - Removed file-based output (-o/-u flags) in favor of stdout piping - Implemented circular buffer (VecDeque) to store last 120 powermetrics samples (2 minutes) - Added dedicated reader thread to process stdout lines without blocking - Removed all temporary file cleanup logic as it's no longer needed - Updated tests to work with the new buffer-based approach Benefits: - Zero disk usage - no more GB-sized temp files for long-running instances - Better performance - no file I/O overhead - More secure - no sensitive data written to disk - Cleaner cleanup - no sudo rm required for temp files The implementation handles all edge cases: - BufReader prevents stdout buffer deadlock - lines() iterator ensures complete line parsing - Process death detection and restart remain functional - Channel-based communication avoids lock contention
Added 10 new test cases covering: - Circular buffer limits and overflow protection - Reader thread line parsing and shutdown handling - Process info extraction from buffer - Multiple sections in buffer - Empty buffer fallback to cache - Malformed section handling - Concurrent buffer access - Process restart scenarios All tests pass, ensuring the pipe-based implementation is robust.
This was referenced Nov 22, 2025
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 refactors the PowerMetricsManager to use an in-memory circular buffer instead of writing to temporary files, eliminating the unbounded file growth issue where
/tmp/all-smi_powermetrics_*files would grow at ~7MB/hour for long-running instances.Problem
Solution
Implemented a pipe-based approach with in-memory circular buffer:
Benefits
Implementation Details
Test plan