Quick revision
The short answer
A time-since-last-run-ms that keeps growing means the log cleaner is not running at all, and max-dirty-percent at 95 confirms that nothing is being compacted, so the topic grows without bound although its 5 million keys have not changed. Usually a cleaner thread died on an unexpected error (DeadThreadCount shows it) or gave up on some partitions (uncleanable-partitions-count), and log-cleaner.log contains the exception. We fix the cause first, such as a corrupt segment, a disk error or an offset map too small for a segment, then restart the broker to restart the cleaner; if it runs but cannot keep up, we add threads, buffer and I/O rate, and check topic settings like segment.ms and min.compaction.lag.ms.
What to remember
In this answer, we saw that a compacted topic growing from 40 GB to 220 GB with constant keys, together with max-dirty-percent at 95 and an ever-growing time-since-last-run-ms, means the log cleaner has stopped. DeadThreadCount and uncleanable-partitions-count show whether a thread died or partitions were skipped, and log-cleaner.log holds the cause, often a corrupt segment, a disk error or an offset map too small. We fix the cause, restart the broker, and if the cleaner is merely slow, add threads, buffer and I/O rate, lower the dirty ratio, and check segment.ms and min.compaction.lag.ms.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A time-since-last-run-ms that keeps growing means the log cleaner is not running at all, and max-dirty-percent at 95 confirms that nothing is being compacted, so the topic grows without bound although its 5 million keys have not changed. Usually a cleaner thread died on an unexpected error (DeadThreadCount shows it) or gave up on some partitions (uncleanable-partitions-count), and log-cleaner.log contains the exception. We fix the cause first, such as a corrupt segment, a disk error or an offset map too small for a segment, then restart the broker to restart the cleaner; if it runs but cannot keep up, we add threads, buffer and I/O rate, and check topic settings like segment.ms and min.compaction.lag.ms.
Why this question is asked
A compacted topic that should stay near the size of its key space but grows fivefold is a slow-motion incident: disk fills, bootstraps take longer every day, and eventually brokers run out of space. The metrics in the question point to a specific failure mode, a cleaner that stopped, which teams often miss because Kafka keeps serving traffic perfectly well without it. Interviewers ask this to see whether we can read the cleaner's metrics and know where it records its failures. In this answer, we will recap what a healthy compacted topic looks like, read the two metrics, find why the cleaner stopped, fix it, handle a cleaner that runs but is too slow, and check topic settings.
1A Quick Recap of a Healthy Compacted Topic
With cleanup.policy=compact, the log cleaner keeps roughly one record per key: when a key gets a new value, the old one is removed in a later cleaning pass. A healthy compacted topic therefore grows with the number of keys and the size of each value, plus a dirty margin of recent updates that are waiting to be cleaned.
Our topic holds about 5 million keys and used 40 GB, which fits roughly 8 KB per key of state. Growing to 220 GB with the same key count means old values are not being removed. Either the cleaner is not running, or it runs but cannot keep up.
2Reading the Two Metrics
max-dirty-percent, in the LogCleanerManager group, is the dirty ratio of the dirtiest log the cleaner knows about, as a percentage. At 95, some log is 95 percent uncleaned data, far beyond the 50 percent at which it should have been picked. time-since-last-run-ms, in the LogCleaner group, is how long ago a cleaner thread finished a pass. In a healthy broker it rises and resets regularly. If it keeps growing for hours or days, no pass has completed in that time.
Together they say the cleaner is not running, not merely slow. A slow cleaner would show time-since-last-run-ms resetting now and then, with max-dirty-percent high but moving.
- time-since-last-run-ms keeps growing?YesCleaner stopped: read log-cleaner.logNoCleaner runs: check whether it keeps up
- DeadThreadCount above 0?YesA cleaner thread died on an errorNoCheck uncleanable-partitions-count
- Cause found and fixed?YesRestart the broker to restart the cleanerNoKeep digging: segment, disk, config
- Dirty percent falling after restart?YesWatch size return toward 40 GBNoTune threads, buffer, I/O rate
- Check segment.ms and min.compaction.lag.ms on the topic
5 steps in order. Play them, or step through them one at a time.
First decide whether the cleaner is dead or just slow; the fixes are different.
3Finding Why the Cleaner Stopped
Cleaner threads run in the broker, and when one hits an unexpected exception it can die. The broker keeps running and serving traffic, so nothing else fails, but compacted topics stop being cleaned. DeadThreadCount in the LogCleaner group shows how many cleaner threads have died; with the default of one thread, a value of 1 means no cleaning at all on that broker.
Newer versions are more forgiving: instead of letting the thread die, the cleaner marks the partition it was working on as uncleanable and moves on. uncleanable-partitions-count, tagged by log directory, shows how many partitions it has given up on, and uncleanable-bytes shows how much data they hold. A partition stays uncleanable until the broker restarts.
The exception itself is in log-cleaner.log, a separate log file the broker writes for the cleaner (configured in log4j). Common causes are a corrupt segment, for example a batch with a bad CRC after a disk problem; an I/O error from a failing disk; and a configuration problem, typically an offset map too small for the work.
4Fixing It
We fix the cause before restarting, otherwise the cleaner dies again on the same segment. For an offset map too small, we raise log.cleaner.dedupe.buffer.size, for example from 128 MB to 512 MB, and make sure the broker heap allows it. For a disk error, we replace the disk or move the partition. For a corrupt segment on one replica, the cleanest fix is to let that replica be rebuilt from a healthy one, for example by reassigning it away and back, rather than editing files.
Then we restart the broker, which restarts the cleaner threads and clears the uncleanable marks. After the restart, time-since-last-run-ms should reset, max-dirty-percent should fall pass by pass, and the topic's size should shrink back towards 40 GB over hours, since the first pass has 180 GB of backlog to work through.
5When the Cleaner Runs but Cannot Keep Up
If time-since-last-run-ms resets normally but dirty percent and size keep growing, the cleaner is alive but too slow for the update rate. We can add threads with log.cleaner.threads, so several partitions are cleaned in parallel. We can raise log.cleaner.dedupe.buffer.size so each pass covers more of the dirty section. We can raise log.cleaner.io.max.bytes.per.second if someone set it low to protect production I/O. And we can lower min.cleanable.dirty.ratio on the topic so passes start earlier and stay smaller, at the cost of more frequent rewriting.
6Checking the Topic's Own Settings
Two topic settings can make compaction look broken when the cleaner is fine. The active segment is never cleaned, so a very large segment.ms or segment.bytes on a topic with a moderate update rate keeps most of the data in the active segment, out of the cleaner's reach. And a large min.compaction.lag.ms, set perhaps to let consumers see every intermediate value for a week, keeps everything younger than that uncompacted by design.
Finally, we prevent a repeat with alerts on DeadThreadCount above zero, uncleanable-partitions-count above zero, time-since-last-run-ms above a few hours, and the ratio between a compacted topic's size and its expected size.
7Follow-up questions
Why does a dead cleaner not affect producers and consumers?
Because cleaning is a background maintenance task. Produce and fetch paths do not depend on it. The only effects are growing disk usage and slower bootstraps, which is why it can go unnoticed for weeks unless the cleaner's metrics are alerted on.
Does the cleaner also affect __consumer_offsets?
Yes. __consumer_offsets is a compacted topic, so a dead cleaner makes it grow too, and group coordinators take longer to load it after a leader change, which slows consumer group recovery. It is another reason to alert on the cleaner.
8Conclusion
In this answer, we saw that a compacted topic growing from 40 GB to 220 GB with constant keys, together with max-dirty-percent at 95 and an ever-growing time-since-last-run-ms, means the log cleaner has stopped. DeadThreadCount and uncleanable-partitions-count show whether a thread died or partitions were skipped, and log-cleaner.log holds the cause, often a corrupt segment, a disk error or an offset map too small. We fix the cause, restart the broker, and if the cleaner is merely slow, add threads, buffer and I/O rate, lower the dirty ratio, and check segment.ms and min.compaction.lag.ms.
Open with
With 5 million keys the topic should stay around 40 GB, so growing to 220 GB means old values are not being removed. The two metrics tell me why. max-dirty-percent at 95 means some log is almost entirely uncleaned, and time-since-last-run-ms growing continuously means no cleaner pass has finished in that time, so the cleaner is not running at all, not just slow.
Then, if they want more
Kafka keeps serving traffic without it, which is why this can go unnoticed. I would check DeadThreadCount, because a cleaner thread can die on an unexpected error, and uncleanable-partitions-count, which in newer versions lists partitions the cleaner gave up on. Then I would read log-cleaner.log for the exception.
Typical causes are a corrupt segment, a disk error, or an offset map too small for a segment, where the message tells you to raise log.cleaner.dedupe.buffer.size.
I would fix that cause first, for example raise the buffer or rebuild the bad replica, and then restart the broker, which restarts the cleaner, and watch dirty percent drop and the size come back down. If instead the cleaner runs but cannot keep up, I would add log.cleaner.threads, raise the dedupe buffer and log.cleaner.io.max.bytes.per.second, or lower min.cleanable.dirty.ratio.
I would also check the topic for a huge segment.ms, since the active segment is never cleaned, or a large min.compaction.lag.ms, and add alerts on the cleaner metrics.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "The broker's max-dirty-percent metric is at 95 and time-since-last-run-ms keeps growing....": https://scrivio-interview-library.netlify.app/spring-boot/kafka-internals/5365453962/