Diagnosing a Host Overloaded by Excessive Logging
System DesignModel answerLast updated
Walk through how you would find out whether logging is exhausting a server, restore service safely, and put guardrails in place so the problem cannot return.
You are on call for a service whose host is struggling, and there are signs that logging is part of the problem. Latency is climbing, and some requests are timing out.
Describe how you would handle this from start to finish:
- Diagnose. How do you work out which resource is actually saturated, and whether logging is the cause or only a bystander?
- Stabilize. What can you safely do right now to restore service without losing data you may need?
- Prevent. What changes to the logging pipeline and its configuration would keep this from happening again?
- Verify. How do you confirm that the fix worked and that the underlying trigger was addressed, not just the symptom?
The report does not say whether the bottleneck is CPU, memory, disk space, disk bandwidth, or a downstream logging sink such as a remote collector. Part of your answer should be how you tell these apart before you change anything.
Some questions you may want to answer or ask yourself:
- Which resource is exhausted?
- Did log volume change recently, for example after a deploy, a config change, or a traffic shift?
- Are application threads blocked on a slow sink, or is an unbounded in-memory queue growing?
- Which logs are needed for debugging or audit, and which can be dropped or sampled?
Hints
Hint 1
Start by attributing the saturation: check CPU, memory, disk space, disk I/O and network per process before you touch any logging setting.
Hint 2
Separate the producer side (how many lines per second, and from where) from the sink side (local file, agent, remote collector). A slow sink can block producers or make an in-memory buffer grow.
Hint 3
Think about bounded behavior: bounded queues, a clear drop-or-block policy, rotation by size and age, retention limits, and rate limiting or sampling for repetitive lines.
Hint 4
A fix is only proven when the metric that was saturated returns to normal under comparable load and you know why volume spiked in the first place.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Framing
The key discipline is to attribute before you act. "Logging is slow" is a hypothesis, and several different failures look similar from the outside. Turning log levels down blindly can destroy the evidence you need and still not fix the incident.
1. Diagnose: which resource, and is logging the cause?
Check the standard resources, per process where possible:
- Disk space:
df -handdf -i(inodes). A full disk causes write failures and can crash databases sharing the volume. Usedu -xh --max-depth=2 /var/log | sort -hto find the large directories, andlsof +L1to find deleted-but-still-open files, which hold space after a naiverm. - Disk bandwidth and latency:
iostat -x 1,iotop. High%utilandawaitwith large sequential writes from the app or log agent points at log volume. - CPU:
top,pidstat, or a profiler or flame graph. Time in string formatting, serialization, compression, or regex-based log parsing indicates a CPU-bound logging cost. - Memory: RSS growth of the app or the log shipper, plus heap dumps. A growing async log queue or a shipper buffering for an unreachable collector shows up here.
- Network and sink: collector latency, error rates, retry counts, and connection state. If the sink is slow, a synchronous appender will block request threads (look at thread dumps for many threads parked in the logging call).
Then measure the producer side:
- Lines per second and bytes per second over time. Compare to before the incident.
- Top log sources by call site, logger name, or message template. A single hot line (a retry loop, a per-item debug statement, a stack trace on every failure) usually dominates.
- Correlate the start of the spike with deploys, feature flags, config changes, upstream errors, or traffic changes.
Decision logic:
| Symptom | Likely cause |
|---|---|
| Disk full, large files in the log directory | Volume too high or rotation/retention missing |
| High disk await, app threads blocked in write | Synchronous logging on a saturated disk |
| App RSS growing, queue depth rising | Unbounded async buffer, sink slower than producers |
| High CPU in formatting or serialization | Expensive log construction at a high level |
| Shipper CPU or memory high, collector errors | Sink or pipeline problem, not the app |
2. Stabilize safely
Goal: restore headroom quickly without losing needed evidence.
- Preserve a sample first. Copy or snapshot a representative slice of the offending logs (or move the file to another volume) so the root cause can still be analyzed.
- Free space correctly. Truncate or compress and move old files. If a process holds a deleted file open, truncate it (
: > file) or restart the process, since deleting does not release space. - Reduce volume at the source. Raise the level on the noisy logger only (for example from DEBUG to WARN) at runtime if supported, rather than globally. Enable sampling or rate limiting for the repeated line.
- Decouple producers from the sink. If the sink is down or slow, switch to a local buffer with a hard cap, or temporarily route to local disk, so request threads stop blocking.
- Shed load or roll back if a recent deploy introduced the flood. Rolling back is often the fastest mitigation.
- Avoid risky moves during the incident: mass deleting logs needed for audit, or restarting every instance at once.
3. Prevent recurrence
Bounded behavior everywhere
- Use an asynchronous appender with a bounded queue. Choose an explicit policy when full: drop lowest-severity first, drop newest, or block, depending on the data. Typical choice for request-serving paths is to drop DEBUG/INFO and never block the request thread. Count drops with a metric.
- Cap shipper buffers (memory and disk) and set backoff with jitter for the sink.
Rotation and retention
- Rotate by size and time (for example 100 MB or daily), compress rotated files, and keep a fixed number or age (for example 7 days locally, longer in cheap central storage).
- Put logs on a separate volume or quota so they cannot starve the application or database.
Volume control
- Sensible default levels per environment, with per-logger overrides.
- Rate limit or deduplicate repeated messages ("message repeated 10,000 times").
- Do not log inside tight loops, avoid logging full payloads, and use lazy message construction so disabled levels cost almost nothing.
- Prefer structured logs and metrics for high-frequency facts. A counter is far cheaper than a line per event.
Alerting
- Alert on disk usage trend (time to full), log bytes per second, queue depth, drop count, and sink error rate, so you hear about it before saturation.
4. Verify
- The saturated resource returns to normal under comparable traffic: disk usage flat, await low, queue depth near zero, no blocked threads.
- Log volume per second is back to its baseline, and you can name the cause of the spike (a bad deploy, a retry storm, a misconfigured level) and show it was fixed.
- Run a test: replay or generate load, and simulate a slow or dead sink. Confirm request latency stays flat and the queue stays bounded while drops are counted.
- Confirm required logs (audit, error) still arrive, and that retention actually deletes old files.
- Write a short postmortem with the trigger, the detection gap, and the guardrails added.
Trade-offs
- Block vs. drop: blocking preserves every line but couples availability to the sink. Dropping protects latency but loses data. Audit logs may deserve a separate, durable path, while diagnostic logs can be dropped.
- Sync vs. async: async lowers latency but risks losing the last lines on a crash and adds memory use.
- Verbose vs. lean: more logging helps debugging but costs money and performance. Sampling and dynamic level changes give most of the benefit.
Common mistakes
- Changing log levels before identifying the saturated resource.
- Deleting a large open file and wondering why space did not return.
- Using an unbounded queue, which converts a slow sink into an out-of-memory crash.
- Fixing the symptom (more disk) without finding why volume increased.
- Declaring success without reproducing load or confirming the metric recovered.
- Putting logs on the same volume as data stores with no quota.