You need to scan 50 GB of compressed logs for a request ID during an incident, as fast as possible. How?
AdvancedScenarioScenarios: text processing and scheduling decisions
Answer
Situation read → I/O and decompression are the bottlenecks; parallelize across files and use the fastest matching mode.
What I'd do →
find /var/log/app -name '*.gz' -print0 |
xargs -0 -P "$(nproc)" -n 4 zgrep -F -H -- 'req-7f3a9c' > /tmp/hits.txt
-Ffixed-string matching is much faster than regex;LC_ALL=Cspeeds it up further.-P $(nproc)runs one decompressor per core;-n 4batches files.- Narrow by time first (file names or mtime) to read less data.
- If installed,
rg -z -F(ripgrep) searches compressed files in parallel by itself. - Run with
niceon a production host, or copy logs elsewhere.
Why → Parallel decompression typically scales nearly linearly with cores until disk throughput becomes the limit.
Interview tip → Mention that this is the moment you wish logs were in a central, indexed system, and say how you would make that case after the incident.
More on Scenarios: text processing and scheduling decisions
Users report errors in the last hour. From the Nginx access log, find which endpoints produce the most 5xx responses.BeginnerA MySQL slow log is 3 GB. You need the 10 slowest query patterns. What do you do?IntermediateTwo servers that should be identical behave differently. Compare their installed packages.BeginnerFind which pods were OOMKilled in a namespace, with their container names and restart counts.IntermediateProduce a CSV of running EC2 instances that are missing an `Owner` tag.IntermediateYou have access logs from five web servers and need one timeline sorted by time. How?Intermediate