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

Cache repo revs in order to avoid read-after-write for up-to-date responses #2784

Closed
wants to merge 11 commits into from

Conversation

matthieusieben
Copy link
Contributor

No description provided.

@@ -548,6 +548,15 @@ export class SeedClient<
return result.data
}

pdsAgent(did: string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

slick addition 👌

export class RepoRevCacheRedis implements SimpleStore<string, string> {
/**
* @param redis - Redis client
* @param maxAge - Maximum age of a cached revision in milliseconds
Copy link
Collaborator

Choose a reason for hiding this comment

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

just noting that this is called maxAge here but px in the constructor

@dholms
Copy link
Collaborator

dholms commented Sep 5, 2024

Overall looking good!

Importantly, we need to update the cache value when we do a write (createRecord, putRecord, deleteRecord, applyWrites). Otherwise we will likely be doing comparisons on stale values on read
nvm, I missed that in account manager

@@ -187,7 +189,8 @@ export class AccountManager
}

async updateRepoRoot(did: string, cid: CID, rev: string) {
return repo.updateRoot(this.db, did, cid, rev)
await repo.updateRoot(this.db, did, cid, rev)
await this.repoRevCache?.set(did, rev)
Copy link
Collaborator

Choose a reason for hiding this comment

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

may be good to fail open on this rather than returning an error to the user

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh rip saw you handle these errors in the simple store 😛


// If the response's "atproto-repo-rev" header matches the current repo rev,
// we can skip the munge step and return the response as-is.
const repoRev = await ctx.repoRevCache?.get(requester)
Copy link
Collaborator

Choose a reason for hiding this comment

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

similarly, it'd be great to fail open here, maybe with a quick timeout on the redis request

Comment on lines 123 to 124
// Repo revision cache
repoRevCacheMaxAge: envInt('PDS_REPO_REV_CACHE_MAX_AGE'), // Seconds (use 0 to disable)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To make the PDS config more uniform I recommend we switch this to be _MAX_TTL and to accept a value in milliseconds.

Copy link
Collaborator

@dholms dholms left a comment

Choose a reason for hiding this comment

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

yup 👍

@matthieusieben
Copy link
Contributor Author

Dropping since it didn't produce the expected perf improvements.

@matthieusieben matthieusieben deleted the msieben/read-after-write-caching branch November 4, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants