-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Add LRU cache alongside redis #6
Conversation
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.
Noice, just a couple things!
await Promise.allSettled( | ||
cachedIdls.map(async (res, i) => { | ||
const programId = programIds[i]!; |
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.
Why do we run allSettled
on an awaited Promise<(string | null)[]>
?
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.
It is mostly because missing idls need to make an RPC call to solana-fm to retrieve and store that in the cache. See line below:
const idl = await getProgramIdl(programId);
await redisClient.connect(); | ||
|
||
const lruCache = new LRUCache<string, string>({ | ||
max: LRU_CACHE_MAX_ITEMS_COUNT, |
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.
We should use the same ttl for the in-memory cache as redis
const client = createClient({ | ||
url: config.REDIS_URL, | ||
}); | ||
const LRU_CACHE_MAX_ITEMS_COUNT = 100; |
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.
We could probably bump this to 1000 without any problems right?
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.
Size of IDL is quite big, but I think node would be fine even with that.
btw I've tested that even a LRU cache of 100 items is going to decrease redis call rate by >90%
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.
Size of IDL is quite big, but I think node would be fine even with that. btw I've tested that even a LRU cache of 100 items is going to decrease redis call rate by >90%
Ahh nice! 👍 I'm fine with either 100 or 1000 then
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.
LGTM 👍 👍 don't forget to update the ExplorerKit Grafana dashboard with these new metrics once you have deployed 🙏
This PR addes LRU cache alongside redis for better performance.
Right now LRU cache size is set to 100 items