Skip to content

Improve connection pool read performance #38

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

Merged
merged 13 commits into from
Apr 4, 2024
Merged

Conversation

rkistner
Copy link
Contributor

@rkistner rkistner commented Apr 3, 2024

The old implementation worked as follows:

  1. If no idle connection is available and the maxReaders haven't been reached, open another connection.
  2. Request a read lock on all open connections.
  3. The first available read lock is used. Others are released as soon as the lock was available.

This worked okay for a small number of connections, but scaled quite badly when the number of connections is increased. Even with the default maximum of 5 read connections, the number of read locks/s benchmark is reduced from 107k/s to 36k/s on my machine when those connections have been opened. This adds significant overhead when doing many individual select statements.

This is a complete re-implementation of the logic, using a queue of pending operations and available connections instead. This ends up being simpler (less edge cases), and scales much better with the number of connections.

Builds on #37 Now part of this PR:

Fixes #36 (issues when closing the database while queries are still running).

Also improves handling of database initialization errors and other uncaught errors in connection isolates.

@rkistner rkistner changed the base branch from fix-closing to main April 4, 2024 13:22
@rkistner rkistner mentioned this pull request Apr 4, 2024
@rkistner rkistner marked this pull request as ready for review April 4, 2024 13:25
Copy link
Contributor

@stevensJourney stevensJourney left a comment

Choose a reason for hiding this comment

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

Awesome! LGTM

@rkistner rkistner merged commit bea5c58 into main Apr 4, 2024
6 checks passed
@rkistner rkistner deleted the connectionpool-performance branch April 4, 2024 14:01
@rkistner rkistner mentioned this pull request Apr 4, 2024
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.

Closed Exception when the SqliteDatabase.close is invoked
2 participants