Use memcached for faster asset resolution - #129
Conversation
the exact caching and prefetching must be further aligned with the resolver
# Conflicts: # client/ayon_usd/addon.py # pyproject.toml # server/__init__.py
remove graphql and prefetcher code that isn't used for usd
… memcached Add settings for memcached, limit endpoint returning paths by default only to usd representations
Add prelaunch hook to set roots for the usd resolver processing root-less paths stored in memcached
Add docs for caching, move mkdocs infra to pyproject toml.
There was a problem hiding this comment.
Pull request overview
This PR adds memcached-based caching support to the AYON USD addon, including server-side settings and an endpoint to pre-seed cache entries, plus client-side infrastructure (tray service + WebSocket invalidation) to prefetch and invalidate cached asset-path resolutions.
Changes:
- Server: add
usd/memcachedsettings and a new endpoint returning assigned entity-URI → resolved-path pairs for a user. - Client: add a cache manager (memcached client, rate limiter, WebSocket invalidation, prefetch loop) and inject memcached env vars during resolver setup.
- Tooling/docs: introduce
uv.lock, addruff.toml, update MkDocs navigation and add caching documentation.
Reviewed changes
Copilot reviewed 32 out of 33 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds a uv lockfile for dependency pinning. |
| tests/client/ayon_usd/test_utils.py | Adds an API call “test” (currently not asserting). |
| server/settings/publish_plugins.py | Minor formatting change. |
| server/settings/main.py | Adds MemcachedSettings to server settings schema. |
| server/settings/conversion.py | Removes stray whitespace. |
| server/settings/init.py | Reorders exports/imports. |
| server/models/entity_path_list.py | New response model for the assigned-paths endpoint. |
| server/models/init.py | Exports new models. |
| server/api/templating.py | Adds template formatting utilities used for path resolution. |
| server/api/router.py | Introduces a FastAPI router for the addon endpoints. |
| server/api/get_paths_for_assigned_assets.py | New endpoint to fetch assigned paths for a user/project. |
| server/api/init.py | Exposes router and endpoint handler (currently malformed __all__). |
| server/addon.py | Registers the addon router and settings conversion hook. |
| server/init.py | Refactors addon class export. |
| ruff.toml | Adds Ruff configuration. |
| pyproject.toml | Updates project metadata/dependencies (contains duplicates + repo URL change). |
| poetry.toml | Removes Poetry virtualenv config. |
| mkdocs.yml | Adds caching docs to navigation. |
| mkdocs_requirements.txt | Removes separate MkDocs requirements file. |
| docs/Ayon_Docs/Caching_Docs.md | New documentation for memcached caching setup and tuning. |
| docs/Ayon_Docs/Admin_Docs.md | Minor formatting adjustment. |
| client/pyproject.toml | Adds client-side dependency manifest for cache manager dependencies. |
| client/ayon_usd/hooks/setup_memcached.py | Adds launch hook to inject resolver pinning roots env var. |
| client/ayon_usd/hooks/pre_resolver_init.py | Injects memcached env vars into resolver environment when enabled. |
| client/ayon_usd/cache_manager/websocket_client.py | New WebSocket invalidation client (has correctness issues). |
| client/ayon_usd/cache_manager/rate_limiter.py | New rate limiter for prefetch requests. |
| client/ayon_usd/cache_manager/null_client.py | No-op cache client fallback. |
| client/ayon_usd/cache_manager/memcached_client.py | Memcached cache implementation. |
| client/ayon_usd/cache_manager/config_manager.py | Dynamic configuration loading/watching for cache settings. |
| client/ayon_usd/cache_manager/cache_service.py | Orchestrates prefetching + caching + invalidation (has correctness issues). |
| client/ayon_usd/cache_manager/cache_client.py | Cache client protocol (currently mismatched with implementations). |
| client/ayon_usd/cache_manager/init.py | Exports cache manager components. |
| client/ayon_usd/addon.py | Adds tray service to run the cache service on launcher startup (has a config init bug). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Concatenated string output after formatting | ||
| self._output: str = "" | ||
| # Is this result from optional part | ||
| self._optional: bool = True |
| entity_type = cls._entity_type_from_topic(data.get("topic", "")) | ||
| if entity_type == "folder": | ||
| data["folder_id"] = data["summary"].get("entityId") | ||
|
|
||
| if entity_type == "task": | ||
| data["task_id"] = data["summary"].get("entityId") | ||
|
|
||
| return cls( | ||
| event_type=data.get("topic", ""), | ||
| project_name=data.get("project", ""), | ||
| entity_id=data["summary"].get("entityId"), | ||
| timestamp=data.get("timestamp") | ||
| ) |
|
I am converting this PR to draft: It should serve more like a documentation / example / template of how the pre-fetching to memcached could be implemented. Memcached support in USD resolver works without any changes implemented in this PR. Few notes about populating the memcached: I think the ideal way would be to have a service running, slowly fetching all paths and invalidation the latest tagged entities based on events coming from the server, in similar fashion how the invalidation is implemented here. |
|
@antirotor Any news on the client review of this? |
Changelog Description
Support memcache for faster asset resolution. For resolver support, see ynput/ayon-usd-resolver#82
Additional review information
How memcached can speed up asset path resolution, see description in asset resolver PR. Changes here helps with following:
Server side
On server side, it adds memcached configuration options to enable it and provide list of servers -
ayon+settings://usd/memcached.It also provides server endpoint that will return list of entity/root-less path pairs associated with the current user to help pre-seeding the cache.
Note
There might be massive load on the server if this is called too often or out of context. Proper prefetching strategy needs to be determined (probably based on the production needs).
Client side
Client side now features Cache manager - system to pre-fetch and invalidate data from the server. Invalidation is done using events coming from the server using websockets. Invalidation currently doesn't make much sense for almost unchanging usd entities and their respective paths and should be considered more as a proof-of-concept for additional entity caching.
Prefetching can be controlled using
AYON_PRECACHE_PROJECTSenvironment variable (comma separated list of projects to process), using config files (that are monitored for changes) or by using CacheManager API.Note that prefetching runs on addon initialization during AYON Launcher startup, so it doesn't have project context yet. We can also introduce pre-launch hook that will prefetch data based on current project context later on.
Warning
You need to build new dependency package to test this.
Testing notes:
AYON_PRECACHE_PROJECTSenvironment variable with the project name you want.