Skip to content

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

Merged
merged 5 commits into from
Nov 7, 2021

Conversation

Turbo87
Copy link
Member

@Turbo87 Turbo87 commented Oct 11, 2021

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 the download 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.

@Turbo87 Turbo87 added C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works A-backend ⚙️ labels Oct 11, 2021
@bors

This comment has been minimized.

Copy link
Member

@pietroalbini pietroalbini left a 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.

@Turbo87
Copy link
Member Author

Turbo87 commented Oct 17, 2021

@pietroalbini I've move the env vars to the Server config and added metrics now. Can you check if that matches what you had in mind?

@pietroalbini
Copy link
Member

Generally yes, but I don't have time for a full review right now.

@bors
Copy link
Contributor

bors commented Oct 20, 2021

☔ The latest upstream changes (presumably #4055) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Oct 20, 2021

☔ The latest upstream changes (presumably #4061) made this pull request unmergeable. Please resolve the merge conflicts.

@Turbo87 Turbo87 force-pushed the moka branch 6 times, most recently from 1426518 to 1f91916 Compare October 26, 2021 06:46
@bors
Copy link
Contributor

bors commented Oct 26, 2021

☔ The latest upstream changes (presumably #4090) made this pull request unmergeable. Please resolve the merge conflicts.

@Turbo87 Turbo87 force-pushed the moka branch 4 times, most recently from 823351d to e649d92 Compare November 2, 2021 08:20
@Turbo87 Turbo87 force-pushed the moka branch 2 times, most recently from f04d139 to 5cbddb6 Compare November 6, 2021 10:07
@bors
Copy link
Contributor

bors commented Nov 6, 2021

☔ The latest upstream changes (presumably #4140) made this pull request unmergeable. Please resolve the merge conflicts.

jtgeibel and others added 5 commits November 7, 2021 12:43
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.
@pietroalbini
Copy link
Member

@bors merge

@pietroalbini
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 7, 2021

📌 Commit b296c42 has been approved by pietroalbini

@bors
Copy link
Contributor

bors commented Nov 7, 2021

⌛ Testing commit b296c42 with merge e4e28f5...

@bors
Copy link
Contributor

bors commented Nov 7, 2021

☀️ Test successful - checks-actions
Approved by: pietroalbini
Pushing e4e28f5 to master...

@bors bors merged commit e4e28f5 into rust-lang:master Nov 7, 2021
@Turbo87 Turbo87 deleted the moka branch November 7, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-enhancement ✨ Category: Adding new behavior or a change to the way an existing feature works
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants