Skip to content
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

Redis cache for stream commit state, dpid mappings, and legacy history structs #30

Merged
merged 3 commits into from
Sep 17, 2024

Conversation

m0ar
Copy link
Contributor

@m0ar m0ar commented Sep 16, 2024

Fetches raw stream log to always get fresh tips, but uses redis to resolve the state of each commit.

Commits:

  • Short TTL (10m default) on pending commits to allow more frequent refreshing
  • Long TTL (1W default) on anchored/final commits

dPIDs and legacy history:

  • Caches mapped dPIDs with the long TTL (as they are permanent)
  • Caches unmapped dPIDs and legacy histories with the short TTL (as they change if upgraded/migrated/re-synced)
    • Can prob increase this when we aren't screwing around with the contracts anymore, in particular the legacy structs

Speedup

Loading a node with a history of ~23 publishes goes from 5ish seconds to about 160ms 🎊 👯‍♀️

@m0ar m0ar added the enhancement New feature or request label Sep 16, 2024
@m0ar m0ar self-assigned this Sep 16, 2024
@m0ar
Copy link
Contributor Author

m0ar commented Sep 16, 2024

⚠️ Unfortunately the test suite used nodes that have broken anchors, so we'll have to YOLO it in for now

Copy link
Contributor

@kadamidev kadamidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking sendable, lets test it in dev

return res.status(400).send("Missing /:id or ids array in body");
} else {
logger.info({ ids }, "Handling history query");
logger.error({ body: req.body, params: req.params }, "request missing IDs");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a .warn instead, no biggie

const stream = await ceramic.loadStream(streamID);
const commitIds = stream.state.log.filter(({ type }) => type !== 2).map(({ cid }) => CommitID.make(streamID, cid));

const versionPromises = commitIds.map(async (commit) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, wonder if there's sense in rebumping the TTLs on cache hits if they're anchored
The data should no longer change at that state, and it would prevent a slow load after TTL expiry on that entry

@m0ar m0ar merged commit 1931b7c into develop Sep 17, 2024
1 check failed
@m0ar m0ar deleted the m0ar/resolver-redis-cache branch September 17, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants