-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kv: introduce setting for maximum lock wait-queue depth
Fixes #66017. This PR introduces a new `kv.lock_table.maximum_lock_wait_queue_length` cluster setting, which controls the maximum length of a lock wait-queue that requests are willing to enter and wait in. The setting can be used to ensure some level of quality-of-service under severe per-key contention. If set to a non-zero value and an existing lock wait-queue is already equal to or exceeding this length, requests will be rejected eagerly instead of entering the queue and waiting. Before this change, the lock-table's wait-queues had no limit on the number of writers that could be queued on a given key. This could lead to unbounded queueing and diminishing quality of service for all writers as the queues built up. It could also leave to starvation (i.e. zero throughput) when requests had a timeout that fires before any single request can get to the head of the queue. This was all especially bad with high replication latency in multi-region clusters, as locks are held for the duration of a consensus replication round. We can see this in the following experiment. Here, we run a multi-region (demo) cluster in three configurations: `default`, `timeout`, and `queue_limit`. Under the `default` configuration, we change nothing. Under the `timeout` configuration, we set `sql.defaults.statement_timeout='250ms'`. Under the `queue_limit` configuration, we set `kv.lock_table.maximum_lock_wait_queue_length=3`. We then run a single-row, update-only workload (workload "U", mocked out in this patch): ``` ./cockroach demo --global --empty --nodes=9 ./cockroach sql -e 'create database ycsb primary region "us-east1" regions "us-west1", "europe-west1" survive region failure' ./cockroach workload init ycsb --families=false --insert-count=1 ./cockroach workload run ycsb --families=false --insert-count=1 --workload=U --duration=30s --tolerate-errors --concurrency=? ``` This results in the following behavior: | setting | concurrency | qps | errors | p50 (ms) | p95 (ms) | |-------------|-------------|------|--------|----------|----------| | default | 1 | 13.7 | 0 | 67.1 | 71.3 | | default | 2 | 12.6 | 0 | 142.6 | 151.0 | | default | 4 | 12.3 | 0 | 302.0 | 385.9 | | default | 8 | 12.2 | 0 | 570.4 | 1610.6 | | default | 16 | 12.0 | 0 | 1208.0 | 2550.1 | | default | 32 | 8.0 | 0 | 4563.4 | 5637.1 | | timeout | 1 | 14.7 | 0 | 67.1 | 67.1 | | timeout | 2 | 12.8 | 17 | 142.6 | 142.6 | | timeout | 4 | 0.2 | 464 | 71.3 | 352.3 | | timeout | 8 | 0.2 | 913 | 67.1 | 335.5 | | timeout | 16 | 0 | - | - | - | | timeout | 32 | 0 | - | - | - | | queue_limit | 1 | 14.5 | 0 | 67.1 | 71.3 | | queue_limit | 2 | 14.2 | 0 | 134.2 | 176.2 | | queue_limit | 4 | 13.3 | 0 | 285.2 | 369.1 | | queue_limit | 8 | 13.0 | 1934 | 352.3 | 486.5 | | queue_limit | 16 | 12.8 | 4290 | 352.3 | 486.5 | | queue_limit | 32 | 11.6 | 9203 | 385.9 | 671.1 | The first thing to note is that under the `default` config, throughput remains relatively steady as concurrency grows, but latency grows linearly with concurrency. Next, note that under the `timeout` config, throughput falls to 0 the moment the p50 latency exceeds the `statement_timeout`. Finally, note that under the `queue_limit` config, errors begin to build once the queue limit is exceeded. However, throughput and latency hold steady as concurrency grows, as desired. So some requests are rejected, but the ones that are not are provided a good quality-of-service.
- Loading branch information
1 parent
9487fa2
commit c14c9a3
Showing
9 changed files
with
581 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.