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

region: update region-size from 96MB to 256MB. #18336

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions best-practices/massive-regions-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ Hibernate Region 在 [TiKV master](https://github.com/tikv/tikv/tree/master) 分
{{< copyable "" >}}

```
config set max-merge-region-size 20
config set max-merge-region-keys 200000
config set max-merge-region-size 54
config set max-merge-region-keys 540000
config set merge-schedule-limit 8
```

Expand All @@ -134,7 +134,11 @@ config set merge-schedule-limit 8

### 方法六:调整 Region 大小

Region 默认的大小约为 96 MiB,将其调大也可以减少 Region 个数,具体介绍可参考[使用更大的 Region](/tune-region-performance.md)。
Region 默认的大小约为 256 MiB,将其调大也可以减少 Region 个数,具体介绍可参考[使用更大的 Region](/tune-region-performance.md)。
LykxSassinator marked this conversation as resolved.
Show resolved Hide resolved

> **注意:**
>
> 从 v8.4.0 开始,Region 的默认值从 96 MiB 调整为 256 MiB。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For deployments upgraded from a prior version, is there anything to be aware of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already specified in "/tune-region-performance.md".

LykxSassinator marked this conversation as resolved.
Show resolved Hide resolved

> **警告:**
>
Expand Down
4 changes: 2 additions & 2 deletions best-practices/pd-scheduling-best-practices.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ Region merge 指的是为了避免删除数据后大量小甚至空的 Region

具体来说,当某个新分裂出来的 Region 存在的时间超过配置项 [`split-merge-interval`](/pd-configuration-file.md#split-merge-interval) 的值(默认 1h)后,如果同时满足以下情况,该 Region 会触发 Region merge 调度:

- 该 Region 大小小于配置项 [`max-merge-region-size`](/pd-configuration-file.md#max-merge-region-size) 的值(默认 20 MiB
- 该 Region 中 key 的数量小于配置项 [`max-merge-region-keys`](/pd-configuration-file.md#max-merge-region-keys) 的值(默认 200000
- 该 Region 大小小于配置项 [`max-merge-region-size`](/pd-configuration-file.md#max-merge-region-size) 的值。从 v8.4.0 开始,该配置项的默认值从 20 MiB 调整为 54 MiB。该变更仅对新集群生效,已有集群不受影响。
- 该 Region 中 key 的数量小于配置项 [`max-merge-region-keys`](/pd-configuration-file.md#max-merge-region-keys) 的值。从 v8.4.0 开始,该配置项的默认值从 200000 调整为 540000。该变更仅对新集群生效,已有集群不受影响。

## 查询调度状态

Expand Down
2 changes: 1 addition & 1 deletion glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Pending 和 Down 是 Peer 可能出现的两种特殊状态。其中 Pending 表

### Region/Peer/Raft Group

每个 Region 负责维护集群的一段连续数据(默认配置下平均约 96 MiB),每份数据会在不同的 Store 存储多个副本(默认配置是 3 副本),每个副本称为 Peer。同一个 Region 的多个 Peer 通过 raft 协议进行数据同步,所以 Peer 也用来指代 raft 实例中的成员。TiKV 使用 multi-raft 模式来管理数据,即每个 Region 都对应一个独立运行的 raft 实例,我们也把这样的一个 raft 实例叫做一个 Raft Group。
每个 Region 负责维护集群的一段连续数据(默认配置下平均约 256 MiB),每份数据会在不同的 Store 存储多个副本(默认配置是 3 副本),每个副本称为 Peer。同一个 Region 的多个 Peer 通过 raft 协议进行数据同步,所以 Peer 也用来指代 raft 实例中的成员。TiKV 使用 multi-raft 模式来管理数据,即每个 Region 都对应一个独立运行的 raft 实例,我们也把这样的一个 raft 实例叫做一个 Raft Group。

### Region Split

Expand Down
8 changes: 4 additions & 4 deletions information-schema/information-schema-cluster-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ SELECT * FROM cluster_config WHERE type='tikv' AND `key` LIKE 'coprocessor%';
| TYPE | INSTANCE | KEY | VALUE |
+------+-----------------+-----------------------------------+---------+
| tikv | 127.0.0.1:20165 | coprocessor.batch-split-limit | 10 |
| tikv | 127.0.0.1:20165 | coprocessor.region-max-keys | 1440000 |
| tikv | 127.0.0.1:20165 | coprocessor.region-max-size | 144MiB |
| tikv | 127.0.0.1:20165 | coprocessor.region-split-keys | 960000 |
| tikv | 127.0.0.1:20165 | coprocessor.region-split-size | 96MiB |
| tikv | 127.0.0.1:20165 | coprocessor.region-max-keys | 3840000 |
| tikv | 127.0.0.1:20165 | coprocessor.region-max-size | 384MiB |
| tikv | 127.0.0.1:20165 | coprocessor.region-split-keys | 2560000 |
| tikv | 127.0.0.1:20165 | coprocessor.region-split-size | 256MiB |
| tikv | 127.0.0.1:20165 | coprocessor.split-region-on-table | false |
+------+-----------------+-----------------------------------+---------+
6 rows in set (0.00 sec)
Expand Down
4 changes: 2 additions & 2 deletions pd-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ pd-server 相关配置项。
### `max-merge-region-size`

+ 控制 Region Merge 的 size 上限,当 Region Size 大于指定值时 PD 不会将其与相邻的 Region 合并。
+ 默认:20
+ 默认:54。在 v8.4.0 之前,默认值为 20。
+ 单位:MiB

### `max-merge-region-keys`

+ 控制 Region Merge 的 key 上限,当 Region key 大于指定值时 PD 不会将其与相邻的 Region 合并。
+ 默认:200000
+ 默认:540000。在 v8.4.0 之前,默认值为 200000

### `patrol-region-interval`

Expand Down
4 changes: 2 additions & 2 deletions pd-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ config show
"leader-schedule-limit": 4,
"leader-schedule-policy": "count",
"low-space-ratio": 0.8,
"max-merge-region-keys": 200000,
"max-merge-region-size": 20,
"max-merge-region-keys": 540000,
"max-merge-region-size": 54,
"max-pending-peer-count": 64,
"max-snapshot-count": 64,
"max-store-down-time": "30m0s",
Expand Down
2 changes: 1 addition & 1 deletion tidb-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TiKV 利用 Raft 来做数据复制,每个数据变更都会落地为一条 Ra
* Hash:按照 Key 做 Hash,根据 Hash 值选择对应的存储节点。
* Range:按照 Key 分 Range,某一段连续的 Key 都保存在一个存储节点上。

TiKV 选择了第二种方式,将整个 Key-Value 空间分成很多段,每一段是一系列连续的 Key,将每一段叫做一个 Region,可以用 [StartKey,EndKey) 这样一个左闭右开区间来描述。每个 Region 中保存的数据量默认维持在 96 MiB 左右(可以通过配置修改)。
TiKV 选择了第二种方式,将整个 Key-Value 空间分成很多段,每一段是一系列连续的 Key,将每一段叫做一个 Region,可以用 [StartKey,EndKey) 这样一个左闭右开区间来描述。每个 Region 中保存的数据量默认维持在 256 MiB 左右(可以通过配置修改)。

![Region in TiDB](/media/tidb-storage-2.png)

Expand Down
6 changes: 3 additions & 3 deletions tikv-configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ Coprocessor 相关的配置项。
### `region-split-size`

+ 分裂后新 Region 的大小,此值属于估算值。
+ 默认值:96MiB
+ 默认值:`"256MiB"`。在 v8.4.0 之前,默认值为 `"96MiB"`。
+ 单位:KiB|MiB|GiB

### `region-max-keys`
Expand All @@ -1092,7 +1092,7 @@ Coprocessor 相关的配置项。
### `region-split-keys`

+ 分裂后新 Region 的 key 的个数,此值属于估算值。
+ 默认值:960000
+ 默认值:`"2560000"`。在 v8.4.0 之前,默认值为 `"960000"`。

### `consistency-check-method`

Expand Down Expand Up @@ -2150,7 +2150,7 @@ Raft Engine 相关的配置项。

+ 备份 SST 文件大小的阈值。如果 TiKV Region 中备份文件的大小超过该阈值,则将该文件备份到 Region 分割的多个 Region 文件中,每个分割 Region 中的文件大小均为 `sst-max-size`(或略大)。
+ 例如,当 Region `[a,e)` 中备份文件大小超过 `sst-max-size` 时,该文件会被备份到多个 Region 范围中,分别为 Region `[a,b)`、`[b,c)`、`[c,d)` 和 `[d,e)`,并且 `[a,b)`、`[b,c)` 和 `[c,d)` 的大小均为 `sst-max-size`(或略大)。
+ 默认值:`"144MiB"`
+ 默认值:`"384MiB"`。在 v8.4.0 之前,默认值为 `"144MiB"`

### `enable-auto-tune` <span class="version-mark">从 v5.4 版本开始引入</span>

Expand Down
2 changes: 1 addition & 1 deletion tikv-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ TiKV 是一个分布式事务型的键值数据库,提供了满足 ACID 约束

Region 与副本之间通过 Raft 协议来维持数据一致性,任何写请求都只能在 Leader 上写入,并且需要写入多数副本后(默认配置为 3 副本,即所有请求必须至少写入两个副本成功)才会返回客户端写入成功。

TiKV 会尽量保持每个 Region 中保存的数据在一个合适的大小,目前默认是 96 MB,这样更有利于 PD 进行调度决策。当某个 Region 的大小超过一定限制(默认是 144 MiB)后,TiKV 会将它分裂为两个或者更多个 Region。同样,当某个 Region 因为大量的删除请求而变得太小时(默认是 20 MiB),TiKV 会将比较小的两个相邻 Region 合并为一个。
TiKV 会尽量保持每个 Region 中保存的数据在一个合适的大小,目前默认是 256 MB,这样更有利于 PD 进行调度决策。当某个 Region 的大小超过一定限制(默认是 384 MiB)后,TiKV 会将它分裂为两个或者更多个 Region。同样,当某个 Region 因为大量的删除请求而变得太小时(默认是 54 MiB),TiKV 会将比较小的两个相邻 Region 合并为一个。

当 PD 需要把某个 Region 的一个副本从一个 TiKV 节点调度到另一个上面时,PD 会先为这个 Raft Group 在目标节点上增加一个 Learner 副本(虽然会复制 Leader 的数据,但是不会计入写请求的多数副本中)。当这个 Learner 副本的进度大致追上 Leader 副本时,Leader 会将它变更为 Follower,之后再移除操作节点的 Follower 副本,这样就完成了 Region 副本的一次调度。

Expand Down
4 changes: 2 additions & 2 deletions tune-tikv-memory-performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ region-split-check-diff = "32MB"

## 当区间为 [a,e) 的 Region 的大小超过 `region_max_size`,TiKV 会尝试分裂该 Region,例如分裂成 [a,b)、[b,c)、[c,d)、[d,e) 等区间的 Region 后
## 这些 Region [a,b), [b,c), [c,d) 的大小为 `region_split_size` (或者稍大于 `region_split_size`)
# region-max-size = "144MB"
# region-split-size = "96MB"
# region-max-size = "384MB"
# region-split-size = "256MB"

[rocksdb]
# RocksDB 进行后台任务的最大线程数,后台任务包括 compaction 和 flush。具体 RocksDB 为什么需要进行 compaction,
Expand Down