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
pgbench: reduced performance on RC vs. SSI with CTEs #109628
Comments
for additional context:
generate the workloadpgbench \
--initialize \
--host=${PGHOST} \
--username=${PGUSER} \
--port=${PGPORT} \
--no-vacuum \
--scale=10 \
${PGDATABASE} 1000000 of 1000000 tuples (100%) done (elapsed 6.26 s, remaining 0.00 s)
creating primary keys...
done in 67.70 s (drop tables 0.51 s, create tables 0.16 s, client-side generate 15.50 s, primary keys 51.53 s). run the built-in
|
I think I understand what's going on here now. First off, I found that Serializable and Snapshot behaved the same, so this was a difference between Snapshot and Read Committed, not between Serializable and Snapshot. That makes sense, because the transaction only performs writes (and there are no FKs), so SSI and SI should behave the same. I then found that the difference disappeared when I disabled per-statement read snapshots for RC. That's kind of strange, because this is a single-statement txn. Bisecting a few different callers led me to this code in cockroach/pkg/sql/conn_executor_exec.go Line 1446 in fea4eb0
The way to interpret this is that we are stepping the transaction's read timestamp (and by extension, provisional commit timestamp) between statements but then also immediately before committing. I believe this last part is unnecessary — there's no reason to step the read timestamp before committing. Doing so just unnecessarily inflates the transaction's commit timestamp. If I pass NOTE: Read Committed on the left, Serializable on the right It's interesting to reason about why this has such an effect. My current understanding of the difference is that by stepping the read timestamp before committing, we were causing RC transactions to commit at higher timestamps than they strictly needed to. For example, a transaction may have written its intents at timestamp 10, 10, and 12 (e.g. if there was an intra-statement refresh at some point). Once all of its intents were written, it could just go ahead and commit at timestamp 12. But instead, we were advancing the commit timestamp to 15 at the last moment. We'd then go and resolve all committed versions to timestamp 15. Doing so expanded the transaction's "contention footprint" (in the MVCC time domain, not real time), leading to more write-write version conflicts and generally more contention. Once the transaction committed at timestamp 15, all other transactions writing to overlapping keys now needed to write at at least timestamp 16. So it's easy to imagine that a conflicting transaction that wanted to write at timestamp 14 would have been fine had the first transaction run under serializable isolation (and would have just committed at 12) but forced to retry had the first transaction run under read committed. I think the fix here is simple — don't step the transaction's read timestamp in |
Fixes cockroachdb#109628. This commit removes the bumping of the read committed transactions' read timestamp in `connExecutor.commitSQLTransactionInternal`. Bumping the transaction's external read timestamp is not needed before committing, and it causes the transaction to commit at a higher timestamp than necessary. On highly contended workloads like the one from cockroachdb#109628, this can cause unnecessary contention by inflating the contention footprint of each transaction (i.e. the duration measured in the MVCC time domain that the transaction holds locks). By not bumping the read timestamp immediately before committed, we improve the performance of contended workloads. For example, on the workload from cockroachdb#109628, we see the following improvement: \## Summary ``` Serializable: 232.6 tps Read Committed (before): 225.3 tps Read Committed (after): 236.0 tps ``` Read Committed improves by **4.7%** and is now **1.5%** faster than Serializable on the workload. \## Raw ``` \### Serializable transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27935 number of transactions actually processed: 27584 number of transactions actually processed: 28380 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 107.483 ms latency average = 108.829 ms latency average = 105.776 ms latency stddev = 264.163 ms latency stddev = 263.132 ms latency stddev = 244.713 ms initial connection time = 12.315 ms initial connection time = 11.692 ms initial connection time = 9.448 ms tps = 232.157370 (without initial connection time) tps = 229.458565 (without initial connection time) tps = 236.039695 (without initial connection time) \### Read Committed (before) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27220 number of transactions actually processed: 27143 number of transactions actually processed: 26966 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 110.293 ms latency average = 110.646 ms latency average = 111.354 ms latency stddev = 173.640 ms latency stddev = 180.792 ms latency stddev = 179.226 ms initial connection time = 8.911 ms initial connection time = 9.894 ms initial connection time = 10.605 ms tps = 226.389120 (without initial connection time) tps = 225.427664 (without initial connection time) tps = 224.059547 (without initial connection time) \### Read Committed (after) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 28526 number of transactions actually processed: 28564 number of transactions actually processed: 28039 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 105.221 ms latency average = 105.114 ms latency average = 107.065 ms latency stddev = 196.386 ms latency stddev = 197.031 ms latency stddev = 203.784 ms initial connection time = 12.549 ms initial connection time = 11.212 ms initial connection time = 7.715 ms tps = 237.329979 (without initial connection time) tps = 237.417802 (without initial connection time) tps = 233.194327 (without initial connection time) ``` Release note: None
114652: sql: don't bump RC txn read timestamp before commit r=nvanbenschoten a=nvanbenschoten Fixes #109628. This commit removes the bumping of the read committed transactions' read timestamp in `connExecutor.commitSQLTransactionInternal`. Bumping the transaction's external read timestamp is not needed before committing, and it causes the transaction to commit at a higher timestamp than necessary. On highly contended workloads like the one from #109628, this can cause unnecessary contention by inflating the contention footprint of each transaction (i.e. the duration measured in the MVCC time domain that the transaction holds locks). By not bumping the read timestamp immediately before committed, we improve the performance of contended workloads. For example, on the workload from #109628, we see the following improvement: ## Summary ``` Serializable: 232.6 tps Read Committed (before): 225.3 tps Read Committed (after): 236.0 tps ``` Read Committed improves by **4.7%** and is now **1.5%** faster than Serializable on the workload. ## Raw ``` ### Serializable transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27935 number of transactions actually processed: 27584 number of transactions actually processed: 28380 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 107.483 ms latency average = 108.829 ms latency average = 105.776 ms latency stddev = 264.163 ms latency stddev = 263.132 ms latency stddev = 244.713 ms initial connection time = 12.315 ms initial connection time = 11.692 ms initial connection time = 9.448 ms tps = 232.157370 (without initial connection time) tps = 229.458565 (without initial connection time) tps = 236.039695 (without initial connection time) ### Read Committed (before) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27220 number of transactions actually processed: 27143 number of transactions actually processed: 26966 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 110.293 ms latency average = 110.646 ms latency average = 111.354 ms latency stddev = 173.640 ms latency stddev = 180.792 ms latency stddev = 179.226 ms initial connection time = 8.911 ms initial connection time = 9.894 ms initial connection time = 10.605 ms tps = 226.389120 (without initial connection time) tps = 225.427664 (without initial connection time) tps = 224.059547 (without initial connection time) ### Read Committed (after) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 28526 number of transactions actually processed: 28564 number of transactions actually processed: 28039 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 105.221 ms latency average = 105.114 ms latency average = 107.065 ms latency stddev = 196.386 ms latency stddev = 197.031 ms latency stddev = 203.784 ms initial connection time = 12.549 ms initial connection time = 11.212 ms initial connection time = 7.715 ms tps = 237.329979 (without initial connection time) tps = 237.417802 (without initial connection time) tps = 233.194327 (without initial connection time) ``` Release note: None Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
Fixes #109628. This commit removes the bumping of the read committed transactions' read timestamp in `connExecutor.commitSQLTransactionInternal`. Bumping the transaction's external read timestamp is not needed before committing, and it causes the transaction to commit at a higher timestamp than necessary. On highly contended workloads like the one from #109628, this can cause unnecessary contention by inflating the contention footprint of each transaction (i.e. the duration measured in the MVCC time domain that the transaction holds locks). By not bumping the read timestamp immediately before committed, we improve the performance of contended workloads. For example, on the workload from #109628, we see the following improvement: \## Summary ``` Serializable: 232.6 tps Read Committed (before): 225.3 tps Read Committed (after): 236.0 tps ``` Read Committed improves by **4.7%** and is now **1.5%** faster than Serializable on the workload. \## Raw ``` \### Serializable transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27935 number of transactions actually processed: 27584 number of transactions actually processed: 28380 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 107.483 ms latency average = 108.829 ms latency average = 105.776 ms latency stddev = 264.163 ms latency stddev = 263.132 ms latency stddev = 244.713 ms initial connection time = 12.315 ms initial connection time = 11.692 ms initial connection time = 9.448 ms tps = 232.157370 (without initial connection time) tps = 229.458565 (without initial connection time) tps = 236.039695 (without initial connection time) \### Read Committed (before) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 27220 number of transactions actually processed: 27143 number of transactions actually processed: 26966 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 110.293 ms latency average = 110.646 ms latency average = 111.354 ms latency stddev = 173.640 ms latency stddev = 180.792 ms latency stddev = 179.226 ms initial connection time = 8.911 ms initial connection time = 9.894 ms initial connection time = 10.605 ms tps = 226.389120 (without initial connection time) tps = 225.427664 (without initial connection time) tps = 224.059547 (without initial connection time) \### Read Committed (after) transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql transaction type: tpcb-cockroach.sql scaling factor: 10 scaling factor: 10 scaling factor: 10 query mode: simple query mode: simple query mode: simple number of clients: 25 number of clients: 25 number of clients: 25 number of threads: 10 number of threads: 10 number of threads: 10 duration: 120 s duration: 120 s duration: 120 s number of transactions actually processed: 28526 number of transactions actually processed: 28564 number of transactions actually processed: 28039 number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of failed transactions: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of serialization failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of deadlock failures: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) number of transactions retried: 0 (0.000%) total number of retries: 0 total number of retries: 0 total number of retries: 0 latency average = 105.221 ms latency average = 105.114 ms latency average = 107.065 ms latency stddev = 196.386 ms latency stddev = 197.031 ms latency stddev = 203.784 ms initial connection time = 12.549 ms initial connection time = 11.212 ms initial connection time = 7.715 ms tps = 237.329979 (without initial connection time) tps = 237.417802 (without initial connection time) tps = 233.194327 (without initial connection time) ``` Release note: None
When running pgbench with RC, we found that the explicit transaction case was faster with RC than with SSI.
However, with a workload rewrite that uses CTEs, performance was better with SSI than RC.
We should understand why.
Reproduction steps:
Jira issue: CRDB-31025
The text was updated successfully, but these errors were encountered: