You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: storage-engine/titan-configuration.md
+84-63Lines changed: 84 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -5,25 +5,27 @@ summary: Learn how to configure Titan.
5
5
6
6
# Titan Configuration
7
7
8
-
This document introduces how to enable and disable [Titan](/storage-engine/titan-overview.md) using the corresponding configuration items, as well as the relevant parameters and the Level Merge feature.
8
+
This document introduces how to enable and disable [Titan](/storage-engine/titan-overview.md) using the corresponding configuration items, data convertion mechanism, the relevant parameters, and the Level Merge feature.
9
9
10
10
## Enable Titan
11
11
12
-
Titan is compatible with RocksDB, so you can directly enable Titan on the existing TiKV instances that use RocksDB. You can use one of the following two methods to enable Titan:
12
+
> **Note:**
13
+
>
14
+
> - Starting from TiDB v7.6.0, Titan is enabled by default for new clusters to enhance the performance of writing wide tables and JSON data. The default value of the [`min-blob-size`](/tikv-configuration-file.md#min-blob-size) threshold is changed from `1KB` to `32KB`.
15
+
> - Existing clusters upgraded to v7.6.0 or later versions retain the original configuration, which means that if Titan is not explicitly enabled, it still uses RocksDB.
16
+
> - If you have enabled Titan before upgrading a cluster to TiDB v7.6.0 or later versions, Titan will be enabled after the upgrade, and the configuration of [`min-blob-size`](/tikv-configuration-file.md#min-blob-size) before the upgrade will also be retained. If you do not explicitly configure the value before the upgrade, the default value of the old version `1KB` will be retained to ensure the stability of the cluster configuration after the upgrade.
13
17
14
-
+ Method 1: If you have deployed the cluster using TiUP, you can execute the `tiup cluster edit-config ${cluster-name}` command and edit the TiKV configuration file as the following example shows:
18
+
Titan is compatible with RocksDB, so you can directly enable Titan on the existing TiKV instances that use RocksDB. You can use one of the following methods to enable Titan:
15
19
16
-
{{< copyable "shell-regular" >}}
20
+
+ Method 1: If you have deployed the cluster using TiUP, you can execute the `tiup cluster edit-config ${cluster-name}` command and edit the TiKV configuration file as the following example shows:
17
21
18
22
```shell
19
-
tikv:
20
-
rocksdb.titan.enabled: true
23
+
tikv:
24
+
rocksdb.titan.enabled: true
21
25
```
22
26
23
27
Reload the configuration and TiKV will be rolling restarted dynamically:
24
28
25
-
{{< copyable "shell-regular">}}
26
-
27
29
```shell
28
30
tiup cluster reload ${cluster-name} -R tikv
29
31
```
@@ -32,83 +34,98 @@ Titan is compatible with RocksDB, so you can directly enable Titan on the existi
32
34
33
35
+ Method 2: Directly edit the TiKV configuration file to enable Titan (**NOT** recommended for the production environment).
34
36
35
-
{{< copyable "">}}
36
-
37
-
``` toml
37
+
```toml
38
38
[rocksdb.titan]
39
39
enabled = true
40
40
```
41
41
42
-
After Titan is enabled, the existing data stored in RocksDB is not immediately moved to the Titan engine. As new data is written to the TiKV foreground and RocksDB performs compaction, the values are progressively separated from keys and written to Titan. You can view the **TiKV Details** ->**Titan kv** ->**blob file size** panel to confirm the size of the data stored in Titan.
42
+
+ Method 3: Edit the `${cluster_name}/tidb-cluster.yaml` configuration file for TiDB Operator:
43
43
44
-
If you want to speed up the writing process, compact data of the whole TiKV cluster manually using tikv-ctl. For details, see [manual compaction](/tikv-control.md#compact-data-of-the-whole-tikv-cluster-manually).
Apply the configuration to trigger an online rolling restart of the TiDB cluster for the changes to take effect:
59
+
60
+
```shell
61
+
kubectl apply -f ${cluster_name} -n ${namespace}
62
+
```
63
+
64
+
For more information, refer to [Configuring a TiDB Cluster in Kubernetes](https://docs.pingcap.com/tidb-in-kubernetes/stable/configure-a-tidb-cluster).
65
+
66
+
## Data Convertion
67
+
68
+
>**Warning:**
47
69
>
48
-
> When Titan is disabled, RocksDB cannot read data that has been migrated to Titan. If Titan is incorrectly disabled on a TiKV instance with Titan already enabled (mistakenly set`rocksdb.titan.enabled` to `false`), TiKV will fail to start, and the `You have disabled titan when its data directory is not empty` error appears in the TiKV log. To correctly disabled Titan, see [Disable Titan](#disable-titan).
70
+
> When Titan is disabled, RocksDB cannot read data that has been moved to Titan. If Titan is incorrectly disabled on a TiKV instance with Titan already enabled (mistakenly set`rocksdb.titan.enabled` to `false`), TiKV will fail to start, and the `You have disabled titan when its data directory is not empty` error appears in the TiKV log. To correctly disabled Titan, see [Disable Titan](#disable-titan).
49
71
50
-
## Parameters
72
+
After Titan is enabled, the existing data stored in RocksDB is not immediately moved to the Titan engine. As new data is written to the TiKV and RocksDB performs compaction, **the values are progressively separated from keys and written to Titan**. Similarly, the data restored through BR snapshot/log, the data converted during scaling, or the data imported by TiDB Lightning Physical Import Mode, is not written directly into Titan. As compaction proceeds, the large values exceeding the default value (`32KB`) of [`min-blob-size`](/tikv-configuration-file.md#min-blob-size) in the processed SST files are separated into Titan. You can monitor the size of files stored in Titan by observing the **TiKV Details > Titan kv > blob file size** panel to estimate the data size.
51
73
52
-
To adjust Titan-related parameters using TiUP, refer to [Modify the configuration](/maintain-tidb-using-tiup.md#modify-the-configuration).
74
+
If you want to speed up the writing process, you can use tikv-ctl to compact data of the whole TiKV cluster manually. For details, see [manual compaction](/tikv-control.md#compact-data-of-the-whole-tikv-cluster-manually). The data access is continuous during the convertion from RocksDB to Titan, therefore the block cache of RocksDB significantly accelerates the data convertion process. In the test, by using tikv-ctl, a volume of 670 GiB TiKV data can be converted to Titan in one hour.
53
75
54
-
+ Titan GC thread count.
76
+
Note that the values inTitan Blob files are not continuous, and Titan's cache is at the value level, so the Blob Cache does not help during compaction. The convertion speed from Titan to RocksDB is an order of magnitude slower than that from RocksDB to Titan. In the test, it takes 12 hours to convert a volume of 800 GiB Titan data on a TiKV node to RocksDB by tikv-ctl in a full compaction.
55
77
56
-
From the **TiKV Details** ->**Thread CPU** ->**RocksDB CPU** panel, if you observe that the Titan GC threads are at full capacity for a long time, consider increasing the size of the Titan GC thread pool.
78
+
## Parameters
57
79
58
-
{{< copyable "">}}
80
+
By properly configuring Titan parameters, you can effectively improve database performance and resource utilization. This section introduces some key parameters you can use.
59
81
60
-
```toml
61
-
[rocksdb.titan]
62
-
max-background-gc = 1
63
-
```
82
+
### `min-blob-size`
64
83
65
-
+ Value sizethreshold.
84
+
You can use [`min-blob-size`](/tikv-configuration-file.md#min-blob-size) to set the threshold for the value size to determine which data is stored in RocksDB and which in Titan's blob files. According to the test, `32KB` is a appropriate threshold that has better write throughput without scan throughput regression compared with RocksDB. If you want further improve write performance and accept scan performance regression, you can change the value to `1KB`.
66
85
67
-
When the size of the value written to the foreground is smaller than the threshold, this value is stored in RocksDB; otherwise, this value is stored in the blobfile of Titan. Based on the distribution of value sizes, if you increase the threshold, more values are stored in RocksDB and TiKV performs better in reading small values. If you decrease the threshold, more values go to Titan, which further reduces RocksDB compactions.
86
+
### `blob-file-compression` and `zstd-dict-size`
68
87
69
-
```toml
70
-
[rocksdb.defaultcf.titan]
71
-
min-blob-size = "1KB"
72
-
```
88
+
You can use [`blob-file-compression`](/tikv-configuration-file.md#blob-file-compression) to specify the compression algorithm used forvaluesin Titan. You can also enable the `zstd` dictionary compression through [`zstd-dict-size`](/tikv-configuration-file.md#zstd-dict-size) to improve the compression rate.
73
89
74
-
+ The algorithm used forcompressing valuesin Titan, which takes value as the unit.
90
+
### `blob-cache-size`
75
91
76
-
```toml
77
-
[rocksdb.defaultcf.titan]
78
-
blob-file-compression = "lz4"
79
-
```
92
+
You can use [`blob-cache-size`](/tikv-configuration-file.md#blob-cache-size) to control the cache size of values in Titan. Larger cache size means higher read performance of Titan. However, too large a cache size causes Out of Memory (OOM) issues.
80
93
81
-
+ The size of value caches in Titan.
94
+
It is recommended to set the value of `storage.block-cache.capacity` to the store size minus the blob file size, and set`blob-cache-size` to `memory size * 50% - block cache size` according to the monitoring metrics when the database is running stably. This maximizes the blob cache size when the block cache is large enough for the whole RocksDB engine.
82
95
83
-
Larger cache size means higher read performance of Titan. However, too large a cache size causes Out of Memory (OOM). It is recommended to set the value of `storage.block-cache.capacity` to the store size minus the blob file size and set`blob-cache-size` to `memory size * 50% - block cache size` according to the monitoring metrics when the database is running stably. This maximizes the blob cache size when the block cache is large enough for the whole RocksDB engine.
96
+
### `discardable-ratio` and `max-background-gc`
84
97
85
-
```toml
86
-
[rocksdb.defaultcf.titan]
87
-
blob-cache-size = 0
88
-
```
98
+
The [`discardable-ratio`](/tikv-configuration-file.md#discardable-ratio) parameter and [`max-background-gc`](/tikv-configuration-file.md#max-background-gc) parameter significantly impact Titan's read performance and garbage collection process.
89
99
90
-
+ When the ratio of discardable data (the corresponding key has been updated or deleted) in a blob file exceeds the following threshold, Titan GC is triggered.
100
+
When the ratio of obsolete data (the corresponding key has been updated or deleted) in a blob file exceeds the threshold set by [`discardable-ratio`](/tikv-configuration-file.md#discardable-ratio), Titan GC is triggered. Reducing this threshold can reduce space amplification but can cause more frequent Titan GC. Increasing this value can reduce Titan GC, I/O bandwidth, and CPU consumption, but increase disk space usage.
91
101
92
-
```toml
93
-
discardable-ratio = 0.5
94
-
```
102
+
If you observe that the Titan GC thread is in full load for a long time from **TiKV Details** - **Thread CPU** - **RocksDB CPU**, consider adjusting [`max-background-gc`](/tikv-configuration-file.md#max-background-gc) to increase the Titan GC thread pool size.
95
103
96
-
When Titan writes the useful data of this blob file to another file, you can use the `discardable-ratio` value to estimate the upper limits of write amplification and space amplification (assuming the compression is disabled).
104
+
### `rate-bytes-per-sec`
97
105
98
-
Upper limit of write amplification = 1 / discardable_ratio
106
+
You can adjust [`rate-bytes-per-sec`](/tikv-configuration-file.md#rate-bytes-per-sec) to limit the I/O rate of RocksDB compaction, reducing its impact on foreground read and write performance during high traffic.
99
107
100
-
Upper limit of space amplification = 1 / (1 - discardable_ratio)
108
+
### Titan configuration example
101
109
102
-
From the two equations above, you can see that decreasing the value of `discardable_ratio` can reduce space amplification but causes GC to be more frequent in Titan. Increasing the value reduces Titan GC, the corresponding I/O bandwidth, and CPU consumption but increases disk usage.
110
+
The following is an example of the Titan configuration file. You can either [use TiUP to modify the configuration](/maintain-tidb-using-tiup.md#modify-the-configuration) or [configure a TiDB cluster on Kubernetes](https://docs.pingcap.com/tidb-in-kubernetes/stable/configure-a-tidb-cluster).
103
111
104
-
+ The following option limits the I/O rate of RocksDB compaction. During peak traffic, limiting RocksDB compaction, its I/O bandwidth, and its CPU consumption reduces its impact on the write and read performance of the foreground.
112
+
```toml
113
+
[rocksdb]
114
+
rate-bytes-per-sec = 0
105
115
106
-
When Titan is enabled, this option limits the summed I/O rates of RocksDB compaction and Titan GC. If you find that the I/O and/or CPU consumption of RocksDB compaction and Titan GC is too large, set this option to a suitable value according the disk I/O bandwidth and the actual write traffic.
116
+
[rocksdb.titan]
117
+
enabled = true
118
+
max-background-gc = 1
107
119
108
-
```toml
109
-
[rocksdb]
110
-
rate-bytes-per-sec = 0
111
-
```
120
+
[rocksdb.defaultcf.titan]
121
+
min-blob-size = "32KB"
122
+
blob-file-compression = "zstd"
123
+
zstd-dict-size = "16KB"
124
+
blob-cache-size = "0GB"
125
+
discardable-ratio = 0.5
126
+
blob-run-mode = "normal"
127
+
level-merge = false
128
+
```
112
129
113
130
## Disable Titan
114
131
@@ -118,26 +135,30 @@ To disable Titan, you can configure the `rocksdb.defaultcf.titan.blob-run-mode`
118
135
- When the option is set to `read-only`, all newly written values are written into RocksDB, regardless of the value size.
119
136
- When the option is set to `fallback`, all newly written values are written into RocksDB, regardless of the value size. Also, all compacted values stored in the Titan blob file are automatically moved back to RocksDB.
120
137
121
-
To fully disable Titan for all existing and future data, you can follow these steps:
138
+
To fully disable Titan for all existing and future data, you can follow these steps. Note that you can skip Step 2 because it greatly impacts online traffic performance. In fact even without Step 2, the data compaction consumes extra I/O and CPU resources when it moves data from Titan to RocksDB, and performance will degrade (sometimes as much as 50%) when TiKV I/O or CPU resources are limited.
122
139
123
140
1. Update the configuration of the TiKV nodes you wish to disable Titan for. You can update configuration in two methods:
124
141
125
142
+ Execute `tiup cluster edit-config`, edit the configuration file, and execute `tiup cluster reload -R tikv`.
126
143
+ Manually update the configuration file and restart TiKV.
127
144
128
-
```toml
129
-
[rocksdb.defaultcf.titan]
130
-
blob-run-mode = "fallback"
131
-
discardable-ratio = 1.0
132
-
```
145
+
```toml
146
+
[rocksdb.defaultcf.titan]
147
+
blob-run-mode = "fallback"
148
+
discardable-ratio = 1.0
149
+
```
150
+
151
+
> **Note:**
152
+
>
153
+
> When there is insufficient disk space to accommodate both Titan and RocksDB data, it is recommended to use the default value of `0.5` for [`discardable-ratio`](/tikv-configuration-file.md#discardable-ratio). In general, the default value is recommended when available disk space is less than 50%. This is because when `discardable-ratio = 1.0`, the RocksDB data continues to increase. At the same time, the recycling of existing blob files in Titan requires all the data in that file to be converted to RocksDB, which is a slow process. However, if the disk size is large enough, setting `discardable-ratio = 1.0` can reduce the GC of the blob file itself during compaction, which saves bandwidth.
133
154
134
-
2. Perform a full compaction using tikv-ctl. This process will consume large amount of I/O and CPU resources.
155
+
2. (Optional) Perform a full compaction using tikv-ctl. This process will consume a large amount of I/O and CPU resources.
135
156
136
157
```bash
137
158
tikv-ctl --pd <PD_ADDR> compact-cluster --bottommost force
138
159
```
139
160
140
-
3. After the compaction is finished, you should waitfor the **Blob file count** metrics under **TiKV-Details**/**Titan - kv** to decrease to `0`.
161
+
3. After the compaction is finished, wait for the **Blob file count** metrics under **TiKV-Details**/**Titan - kv** to decrease to `0`.
141
162
142
163
4. Update the configuration of these TiKV nodes to disable Titan.
Copy file name to clipboardExpand all lines: storage-engine/titan-overview.md
+6Lines changed: 6 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -31,6 +31,8 @@ The prerequisites for enabling Titan are as follows:
31
31
- No range query will be performed or you do not need a high performance of range query. Because the data stored in Titan is not well-ordered, its performance of range query is poorer than that of RocksDB, especially for the query of a large range. According PingCAP's internal test, Titan's range query performance is 40% to a few times lower than that of RocksDB.
32
32
- Sufficient disk space (consider reserving a space twice of the RocksDB disk consumption with the same data volume). This is because Titan reduces write amplification at the cost of disk space. In addition, Titan compresses values one by one, and its compression rate is lower than that of RocksDB. RocksDB compresses blocks one by one. Therefore, Titan consumes more storage space than RocksDB, which is expected and normal. In some situations, Titan's storage consumption can be twice that of RocksDB.
33
33
34
+
Starting from v7.6.0, Titan is enabled by default for newly created clusters. Because small TiKV values remain stored in RocksDB, you can enable Titan in this scenario as well.
35
+
34
36
If you want to improve the performance of Titan, see the blog post [Titan: A RocksDB Plugin to Reduce Write Amplification](https://pingcap.com/blog/titan-storage-engine-design-and-implementation/).
35
37
36
38
## Architecture and implementation
@@ -124,3 +126,7 @@ Range Merge is an optimized approach of GC based on Level Merge. However, the bo
124
126

125
127
126
128
Therefore, the Range Merge operation is needed to keep the number of sorted runs within a certain level. At the time of OnCompactionComplete, Titan counts the number of sorted runs in a range. If the number is large, Titan marks the corresponding blob file as ToMerge and rewrites it in the next compaction.
129
+
130
+
### Scale out and scale in
131
+
132
+
For backward compatibility, the TiKV snapshots are still in the RocksDB format during scaling. Because the scaled nodes are all from RocksDB at the beginning, they carry the characteristics of RocksDB, such as higher compression rate than the old TiKV nodes, smaller store size, and relatively larger write amplification in compaction. These SST files in RocksDB format will be gradually converted to Titan format after compaction.
0 commit comments