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

cockroach-go: transaction requires four round trips to manage txn state #28105

Open
nvanbenschoten opened this issue Jul 31, 2018 · 0 comments
Open
Assignees
Labels
A-sql-pgwire pgwire protocol issues. C-performance Perf of queries or internals. Solution not expected to change functional behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@nvanbenschoten
Copy link
Member

nvanbenschoten commented Jul 31, 2018

We currently suggest that all Go clients use our cockroach-go library when running transactional workloads. We also use this library ourself in tests and in benchmark load generators. This is a problem because the library has never been tuned for efficiency. The most obvious example of this is that the library performs four extra client<->gateway round trips just to manage transaction state. These roundtrips are to run the statements:

  • BEGIN
  • SAVEPOINT cockroach_restart
  • RELEASE SAVEPOINT cockroach_restart
  • COMMIT

There are two main problems with this:

  1. it increases transactional latency
  2. it increases transactional CPU footprint

We should explore methods to reduce the amount of work a transaction needs to perform in order to maintain state. For instance, we could send the first two statements together like BEGIN; SAVEPOINT cockroach_restart and the last two statements together like RELEASE SAVEPOINT cockroach_restart; COMMIT (either manually or through a driver batching API).

We could also take this a step further by taking hints from out client.Txn package. The first two statements could be lazily prepended to the first client-supplied statement. Further, we could provide an ExecAndCommit method that's analagous to our CommitInBatch method which would send that last client statement with the final two txn management statements. Combined, these two changes would even open up the opportunity for us to detect 1PC-able transactions that could have their BEGIN and COMMIT statements stripped and run in an implicit-transaction.

To accomplish all of these goals we'll need to be a little more aggresive about our interaction with the stdlib's database/sql package and may need to make the package more opinionated. I don't think this is a problem, especially if we offer it as an alternative to the existing API.

cc. @andreimatei @cockroachdb/sql-wiring

Jira issue: CRDB-4927

@nvanbenschoten nvanbenschoten added C-performance Perf of queries or internals. Solution not expected to change functional behavior. A-sql-pgwire pgwire protocol issues. labels Jul 31, 2018
@nvanbenschoten nvanbenschoten added this to the 2.2 milestone Jul 31, 2018
@petermattis petermattis removed this from the 2.2 milestone Oct 5, 2018
@rafiss rafiss self-assigned this Apr 28, 2020
@rafiss rafiss added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgwire pgwire protocol issues. C-performance Perf of queries or internals. Solution not expected to change functional behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

No branches or pull requests

3 participants