#8
Add file descriptor budgeting and backpressure for RocksDB, blob I/O, and replication
Problem
The cache service currently uses file descriptors from a shared process-wide pool without explicit budgeting between:
- RocksDB open files
- foreground blob reads
- upload/temp-file writes
- background replication
- inbound and outbound sockets
In a highly concurrent environment this can lead to EMFILE / file descriptor exhaustion, which would cause the service to fail in unpredictable ways.
Current state
A few places that consume file descriptors directly:
src/store.rs: RocksDB is opened with default options and does not setmax_open_filessrc/http.rs: blob serving opens files per request for streamingsrc/replication.rs: replication opens local blob files and outbound HTTP connectionssrc/utils.rs: request bodies are persisted to temp files during uploads
We also do not currently expose the active FD count or enforce any workload-specific concurrency budgets.
What we should do
- set an explicit process/container
nofilelimit in deployment - add a configurable RocksDB
max_open_files - introduce bounded concurrency / semaphores for major workload classes
- foreground blob reads
- uploads/temp-file work
- replication
- reserve headroom so background work cannot starve foreground traffic
- add backpressure / load shedding when FD usage crosses configured watermarks
- export observability for open FD count and budget usage
Suggested approach
- Add config for RocksDB file budget, per-workload concurrency budgets, and watermark thresholds.
- Export a metric for current open FDs, e.g. by counting
/proc/self/fdon Linux. - Give replication a lower priority and pause/throttle it first when usage is high.
- Reject non-critical work with
503rather than allowing the process to exhaust descriptors. - Log the effective
RLIMIT_NOFILEat startup.
Acceptance criteria
- RocksDB open file usage is capped by config.
- Foreground and background file-consuming workloads have separate bounded concurrency controls.
- The service exposes an open-FD metric.
- Replication is throttled or paused before foreground traffic is impacted.
- The service sheds load before hitting
EMFILE. - Configuration and operational expectations are documented.
Notes
This does not need a perfect fairness model. The important part is explicit budgeting, reserved headroom, and predictable degradation under pressure.
Activity
0No activity yet.