-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
get_timestamp should use the cache, not query the database #8
Comments
Hey! Querying the timestamp is meant to support updating the asset in case the time stamp has been updated. Using the timestamp from the cache does not give us this feature. However, we can add an option that disables updating the timestamp from the database and always uses the cache. |
@elrond79 @nrusch what do you think? |
I think that get_timestamp is (ab)used to check if a reload of the assets will be required on the next reload... while most of the code in SDFLayer seems to use get_timestamp to keep track of the timestamp of the current layer. |
The timestamp recorded during the resolver.FetchToLocalResolvedPath is the correct asset timestamp to be reported in layer::_OpenLayerAndUnlockRegistry. So if you won't need to reload assets in the usd runtime (usdcat, usdzip, ...), you can save a lot of database calls. |
The confusion all starts with this dubious function
It would be ideal if an extra 'fetch' boolean would be passed along to indicate that you want either the timestamp from the path (from database) or from the resolvedPath (local file). |
I'm getting my expected result by using UpdateAssetInfo to fetch the latest date modified from the db when the cache indicates that the asset is already fetched. When the cache indicates 'NEEDS_CACHING', UpdateAssetInfo does nothing.
I ended up with an implementation where Resolve only determines the localPath (without doing any calls), UpdateAssetInfo does a HEAD request (similar to get_raw_timestamp) only if a local cache is present (to refresh the metadata) and Fetch does the heavy lifting with less pre-conditions. On top of that, I'm adding the "IfModifiedSince" header in the Fetch call, catching the 304 Not Modified error. So ideally, the URI resolver does a single DB call max for each time the scene is loaded. Only when the server doesn't support the 'IfModifiedSince' header (even not via a query), you may need up to 2 DB calls: one to resolve/update and one to fetch. |
Thanks for the detailed information, I'll dig through the details. If you have it working on your side, a PR would be useful. |
I've been working in a separate repo: https://github.com/westerndigitalcorporation/usd-s3-resolver I need to add a few more performance tests and sort out the fact that reloads are slower than initial loads on S3. Once that is done, I could apply the same logic to the MySQL resolver. It looks like stage.reload is single threaded while the initial load is multithreaded... more on that later. Unfortunately I have to move on to my next project so I can't make promises on the timeline here. |
resolver.RefreshContext(context) seems the ideal place to reset the caches. You're even able to flush only a subset of the cache. |
Opening and reloading a stage applies these steps with database calls:
Fetch asset always does an extra get_raw_timestamp check when the cache says that fetching is not necessary...
Because of this, I think that the get_timestamp call should just return the cached timestamp value without making yet another database query.
I think this line should be dropped: https://github.com/LumaPictures/usd-uri-resolver/blob/master/URIResolver/sql.cpp#L525
This reduces the database queries per unique asset from 3 to 2.
The text was updated successfully, but these errors were encountered: