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

Use a dedicated thread for each connection #70

Closed
wants to merge 1 commit into from

Conversation

djmb
Copy link
Collaborator

@djmb djmb commented Sep 14, 2023

Switching the connection out when we need to change shard is expensive. It requires checking a connection out of the pool. That will verify the connection which requires a round trip to the database.

Instead we'll create a dedicated thread for each connection and run the query on it via a Concurrent::Promise.

This has two benefits:

  1. There's no connection switching required as each of the threads only talks to one shard.
  2. Multi reads and writes can now happen in parallel as we trigger them as before getting the results from the promises.

The existing async operations (trimming and writing to non primary clusters) don't use these executors, they have their own one instead that does the connection switching. We don't need to worry so much about that as they are not time critical operations, but there's some scope here to tidy things up as they have a lot in common with the new threaded operations.

Switching the connection out when we need to change shard is expensive.
It requires checking a connection out of the pool. That will verify the
connection which requires a round trip to the database.

Instead we'll create a dedicated thread for each connection and run
the query on it via a `Concurrent::Promise`.

This has two benefits:
1. There's no connection switching required as each of the threads only
talks to one shard.
2. Multi reads and writes can now happen in parallel as we trigger them
as before getting the results from the promises.

The existing async operations (trimming and writing to non primary
clusters) don't use these executors, they have their own one instead
that does the connection switching. We don't need to worry so much about
that as they are not time critical operations, but there's some scope
here to tidy things up as they have a lot in common with the new
threaded operations.
@djmb djmb closed this Sep 21, 2023
@djmb djmb deleted the thread-per-connection branch October 3, 2023 12:57
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.

1 participant