Repository navigation
memcached: trust a seen miss marker briefly instead of re-reading it - #108
Conversation
…g it Miss markers stay out of the in-process caches so that a publish is seen, so every lookup of a dangling URI read memcached again. One Resolve looks a URI up more than once, which made 300 dangling references cost 901 gets on a warm stage, about 5 s at a 5 ms round trip. A process now trusts a marker it saw for up to 5 seconds, never longer than the marker's TTL. ClearCache and DeleteFromCache end that immediately. When `add` finds an existing value it may be a path another process just stored, so that value is read again instead of being trusted as a miss.
There was a problem hiding this comment.
🟡 Changes recommended
Miss-marker handling can reinstate stale misses after explicit invalidation and extend local miss windows beyond the marker’s expiry.
2 open issues
What changed in this PR
This PR reduces repeated memcached reads for unresolved AYON URIs by briefly remembering observed miss markers. The diff also includes the configurable-expiry and cache-invalidation changes from #104.
Changes:
- Add a short local miss-trust window to single and batch lookups.
- Distinguish stored markers from existing values to avoid trusting a concurrently published path as a miss.
- Include configurable expiry, targeted invalidation, documentation, and helper tests.
| File | Description |
|---|---|
| tests/memcachedExpiryTest.cpp | Tests URI classification, expiry settings, and trust-window calculations. |
| src/AyonUsdResolver/config.h | Defines expiry environment-variable names. |
| src/AyonUsdResolver/cache/resolverContextCache.h | Declares expiry settings and local miss tracking. |
| src/AyonUsdResolver/cache/resolverContextCache.cpp | Implements miss tracking, expiry selection, and targeted invalidation. |
| src/AyonUsdResolver/cache/memcachedHandler.h | Defines marker-write outcomes and updates cache APIs. |
| src/AyonUsdResolver/cache/memcachedHandler.cpp | Handles empty markers, conditional writes, and key-length limits. |
| src/AyonUsdResolver/cache/memcachedExpiry.h | Adds classification, expiry, and trust-window helpers. |
| README.md | Documents expiry controls, invalidation, and delayed publish visibility. |
Review effort: Balanced
| const int64_t window | ||
| = trust ? MemcachedExpiry::knownMissWindowFor(MemcachedExpiry::missTtlFor(_MemcachedTtl(uri), m_memcachedMissExpire)) | ||
| : 0; | ||
| const auto until = std::chrono::steady_clock::now() + std::chrono::seconds(window); |
There was a problem hiding this comment.
Correct, and the documentation was wrong: it said the trust is never longer than the marker's TTL, but the window starts when the marker is read, so it can end up to 5 seconds after the marker expired. Fixed the wording in the README and memcachedExpiry.h in 212d650.
The code stays as it is on purpose. The overrun is the same 5 seconds the README already accepts when another process deletes a marker. Knowing the real expiry would take an extra read per marker or a timestamp in the item flags, and not trusting read markers would undo this PR (300 dangling references: 901 gets instead of 301).
| std::lock_guard<std::mutex> lock(m_missKeysMutex); | ||
| m_missKeys[uri] = until; |
There was a problem hiding this comment.
Correct, fixed in 212d650. Lookups now take a generation from KnownMisses before reading, and an older observation is kept for ClearCache but not trusted. The same applies to _StoreMiss.
A generation alone would not have been enough, because a lookup could take the new generation and still read a marker not yet deleted. So invalidation now deletes the marker first and advances the generation after. Reproduced with the read of a marker held in a proxy while the invalidation starts: 16 of 16 runs failed before the change, 16 of 16 pass with it.
A lookup that read a marker could record it after ClearCache or DeleteFromCache had finished, which hid the URI for up to 5 seconds after an explicit invalidation. ClearCache also emptied the list before deleting the markers, so with many markers this window lasted seconds. Lookups now take a generation before reading memcached. Invalidation deletes the marker first and then advances the generation, and an older observation is remembered for ClearCache but not trusted. Also correct the documented limit: the 5 seconds count from when the marker was read, so the trust can end up to 5 seconds after the marker expired.
|
Heads-up: since 212d650 (and the base merge 5caf3bc), this PR conflicts with #110 in // Taken before the markers are read, so an invalidation during the mget is not undone (see KnownMisses).
const uint64_t observedAt = m_knownMisses.generation();
std::unordered_map<std::string, std::string> cachedValues;
{
std::lock_guard<std::mutex> lock(s_memcachedMutex);
cachedValues = m_memcached->get()->getMany(eligible);
}With #108, #109, #110 and #106 merged on the base in your order, the build passes our smoke tests on Houdini 21.0/22.0, Maya 2026 and standalone USD. Our behaviour probe also picked up the documented trade-off: after a miss, a publish is seen in the same process only once the 5 s window has passed. |
Add the scenarios that fail on builds without #108, #109 and #110, now that those are merged: - miss markers: trust window, ClearCache and DeleteFromCache ending it, an invalidation during a read, a path stored during the lookup - malformed AYON answers write no marker; an empty answer still does - dangling references are read once, and their open time - one dead server keeps the hits from the others The proxy can now hold the reads of one key, and the probe can open a stage in the background, to keep the races open.

Description
A stage with dangling references read memcached for every lookup of every missing URI. This PR makes a process remember a miss marker it has seen for a few seconds.
Changelog
Miss markers stay out of the in-process caches so that a publish is seen. As a result, each lookup of a dangling URI read memcached again, and one
Resolvelooks a URI up more than once.kKnownMissWindowSeconds), counted from when it read the marker. This covers bothgetAssetandbatchWarm.ClearCache()andDeleteFromCache()end the window. A lookup that read the marker before they finished cannot restore it: lookups take a generation from the newKnownMissesbefore reading, and invalidation deletes the marker first and advances the generation after.addis not trusted:addMissMarkernow reportsStored,ExistsorFailed.Existsmay be a path another process just stored, so it is read again instead of being treated as a miss.Behaviour change: a process that has just seen a marker can miss a publish for up to 5 seconds, even if another process has already deleted the marker or the marker has expired. This affects only that process's view, not what memcached holds. The README states this. Capping the window at the marker's real expiry would take an extra read per marker, which this PR exists to avoid.
Linked issues/branches
enhancement/featuriing-memcached(Memcached support #82)Type of Change
Additional info
Measured with the integration harness from #107 against a live AYON server, standalone OpenUSD 25.05 and memcached. It is a warm stage with 300 dangling references, median of 5, with the round trip simulated by a proxy.
getcommandsDragonfly results are within a few ms of these. Warm and cold open times for a stage without dangling references did not change.
Testing
test_malformed_answer_writes_no_marker, which needs memcached: write miss markers only for confirmed misses #109.ClearCacheorDeleteFromCachestarts. It failed 16 of 16 runs without the second commit and passed 16 of 16 with it (2 operations, memcached and Dragonfly, 4 runs each). It disables prewarm, so it goes throughgetAsset;batchWarmuses the same helper but was not raced.tests/memcachedExpiryTest.cppcovers the window calculation andKnownMisses, including an observation recorded after an invalidation, an order the scenario above does not force.addMissMarkerstub changed.