Prompt
Why are my metrics queries getting slower after compaction?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
Compaction can make metrics queries slower for a few common reasons, even though it usually helps storage efficiency overall.
Likely causes
-
Fewer but much larger files/blocks
- After compaction, data may be merged into larger chunks.
- If your query only needs a small time range, it may still have to scan a big compacted block.
- Large blocks can increase read amplification and disk I/O for selective queries.
-
Loss of “fresh” indexing or metadata granularity
- Before compaction, smaller files may let the query engine skip more data using file-level metadata.
- After compaction, that pruning can be less effective if the engine treats the merged file as one unit.
-
Compaction created less optimal sort order
- If the compacted data isn’t sorted the way your queries filter/group, queries may scan more rows.
- This is especially noticeable for label-based metrics queries.
-
Hot cache got invalidated
- Compaction rewrites data, so previously cached blocks/pages may no longer be usable.
- Right after compaction, queries can be slower until caches warm back up.
-
Resource contention from the compaction job
- If compaction is still running or recently ran, it may compete for:
- CPU
- disk bandwidth
- memory
- network I/O
- Queries can slow down even if the compacted data itself is better.
- If compaction is still running or recently ran, it may compete for:
-
Too aggressive compaction
- Over-compaction can reduce parallelism.
- With too few large objects, the query engine has fewer pieces to read in parallel.
-
Query planner changes
- The engine may choose a different plan after compaction because stats, file counts, or partition layout changed.
- Sometimes the new plan is worse for your workload.
-
Compression tradeoff
- Compaction often increases compression ratio.
- Better compression means less storage, but decompression can cost more CPU, which may slow query latency if CPU-bound.
What to check
- Compare query latency before/after compaction for:
- small time ranges
- wide time ranges
- highly selective label filters
- Look at whether compaction:
- increased file/block size too much
- reduced file count drastically
- changed sort order
- Check for:
- higher disk read bytes
- higher CPU usage
- cache misses
- compaction running concurrently with queries
- Inspect query plans if your system provides them.
Typical fixes
- Tune compaction to keep block sizes at a query-friendly size.
- Preserve or improve sort order on common query keys.
- Schedule compaction during off-peak hours.
- Ensure query caches are warmed after compaction.
- Avoid making files so large that selective queries must scan too much.
- If supported, use tiered compaction instead of over-merging everything at once.
If you tell me what system you’re using—Prometheus, Mimir, Cortex, Thanos, ClickHouse, InfluxDB, TimescaleDB, or something else—I can give a more precise explanation and tuning advice.