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

internal/datastore/crdb: split read/write connpools #1179

Merged
merged 6 commits into from
Mar 9, 2023

Conversation

jzelinskie
Copy link
Member

@jzelinskie jzelinskie commented Feb 23, 2023

Because CRDB and Postgres have a stateful protocol that consumes a connection while awaiting a response and writes can starve readers for connections from the pool when there is sufficient load on SpiceDB.

This pull request splits out reads and writes for CockroachDB and PostgreSQL into two different connection pools. This should cause write latency to only impact writes rather than both reads and writes.

@github-actions github-actions bot added the area/datastore Affects the storage system label Feb 23, 2023
@github-actions github-actions bot added the area/CLI Affects the command line label Feb 23, 2023
@jzelinskie jzelinskie force-pushed the rw-conn-pool branch 2 times, most recently from 6f80962 to bec09ef Compare March 7, 2023 00:11
@jzelinskie jzelinskie marked this pull request as ready for review March 7, 2023 00:12
@jzelinskie jzelinskie requested a review from a team as a code owner March 7, 2023 00:12
pkg/cmd/datastore/datastore.go Show resolved Hide resolved
mysql.ConnMaxIdleTime(opts.MaxIdleTime),
mysql.ConnMaxLifetime(opts.MaxLifetime),
mysql.MaxOpenConns(opts.MaxOpenConns),
mysql.MaxOpenConns(opts.ReadConnPool.MaxOpenConns),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it could be argued some folks may consider setting the WriteConnPool parameter instead for those databases that do not support 2 conn pools. As a consequence, the user may think the flag is properly set, when it's in fact being ignored.

Ideally the application makes it difficult to make a mistake here.

Copy link
Member Author

@jzelinskie jzelinskie Mar 7, 2023

Choose a reason for hiding this comment

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

I agree -- especially since this PR doesn't split the pools for all of the datastores.

What's the precedent? We've got some other flags that are CRDB specific, right? What are we doing there?
Let's just be consistent with the existing behavior in this PR and if we have to clean up that behavior, do everything at once in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

let's assume a user wants to move to use MySQL with the new connection flag, because the old ones are deprecated. They may think they have to set the write flags, when in fact they have to set the read flags. Does that make sense?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because MySQL doesn't use pgx, let's get this merged for now and we can work on getting parity to MySQL before the next release.

pkg/cmd/datastore/datastore.go Outdated Show resolved Hide resolved
internal/datastore/postgres/stats.go Show resolved Hide resolved
internal/datastore/postgres/options.go Show resolved Hide resolved
@github-actions github-actions bot added the area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) label Mar 9, 2023
vroldanbet
vroldanbet previously approved these changes Mar 9, 2023
internal/datastore/crdb/crdb.go Outdated Show resolved Hide resolved
internal/datastore/postgres/common/pgx.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

LGTM

@jzelinskie jzelinskie merged commit c6ae0e9 into authzed:main Mar 9, 2023
@jzelinskie jzelinskie deleted the rw-conn-pool branch March 9, 2023 21:49
@github-actions github-actions bot locked and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/CLI Affects the command line area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants