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

best-practices: add massive region performance improvement doc #2039

Merged
merged 14 commits into from
Nov 22, 2019

Conversation

TomShawn
Copy link
Contributor

@TomShawn TomShawn commented Nov 13, 2019

What is changed, added or deleted?

This PR adds the massive Region performance improvement doc.
The added documents have been tailored for each version. Therefore, v2.1 is a little different from other versions.

What is the related PR or file link(s)?

https://pingcap.com/blog-cn/best-practice-massive-regions-performance-improvement/

Which version does your change affect?

dev, v2.1, v3.0, v3.1

@TomShawn TomShawn added v2.1 area/best-practices Adds or updates TiDB best practices. labels Nov 13, 2019
@TomShawn TomShawn changed the title best-practices: add massiv region performance improvement doc best-practices: add massive region performance improvement doc Nov 13, 2019
@TomShawn TomShawn requested a review from Connor1996 November 13, 2019 12:46

需要注意的是,该 tick 消息的间隔也决定了 `election timeout` 和 `heartbeat` 的间隔。示例如下:

{{< copyable "" >}}
Copy link
Member

Choose a reason for hiding this comment

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

这是什么?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果代码块里的内容是用户需要复制的(比如可执行的 shell/bash 命令、SQL 语句等),则为了在渲染官网时代码块前能自动添加相应命令前缀($、# 或 >),必须在代码块前添加渲染程序可识别的 code snippet。


如果 IO 资源和 CPU 资源都有较多盈余,可在单台机器上部署多个 TiKV 实例,以减少单个 TiKV 实例上的 Region 个数;或者增加扩容 TiKV 集群的机器数。

### 方法二:调整 `raft-base-tick-interval`
Copy link
Member

Choose a reason for hiding this comment

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

缺少“开启 Region Merge”

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v3.0 里已经默认开启 Region Merge,所以用户不需要再根据删去的内容去开启 Region Merge 了吧?这部分内容仍保留在 v2.1 里。

Copy link
Member

@Connor1996 Connor1996 Nov 14, 2019

Choose a reason for hiding this comment

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

搞不好用户自己关了,同时还有一些调整的 reference 的文档还是可以看下的,注明默认已开启就好

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

@TomShawn TomShawn requested a review from lilin90 November 14, 2019 07:20
dev/TOC.md Outdated
@@ -266,6 +266,7 @@
- [高并发写入场景最佳实践](/dev/reference/best-practices/high-concurrency.md)
- [Grafana 监控最佳实践](/dev/reference/best-practices/grafana-monitor.md)
- [PD 调度策略最佳实践](/dev/reference/best-practices/pd-scheduling.md)
- [海量 Region 集群调优最佳实践](/dev/reference/best-practices/massive-region.md)
Copy link
Member

Choose a reason for hiding this comment

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

How about using the plural form of region in the file name?

Suggested change
- [海量 Region 集群调优最佳实践](/dev/reference/best-practices/massive-region.md)
- [海量 Region 集群调优最佳实践](/dev/reference/best-practices/massive-regions.md)

@@ -0,0 +1,143 @@
---
Copy link
Member

Choose a reason for hiding this comment

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

massive-region.md -> massive-regions.md


在 TiDB 的架构中,所有数据以一定 key range 被切分成若干 Region 分布在多个 TiKV 实例上。随着数据的写入,一个集群中会产生上百万个甚至千万个 Region。单个 TiKV 实例上产生过多的 Region 会给集群带来较大的负担,影响整个集群的性能表现。

本文先介绍 TiKV 核心模块 Raftstore 的工作流程,海量 Region 导致性能问题的原因,以及优化性能的方法。
Copy link
Member

Choose a reason for hiding this comment

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

The word is a little bit weird for me. We can just use .


## 性能问题

如上图所示,Region 依次逐个处理消息。那么在 Region 数量较多的情况下,Raftstore 会需要花费一些时间去处理大量 Region 的心跳,使一些读写请求得不到及时的处理而产生延迟。如果读写压力较大,Raftstore 线程的 CPU 使用率容易达到瓶颈,而这个延迟会进一步增加,进而影响性能表现。
Copy link
Member

Choose a reason for hiding this comment

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

  • 根据上下文,这里不是 Region 去处理,处理的对象是 Region 消息。
  • 使一些读写请求得不到及时的处理而产生延迟:这里是指 Raftstore 的延迟导致读写请求得不到及时处理。
Suggested change
如上图所示,Region 依次逐个处理消息。那么在 Region 数量较多的情况下,Raftstore 会需要花费一些时间去处理大量 Region 的心跳,使一些读写请求得不到及时的处理而产生延迟。如果读写压力较大,Raftstore 线程的 CPU 使用率容易达到瓶颈,而这个延迟会进一步增加,进而影响性能表现。
从 Raftstore 处理流程示意图可以看出,众多 Region 消息需要一个接一个地依次处理。那么在 Region 数量较多的情况下,Raftstore 需要花费一些时间去处理大量 Region 的心跳,从而带来一些延迟,导致某些读写请求得不到及时处理。如果读写压力较大,Raftstore 线程的 CPU 使用率容易达到瓶颈,导致延迟进一步增加,进而影响性能表现。

Copy link
Member

Choose a reason for hiding this comment

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

“众多 Region 消息需要一个接一个地依次处理” 感觉没有表现出 Region 的消息是 batch 在一起的。一次性处理的是整个 Region 的消息,而不是所有 Region 消息混杂在一起一个接一个的处理。“众多 Region 需要一个接一个地依次处理消息” 这样如何?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

众多 Region 需要一个接一个地依次处理消息,这样读者可能会以为是 Region 在处理消息。成批出现的 Region 消息需要一个接一个地依次被处理 这样呢?

Copy link
Member

Choose a reason for hiding this comment

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

"Region 处理消息“ 感觉逻辑上没有什么问题。那这样说 ”Raftstore 一个接一个地驱动 Region 去处理它们的消息“?

Copy link
Member

@lilin90 lilin90 Nov 15, 2019

Choose a reason for hiding this comment

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

@Connor1996 Got it. 要不就这样呢?“需要依次处理各个 Region 的消息” @TomShawn

Copy link
Member

Choose a reason for hiding this comment

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

+1

> **注意:**
>
> + Raftstore 的 CPU 使用率是指单线程的情况。如果是多线程 Raftstore,可等比例放大使用率。
> + 由于 Raftstore 线程中有 IO 操作,所以 CPU 使用率不可能达到 100%。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> + 由于 Raftstore 线程中有 IO 操作,所以 CPU 使用率不可能达到 100%。
> + 由于 Raftstore 线程中有 I/O 操作,所以 CPU 使用率不可能达到 100%。


### 性能监控

这一监控 metrics 可在 TiKV Grafana 面板下查看:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
这一监控 metrics 可在 TiKV Grafana 面板下查看
可在 Grafana 的 TiKV 面板下查看相关的监控 metrics


### 方法一:增加 TiKV 实例

如果 IO 资源和 CPU 资源都有较多盈余,可在单台机器上部署多个 TiKV 实例,以减少单个 TiKV 实例上的 Region 个数;或者增加扩容 TiKV 集群的机器数。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
如果 IO 资源和 CPU 资源都有较多盈余,可在单台机器上部署多个 TiKV 实例,以减少单个 TiKV 实例上的 Region 个数;或者增加扩容 TiKV 集群的机器数。
如果 I/O 资源和 CPU 资源都比较充足,可在单台机器上部署多个 TiKV 实例,以减少单个 TiKV 实例上的 Region 个数;或者增加 TiKV 集群的机器数。


在实际情况中,读写请求并不会均匀分布到每个 Region 上,而是集中在少数的 Region 上。那么可以尽量减少暂时空闲的 Region 的消息数量,这也就是 Hibernate Region 的功能。无必要时可不进行 `raft-base-tick`,即不驱动空闲 Region 的 Raft 状态机,那么就不会触发这些 Region 的 Raft 产生心跳信息,极大地减小了 Raftstore 的工作负担。

截止 TiDB v3.0.5,Hibernate Region 仍是一个实验功能,在 [TiKV master](https://github.com/tikv/tikv/tree/master) 分支上已经默认开启。可根据实际情况和需求来开启该功能。Hibernate Region 的配置说明请参考[配置 Hibernate Region](https://github.com/tikv/tikv/blob/master/docs/reference/configuration/raftstore-config.md#hibernate-region)。
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
截止 TiDB v3.0.5,Hibernate Region 仍是一个实验功能,在 [TiKV master](https://github.com/tikv/tikv/tree/master) 分支上已经默认开启。可根据实际情况和需求来开启该功能。Hibernate Region 的配置说明请参考[配置 Hibernate Region](https://github.com/tikv/tikv/blob/master/docs/reference/configuration/raftstore-config.md#hibernate-region)
截至 TiDB v3.0.5,Hibernate Region 仍是一个实验功能,在 [TiKV master](https://github.com/tikv/tikv/tree/master) 分支上已经默认开启。可根据实际情况和需求来开启该功能。Hibernate Region 的配置说明请参考[配置 Hibernate Region](https://github.com/tikv/tikv/blob/master/docs/reference/configuration/raftstore-config.md#hibernate-region)


开启 `Region Merge` 也能减少 Region 的个数。与 `Region Split` 相反,`Region Merge` 是通过调度把相邻的小 Region 合并的过程。在集群中删除数据或者执行 `Drop Table`/`Truncate Table` 语句后,可以将小 Region 甚至空 Region 进行合并以减少资源的消耗。

通过 pd-ctl 设置以下参数即可开启 `Region Merge`:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
通过 pd-ctl 设置以下参数即可开启 `Region Merge`:
通过 pd-ctl 设置以下参数即可开启 `Region Merge`


详情请参考[如何配置 Region Merge](https://github.com/tikv/tikv/blob/master/docs/how-to/configure/region-merge.md) 和 [PD 配置文件描述](/dev/reference/configuration/pd-server/configuration-file.md#schedule) 。

同时,默认配置的 `Region Merge` 的参数设置较为保守,可以根据需求参考 [TiDB 最佳实践系列(二)PD 调度策略](https://pingcap.com/blog-cn/best-practice-pd/#5-region-merge-%E9%80%9F%E5%BA%A6%E6%85%A2) 中提供的方法加快 `Region Merge` 过程的速度。
Copy link
Member

Choose a reason for hiding this comment

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

为什么不用 docs-cn 中已发布的 PD 最佳实践链接呢?

Suggested change
同时,默认配置的 `Region Merge` 的参数设置较为保守,可以根据需求参考 [TiDB 最佳实践系列(二)PD 调度策略](https://pingcap.com/blog-cn/best-practice-pd/#5-region-merge-%E9%80%9F%E5%BA%A6%E6%85%A2) 中提供的方法加快 `Region Merge` 过程的速度。
同时,默认配置的 `Region Merge` 的参数设置较为保守,可以根据需求参考 [TiDB 最佳实践系列(二)PD 调度策略](/dev/reference/best-practices/pd-scheduling.md#region-merge-速度慢) 中提供的方法加快 `Region Merge` 过程的速度。

Copy link
Member

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@TomShawn TomShawn added the translation/doing This PR’s assignee is translating this PR. label Nov 20, 2019
@TomShawn TomShawn self-assigned this Nov 20, 2019
Copy link
Member

@lilin90 lilin90 left a comment

Choose a reason for hiding this comment

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

LGTM

@lilin90 lilin90 merged commit 196c741 into pingcap:master Nov 22, 2019
@TomShawn TomShawn added translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR. and removed translation/doing This PR’s assignee is translating this PR. labels Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/best-practices Adds or updates TiDB best practices. translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants