-
Notifications
You must be signed in to change notification settings - Fork 645
Implement version_id
cache for download
endpoint using moka
crate
#3999
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
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good!
Before merging and deploying this I think it'd be useful to have two new metrics to count the cache hits and cache misses: that way we know how well the cache is working in prod, allowing us to tweak the params to improve performance.
@pietroalbini I've move the env vars to the |
Generally yes, but I don't have time for a full review right now. |
☔ The latest upstream changes (presumably #4055) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #4061) made this pull request unmergeable. Please resolve the merge conflicts. |
1426518
to
1f91916
Compare
☔ The latest upstream changes (presumably #4090) made this pull request unmergeable. Please resolve the merge conflicts. |
823351d
to
e649d92
Compare
f04d139
to
5cbddb6
Compare
☔ The latest upstream changes (presumably #4140) made this pull request unmergeable. Please resolve the merge conflicts. |
…ount()` to proper functions
This adds a caching layer in the app backend to reduce the number of database queries. While this query is extremely fast, a massive number of concurrent download requests can still result in a request backlog. In this implementation cached values are never dropped. This means that memory usage will grow over time, however the memory usage is expected to be well within our instance size and the application is automatically rebooted at least once every 24 hours. Additionally, on the rare occasion that a crate version is deleted, the cache will continue to serve redirects and attempt to record download counts for that version. If a version is deleted and continues to see download requests, it is expected that the entire shard of downloads containing that version_id will fail to persist. Even if we expired cached entries after a certain time period, there would still be a window where a deleted version could cause download counts for other versions to not be persisted. It is possible we could make the download counter logic robust against this scenario, but given that deleting versions is rare we can mitigate this by restarting the app after deleting crates or versions.
@bors merge |
@bors r+ |
📌 Commit b296c42 has been approved by |
☀️ Test successful - checks-actions |
This PR builds on top of #3848, but uses https://github.com/moka-rs/moka instead of https://github.com/xacrimon/dashmap for caching the
version_id
in thedownload
API endpoint. I've implemented it using environment variables and default values that will allow us to fine tune the values in production, if necessary.