OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

Hardcoded 0.2s lock poll interval + unbounded compressor lock retries saturate CPU and flood logs under concurrent memory extraction

Open pengfus opened this issue 4 months ago • 2 comments

Environment

Same deployment as the companion stale-lock issue #3273: OpenViking v0.4.5 docker compose, single node, 24 cores / 64 GB, qdrant v1.18.1 (dim 4096, cosine), self-hosted OpenAI-compatible Qwen gateway for embedding/VLM/rerank, ~4–5 session operations/sec concentrated on a few user ids. memory config left at defaults.

Symptom

  • The openviking-server process pinned ~140% CPU continuously; system load 7+.
  • API latency became erratic — /health (a trivial endpoint) intermittently took 1.2 s vs 1–3 ms, i.e. the asyncio event loop itself was starved.
  • Log volume exploded: 366k Still waiting for lock INFO lines in 2 hours (74% of all log lines), 300+ MB/day log files.
  • urllib3 Connection pool is full, discarding connection warnings against the qdrant host (pool size 10) throughout.

Root cause

Lock waiting is implemented as file-existence polling with a hardcoded interval:

# openviking/storage/transaction/path_lock.py (v0.4.5)
_POLL_INTERVAL = 0.2

Three things multiply together:

  1. SessionCompressorV2 passes timeout=None to acquire_exact_tree_batch, which path_lock maps to "wait up to lock_expire (300 s)" — so each acquisition attempt polls every 0.2 s, per contended path, for up to 5 minutes. Each poll is several AGFS operations (own-lock check, exact-lock check, ancestor tree scan), each dispatched through run_in_executor.
  2. Lock holders run multi-turn LLM extraction while holding the locks (see #3273), so under sustained per-user traffic dozens-to-hundreds of extraction coroutines are waiting at any moment.
  3. The outer retry loop defaults are aggressive too: memory.v2_lock_retry_interval_seconds = 0.2, v2_lock_max_retries = 0 (unlimited), so blocked extractions accumulate without bound.

py-spy sampling of the live process showed the cost is dominated by executor churn from this polling: a large thread pool with cross-thread wakeups (call_soon_threadsafe → _write_to_self) on every probe, and Future.set_exception completions outnumbering set_result ~3.5:1 (probes of non-existent lock files complete exceptionally). The waiters also log Still waiting for lock at INFO every 10 s per path, producing the log flood.

Mitigations we verified in production

  1. Config: memory.v2_lock_retry_interval_seconds: 3.0, v2_lock_max_retries: 100 — removed the unbounded pile-up, cut log spam.
  2. One-line patch: _POLL_INTERVAL = 1.0 — combined with the stale-lock fix in the companion issue, server CPU went from ~140% to 1–5% and /health latency stabilized at 1–20 ms.

Suggestions

  • Make the poll interval configurable (and/or use exponential backoff with a cap) instead of the hardcoded 0.2 s.
  • Consider demoting the per-path Still waiting for lock INFO logs to DEBUG, or rate-limiting them per owner rather than per path — at INFO they can dominate production logs.
  • Longer term: an event/notification-based wait (or per-user queueing for extraction) would remove the polling cost entirely.

pengfus avatar Jul 15 '26 13:07 pengfus

Adding independent field data from another deployment that hits the same pattern as this issue (+ #3274, + #1581 which fixed the config semantics).

Environment

  • OpenViking v0.4.7 (docker-single-node, 24-core class host, Volcengine Doubao embedding + VLM backends).
  • Workload is agent-driven memory extraction (Hermes Agent → OV memory provider). Bursty rather than steady; a few sessions/minute with occasional bursts of ~5/sec.
  • memory.v2_lock_max_retries left at default (i.e. the pre-#1581 unlimited-retry semantics).

Observed symptoms (matches #3274 exactly)

  • openviking-server process pinned around ~60% CPU baseline, with sustained bursts higher during memory extraction.
  • Swap grew slowly (~tens of MB / hour) while RSS climbed correspondingly; no leak stabilization within a normal working day.
  • Log stream dominated by two repeating patterns during the CPU spikes:
    compressor_v2 - Failed to acquire memory locks, retrying (attempt=N, max=unlimited)
    path_lock - Removing stale lock: /.../memories/{events,tools}/.path.ovlock
    
    attempt counter climbs into the tens of thousands on a bad hour, exactly matching the "unbounded retries" behavior described in this issue and in #1581.

Cross-issue read

  • #1581 (now closed) fixed the config surface — 0 no longer means "unlimited". Deployments that never explicitly set memory.v2_lock_max_retries inherit the historical unlimited semantics until they upgrade + set a bounded value.
  • This issue (#3274) is the runtime half: even with a finite retry count, the hardcoded 0.2 s poll interval is what turns any legitimate contention into CPU pressure and log flood.
  • #3226 explains why compressor_v2 stays inside a lock section long enough to matter — the unbounded-prompt path can send 52k+ token payloads to the VLM, which is exactly the kind of tail latency that lets a compressor session hold .path.ovlock long enough for the next N sessions to pile into the retry loop.

Reading the three together, this looks less like "three separate bugs" and more like one failure mode with three surface expressions: unbounded retries × short poll × unbounded per-attempt work = a stable log-flood/CPU-saturation attractor whenever memory extraction fans out.

What worked as a workaround here

  • Configuring memory.v2_lock_max_retries=30 (post-#1581) cut the log flood immediately — extraction now fails fast with a real error instead of spinning.
  • Rate-limiting extraction concurrency at the agent layer (fewer parallel session commits) kept the still-hardcoded 0.2 s poll from stacking up.
  • Neither of those addresses the root cause; both just push the failure mode below the threshold where the system self-DoSes.

Happy to run additional reproduction against v0.4.9 / v0.4.10 if the maintainers want confirmation that the fix in #3274's suggested direction (configurable poll interval + bounded retry) lands cleanly on top of #1581.

livechenjt-prog avatar Jul 16 '26 14:07 livechenjt-prog

Thanks for the detailed report! Both mechanisms identified here have changed: #3642 replaced the fixed lock polling interval with bounded, jittered backoff, and #3346 removed the V2 compressor and its unbounded retry loop. The current lock path is managed by Rust rather than that Python V2 loop.

Closing the reported implementation issue as resolved on main. If a version containing both changes still produces a lock-contention CPU/log storm, please reopen, or comment requesting reopening, with the version, concurrency level, lock settings and a short timestamped log sample. That would identify a remaining current path rather than the removed V2 mechanism.

qin-ctx avatar Sep 18 '26 08:09 qin-ctx