Repository navigation
fix(memory): cap metrics-db event size, add DB size limit, eliminate clone in log_metrics - #1678
Closed
Siddhant-K-code wants to merge 3 commits into
Closed
Siddhant-K-code wants to merge 3 commits into
Siddhant-K-code wants to merge 3 commits into
Conversation
…rics
Two targeted fixes for the memory/disk growth issue (PD-23):
1. Cap metrics-db row size (telemetry_worker.rs):
- Skip inserting events with serialized JSON > 256KB into the metrics DB.
- Large raw transcript events (avg 79KB, up to several MB) were causing
unbounded DB growth (2.4GB from 1.9GB of transcripts in our tests).
- Most useful telemetry events are 1-10KB; oversized ones provide no
proportional value and are now dropped with a debug log.
2. Eliminate .to_vec() clone in log_metrics (observability/mod.rs):
- log_metrics already takes Vec<MetricEvent> by value but was borrowing
chunks and cloning them back via .to_vec(), doubling peak memory.
- Now consumes the Vec via into_iter().take() to produce owned chunks
without any cloning.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Reduce MAX_METRIC_EVENT_JSON_BYTES from 256KB to 64KB: most useful telemetry events are 1-10KB; raw transcript events averaging 50-100KB are the primary source of DB bloat. - Add MAX_METRICS_DB_FILE_BYTES (512MB): stop inserting when the DB file exceeds this limit, preventing unbounded disk growth when metrics upload is unavailable. - Expose MetricsDatabase::db_path() for the file-size check. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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
Three targeted fixes for the memory/disk growth issue (PD-23, #1677):
1. Per-event size cap (
telemetry_worker.rs): Skip events with serialized JSON > 64KB before DB insertion. Raw transcript events (assistant responses with full file content) average 50-150KB and are the primary source of unbounded DB growth. Useful telemetry (committed values, agent usage, small session events) are 1-10KB and pass through unaffected.2. DB file size cap (
telemetry_worker.rs): Stop inserting whenmetrics-dbexceeds 512MB. Prevents unbounded disk growth when metrics upload is unavailable (no login, offline, API failures). Checked viastd::fs::metadatabefore each batch insert.3. Eliminate
.to_vec()clone (observability/mod.rs):log_metricsnow consumes theVec<MetricEvent>viainto_iter()instead of borrowing chunks and cloning them back. Eliminates doubling of peak memory during batch chunking.Validation Results
Measured via
/proc/<pid>/statusRSS polling at 500ms intervals, fresh daemon restart with synthetic Cursor transcript files.Controlled scenarios (uniform event size):
Realistic scenario (mixed sizes: 40% @1kb, 30% @5kb, 20% @30KB, 10% @150KB):
Side effects
.jsonlfiles on disk still contain the full content. All small/medium telemetry events (metadata, stats, tool usage) pass through unaffected.