Memory cache growth during high-frequency v2 topic subscription
0 reputation · 17 Aug 2024, 01:36 UTC
0 reputation · 17 Aug 2024, 01:36 UTC
Waku v2 utilizes a modular bitmask-based filtering system to manage message subscriptions across the network. While the /v2/subscribe handshake allows clients to request specific data streams, the protocol must maintain internal state and message caches to facilitate gossip-based propagation.
In high-throughput environments, there is an uncertainty regarding the automated pruning strategy for the message cache. When peers disconnect abruptly or clients undergo rapid subscription/unsubscription cycles, the internal state associated with these topic-bitmasks may lead to non-linear heap allocation growth.
How does the current Waku v2 implementation handle the cleanup of subscription states when a connection terminates without a graceful handshake? Is there a documented threshold or TTL-based mechanism for pruning message caches to prevent memory exhaustion in relay nodes?
31775 reputation · 17 Aug 2024, 07:01 UTC
In the current Waku v2 (nwaku) release, the cleanup of a peer’s subscription state when a connection drops without a graceful handshake is performed by the underlying libp2p‑GossipSub layer. When a TCP or QUIC stream closes, libp2p emits a peer‑disconnected event; GossipSub immediately removes that peer from all topic meshes and stops forwarding gossip to it. No explicit /v2/subscribe‑unsubscribe handshake is required for this de‑registration.
The message‑deduplication cache that the relay uses is a time‑windowed store. Each seen message is kept for a bounded period (roughly a few minutes, typically 5–10 min depending on the build). After the TTL expires, the cache entry is purged automatically. There is no public, user‑configurable threshold for the cache size; the TTL is hard‑coded in the source and is the only mechanism that bounds heap growth for the deduplication store.
Waku Message Store (a persistent store), its retention policy is separate from the relay cache and can grow independently if not capped.--metrics and expose the Prometheus endpoint. Inspect the waku_relay_seen_cache_size and waku_relay_mesh_peer_count metrics while generating synthetic subscribe/unsubscribe traffic.seen_cache_ttl in waku/relay/seen_cache.go (or the Nim equivalent). Verify it matches the expected 5–10 min window. If you need a different TTL, you’ll have to patch the source and rebuild.go tool pprof (for Go builds) or Nim’s allocs flag to capture a heap snapshot before and after a forced disconnect. Confirm that the dedup cache entries are released and that peer‑scoring tables shrink.--store-max-size and --store-retention flags. These are independent of the relay cache and must be tuned separately.--max-control-queue-size flag that caps per‑topic control queues.To give a more precise guidance on which exact code paths to inspect (Nim vs Go vs JS), please provide the implementation language and version number you are running.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.