Skip to content

Commit 7ca7906

Browse files
committed
sql: set default initial_retry_backoff_for_read_committed to 2ms
Testing was performed with a 3-node cluster running the following transaction repeatedly from 32 connections, all trying to lock the same row: ```sql BEGIN; SELECT 1; SELECT k, v FROM kv WHERE k IN (0) FOR UPDATE; -- 10 ms pause UPSERT INTO kv VALUES (0, <random byte>); COMMIT; ``` This workload was produced using the following commands: ``` cockroach workload init kv \ --sequential --cycle-length 1 --insert-count 1 \ --data-loader INSERT --user demo --db defaultdb cockroach workload run kv \ --sequential --cycle-length 1 --write-seq S0 \ --del-percent 0 --read-percent 0 --span-percent 0 \ --isolation-level read_committed \ --sel1-writes --sfu-writes --sfu-wait-delay 10ms \ --user demo --db defaultdb --concurrency 32 ``` For this workload, setting `initial_retry_backoff_for_read_committed` below 500μs caused more than 100 retries, and above 10ms caused excessively high PMax query latency. 1ms, 2ms, 4ms all performed well. We pick 2ms as this should be just at or below the typical execution time of most workloads. 2ms might be too low for longer-running statements (though still an improvement over 0ms, the current default). Release note (sql change): Set the default value of session variable `initial_retry_backoff_for_read_committed` to 2ms. Testing has shown that some high-contention workloads running under Read Committed isolation benefit from exponential backoff. 2ms might be too quick of an initial backoff for longer-running statements, but setting this much higher than the normal duration of execution will cause excessive delay.
1 parent 0fbd967 commit 7ca7906

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4011,7 +4011,7 @@ idle_in_transaction_session_timeout 0
40114011
idle_session_timeout 0
40124012
index_join_streamer_batch_size 8.0 MiB
40134013
index_recommendations_enabled off
4014-
initial_retry_backoff_for_read_committed 0
4014+
initial_retry_backoff_for_read_committed 2
40154015
inject_retry_errors_enabled off
40164016
inject_retry_errors_on_commit_enabled off
40174017
integer_datetimes on

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3005,7 +3005,7 @@ idle_in_transaction_session_timeout 0 N
30053005
idle_session_timeout 0 NULL NULL NULL string
30063006
index_join_streamer_batch_size 8.0 MiB NULL NULL NULL string
30073007
index_recommendations_enabled off NULL NULL NULL string
3008-
initial_retry_backoff_for_read_committed 0 NULL NULL NULL string
3008+
initial_retry_backoff_for_read_committed 2 NULL NULL NULL string
30093009
inject_retry_errors_enabled off NULL NULL NULL string
30103010
inject_retry_errors_on_commit_enabled off NULL NULL NULL string
30113011
integer_datetimes on NULL NULL NULL string
@@ -3236,7 +3236,7 @@ idle_in_transaction_session_timeout 0 N
32363236
idle_session_timeout 0 NULL user NULL 0s 0s
32373237
index_join_streamer_batch_size 8.0 MiB NULL user NULL 8.0 MiB 8.0 MiB
32383238
index_recommendations_enabled off NULL user NULL on false
3239-
initial_retry_backoff_for_read_committed 0 NULL user NULL 0s 0s
3239+
initial_retry_backoff_for_read_committed 2 NULL user NULL 2ms 2ms
32403240
inject_retry_errors_enabled off NULL user NULL off off
32413241
inject_retry_errors_on_commit_enabled off NULL user NULL off off
32423242
integer_datetimes on NULL user NULL on on

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ idle_in_transaction_session_timeout 0
119119
idle_session_timeout 0
120120
index_join_streamer_batch_size 8.0 MiB
121121
index_recommendations_enabled off
122-
initial_retry_backoff_for_read_committed 0
122+
initial_retry_backoff_for_read_committed 2
123123
inject_retry_errors_enabled off
124124
inject_retry_errors_on_commit_enabled off
125125
integer_datetimes on

pkg/sql/opt/exec/explain/output_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ func TestRetryFields(t *testing.T) {
362362
sqlDB := sqlutils.MakeSQLRunner(conn)
363363
sqlDB.Exec(t, "CREATE SEQUENCE s")
364364
sqlDB.Exec(t, "CREATE TABLE a (a INT)")
365+
// Speed up retries.
366+
sqlDB.Exec(t, "SET initial_retry_backoff_for_read_committed = '1us'")
365367

366368
retryCountRE := regexp.MustCompile(`number of transaction retries: (\d+)`)
367369
retryTimeRE := regexp.MustCompile(`time spent retrying the transaction: ([\d\.]+)[µsm]+`)

pkg/sql/vars.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4060,7 +4060,7 @@ var varGen = map[string]sessionVar{
40604060
return strconv.FormatInt(ms, 10), nil
40614061
},
40624062
GlobalDefault: func(sv *settings.Values) string {
4063-
return "0s"
4063+
return "2ms"
40644064
},
40654065
},
40664066
}

0 commit comments

Comments
 (0)