Why Splitting Logs by Business Key Becomes a Resource-Management Problem
Description and use
Splitting logs by business key simplifies tracing but high cardinality exhausts file descriptors and degrades performance. Use Log4Key with maxOpenFiles, LRU cache, and batched writes to contain resource usage.
Problem
When logs are split by business key (player, order, tenant), high cardinality leads to file descriptor exhaustion and performance degradation.
Outcome
Log4Key allows per‑business‑object log files, but high key cardinality triggers file descriptor limits, leading to event rejections and throughput drops. The solution requires careful tuning of maxOpenFiles, worker threads, and batching.
Workflow
- 1. Add a business key to each log event using Log4KeyLogger.
- 2. Configure Log4Key to route events to files named after the key.
- 3. Set maxOpenFiles to cap open file descriptors.
- 4. Use LRU policy to close idle files and open new ones.
- 5. Batch writes and flush periodically to reduce I/O overhead.
- 6. Monitor for rejections and adjust worker count or maxOpenFiles as needed.
Evidence
At 200 keys there's no rejection. At 210, rejection shows up — mailbox full, events dropped — and write throughput falls off noticeably.
None of this changes what the disk can actually sustain. What it does is keep resource exhaustion contained within the logging layer, instead of letting it take down the app.
- Record date: 2026-09-21T18:30:23.840Z