Skip to content

fix: avoid too many concurrent db queries when cache becomes invalid#699

Open
nilsding wants to merge 1 commit intomainfrom
bugfix/noid/reduce-db-access-when-updating-storagemapping
Open

fix: avoid too many concurrent db queries when cache becomes invalid#699
nilsding wants to merge 1 commit intomainfrom
bugfix/noid/reduce-db-access-when-updating-storagemapping

Conversation

@nilsding
Copy link
Copy Markdown
Member

In large installations it's more likely that multiple storage_update events are processed at the same time. When the storage mapping cache becomes invalid each of these events would try to query the database to update the cache.

Apart from causing additional load on the database this would also exhaust sqlx's internal connection pool when more event handling threads are running than there are available database connections -- in this case the Failed to query database: pool timed out while waiting for an open connection message is logged.

This PR changes how the storage mapping cache is updated once it becomes invalid by trying to reduce the chance of multiple threads querying the database at once. Other callers should then still retrieve the old cached mapping during the time the cache is updated.

In large installations it's more likely to process multiple storage_update
events at the same time.  When the storage mapping cache becomes invalid
each of these events would try to query the database to update the cache.

Apart from causing additional load on the database this would also exhaust
sqlx's internal connection pool when more event handling threads are running
than there are available database connections -- in this case the `Failed to
query database: pool timed out while waiting for an open connection` message
is logged.

This commit changes how the storage mapping cache is updated once it becomes
invalid by trying to reduce the chance of multiple threads querying the
database at once.  Other callers should then still retrieve the old cached
mapping during the time the cache is updated.

Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
@nilsding nilsding self-assigned this Apr 24, 2026
@nilsding nilsding added 3. to review Performance 🚀 rust Pull requests that update rust code labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Performance 🚀 rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant