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
db: Use mutex around cache #12580
db: Use mutex around cache #12580
Conversation
This ensures that when the cache has expired, only one goroutine will refresh it while others will block until the it has refreshed.
@keegancsmith hah, I think using a mutex may actually be better 😄 |
Yeah I was aware of this drawbac, and mentioned it on our call. But a few points:
|
Ok, fair enough. Another option I considered was keeping atomic.Value and returning stale cache data and kicking off a background process to update the cache.. but that's even more complicated 😄 |
Related to the work you both did here: I played around with the query we are using to load this data. It's a pretty optimal plan. It takes 300ms because it's moving 3.75GB of memory around (all rows were already cached in memory, no disk I/O), so we're actually limited by memory bus bandwidth (12.5 GB / s, extrapolated). Two remarks:
|
Thanks for looking in, yeah I suspected it had to do with IO. Is it really 3.75GB of memory? The
Agreed.
I think the estimate on the size above is likely an order of magnitude off, so it should be fine. The current implementation is a clear improvement in the following ways:
I was thinking this morning about how we can take this optimization and apply it for customers. The big reason this is so much faster is due to avoiding network IO, so the idea of implementing an imemory version of our List function may be very effective. |
Good call. I think this might be the data size for the full rows which Postgres needs to move around (since it's not a column store) before filtering down to just name and id which is what is returned to the frontend. |
This ensures that when the cache has expired, only one goroutine will
refresh it while others will block until the it has refreshed.