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

reference: add tidb best practices under high concurrency #1823

Merged
merged 27 commits into from
Oct 12, 2019

Conversation

TomShawn
Copy link
Contributor

@TomShawn TomShawn commented Sep 5, 2019

What is changed, added or deleted?

This PR adds TiDB 高并发写入常见热点问题及规避方法.md.

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

N/A

Which version does your change affect?

dev, v3.0

@TomShawn TomShawn added v3.0 translation/doing This PR’s assignee is translating this PR. labels Sep 5, 2019
@TomShawn TomShawn requested review from winkyao and lilin90 September 5, 2019 06:51
@TomShawn TomShawn self-assigned this Sep 5, 2019
@TomShawn TomShawn changed the title reference: add TiDB Best Practices Under High Concurrency reference: add tidb best practices under high concurrency Sep 5, 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.

Please add the code snippet for code blocks where necessary.

dev/TOC.md Outdated
@@ -317,6 +317,8 @@
- [TiDB 最佳实践](https://pingcap.com/blog-cn/tidb-best-practice/)
+ [TiSpark 使用指南](/dev/reference/tispark.md)
+ [TiDB Binlog 简介](/dev/reference/tidb-binlog-overview.md)
+ 最佳实践
- [TiDB 高并发写入常见热点问题及规避方法](/dev/reference/best-practices/high-concurrency.md)
Copy link
Member

Choose a reason for hiding this comment

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

The file name cannot convey the meaning of the title.

dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
dev/reference/best-practices/high-concurrency.md Outdated Show resolved Hide resolved
@lilin90 lilin90 added area/best-practices Adds or updates TiDB best practices. translation/doing This PR’s assignee is translating this PR. and removed translation/doing This PR’s assignee is translating this PR. labels Sep 24, 2019
dev/TOC.md Outdated
@@ -321,6 +321,8 @@
- [TiDB 最佳实践](https://pingcap.com/blog-cn/tidb-best-practice/)
+ [TiSpark 使用指南](/dev/reference/tispark.md)
+ [TiDB Binlog 简介](/dev/reference/tidb-binlog-overview.md)
+ 最佳实践
Copy link
Member

Choose a reason for hiding this comment

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

Please move this section to the place just behind 周边工具.

dev/TOC.md Outdated
@@ -321,6 +321,8 @@
- [TiDB 最佳实践](https://pingcap.com/blog-cn/tidb-best-practice/)
+ [TiSpark 使用指南](/dev/reference/tispark.md)
+ [TiDB Binlog 简介](/dev/reference/tidb-binlog-overview.md)
+ 最佳实践
- [TiDB 高并发写入场景最佳实践](/dev/reference/best-practices/in-high-concurrency.md)
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 高并发写入场景最佳实践](/dev/reference/best-practices/in-high-concurrency.md)
- [TiDB 高并发写入场景最佳实践](/dev/reference/best-practices/high-concurrency.md)

@@ -0,0 +1,204 @@
---
title: TiDB 高并发写入场景最佳实践
category: reference
Copy link
Member

Choose a reason for hiding this comment

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

Add a summary.


# TiDB 高并发写入场景最佳实践

在 TiDB 的使用过程中,一个典型场景是高并发批量写入数据到 TiDB。本文阐述了该场景中的常见问题,旨在给出一个业务的最佳实践,帮助读者在开发业务时避免陷入 TiDB 使用的 “反模式”。
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 的使用过程中,一个典型场景是高并发批量写入数据到 TiDB。本文阐述了该场景中的常见问题,旨在给出一个业务的最佳实践,帮助读者在开发业务时避免陷入 TiDB 使用的 “反模式”。
高并发批量写入数据到 TiDB 是使用 TiDB 过程中的一个典型场景。本文阐述了该场景中的常见问题,并提供了业务的最佳实践,旨在帮助用户在开发业务时避免陷入 TiDB 使用的“反模式”。

Copy link
Member

Choose a reason for hiding this comment

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

What does "反模式" mean here?


## 目标读者

本文读者应该对 TiDB 有一定的了解,推荐先阅读 TiDB 原理的三篇文章([讲存储](https://pingcap.com/blog-cn/tidb-internal-1/),[说计算](https://pingcap.com/blog-cn/tidb-internal-2/),[谈调度](https://pingcap.com/blog-cn/tidb-internal-3/)),以及 [TiDB Best Practice](https://pingcap.com/blog-cn/tidb-best-practice/)。
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 有一定的了解,推荐先阅读 TiDB 原理的三篇文章[讲存储](https://pingcap.com/blog-cn/tidb-internal-1/)[说计算](https://pingcap.com/blog-cn/tidb-internal-2/)[谈调度](https://pingcap.com/blog-cn/tidb-internal-3/)),以及 [TiDB Best Practice](https://pingcap.com/blog-cn/tidb-best-practice/)
本文假设你已对 TiDB 有一定的了解,推荐先阅读 TiDB 原理相关的三篇文章[讲存储](https://pingcap.com/blog-cn/tidb-internal-1/)[说计算](https://pingcap.com/blog-cn/tidb-internal-2/)[谈调度](https://pingcap.com/blog-cn/tidb-internal-3/)),以及 [TiDB Best Practice](https://pingcap.com/blog-cn/tidb-best-practice/)

[CommonPrefix + TableID, CommonPrefix + TableID + 1)
```

短时间内大量数据会持续写入到同一个 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
短时间内大量数据会持续写入到同一个 Region上
短时间内大量数据会持续写入到同一个 Region 上

SPLIT TABLE table_name [INDEX index_name] BY (value_list) [, (value_list)]
```

但是 TiDB 并不自动提前完成这个切分操作。原因如下:
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 并不自动提前完成这个切分操作。原因如下:
但是 TiDB 并不会自动提前完成这个切分操作。原因如下:


### 更复杂的热点问题

如果表没有主键或者主键不是 Int 类型,而且用户也不想自己生成一个随机分布的主键 ID 的话,TiDB 内部有一个隐式的 `_tidb_rowid` 列作为行 ID。在不使用 `SHARD_ROW_ID_BITS` 的情况下,`_tidb_rowid` 列的值基本也为单调递增,此时也会有写热点存在。(参阅 [`SHARD_ROW_ID_BITS` 的详细说明](/dev/reference/configuration/tidb-server/tidb-specific-variables.md#shard_row_id_bits))
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
如果表没有主键或者主键不是 Int 类型,而且用户也不想自己生成一个随机分布的主键 ID 的话,TiDB 内部有一个隐式的 `_tidb_rowid` 列作为行 ID。在不使用 `SHARD_ROW_ID_BITS` 的情况下,`_tidb_rowid` 列的值基本也为单调递增,此时也会有写热点存在(参阅 [`SHARD_ROW_ID_BITS` 的详细说明](/dev/reference/configuration/tidb-server/tidb-specific-variables.md#shard_row_id_bits)
如果表没有主键或者主键不是 Int 类型,而且用户也不想自己生成一个随机分布的主键 ID 的话,TiDB 内部有一个隐式的 `_tidb_rowid` 列作为行 ID。在不使用 `SHARD_ROW_ID_BITS` 的情况下,`_tidb_rowid` 列的值基本也为单调递增,此时也会有写热点存在(参阅 [`SHARD_ROW_ID_BITS` 的详细说明](/dev/reference/configuration/tidb-server/tidb-specific-variables.md#shard_row_id_bits)


### 关闭 TiDB 的 Latch 机制

TiDB 2.1 版本中在 SQL 层引入了 [latch 机制](/dev/reference/configuration/tidb-server/configuration-file.md#txn-local-latches),用于在写入冲突比较频繁的场景中提前发现事务冲突,减少 TiDB 和 TiKV 事务提交时写写冲突导致的重试。在多数情况下,跑批场景全部使用存量数据,所以并不存在事务的写入冲突。可以把 TiDB 的 latch 功能关闭,以减少细小内存对象的分配:
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 2.1 版本中在 SQL 层引入了 [latch 机制](/dev/reference/configuration/tidb-server/configuration-file.md#txn-local-latches),用于在写入冲突比较频繁的场景中提前发现事务冲突,减少 TiDB 和 TiKV 事务提交时写写冲突导致的重试。在多数情况下,跑批场景全部使用存量数据,所以并不存在事务的写入冲突。可以把 TiDB 的 latch 功能关闭,以减少细小内存对象的分配:
TiDB 2.1 版本中在 SQL 层引入了 [latch 机制](/dev/reference/configuration/tidb-server/configuration-file.md#txn-local-latches),用于在写入冲突比较频繁的场景中提前发现事务冲突,减少 TiDB 和 TiKV 事务提交时写写冲突导致的重试。通常,跑批场景使用的是存量数据,所以并不存在事务的写入冲突。可以把 TiDB 的 latch 功能关闭,以减少细小内存对象的分配:


## 参数配置

### 关闭 TiDB 的 Latch 机制
Copy link
Member

Choose a reason for hiding this comment

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

Consider removing this line because it's a lone 3rd-level heading.

@@ -0,0 +1,203 @@
---
title: TiDB 高并发写入场景最佳实践
summary: 介绍了 TiDB 在高并发场景下的最佳实践。
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
summary: 介绍了 TiDB 在高并发场景下的最佳实践
summary: 了解 TiDB 在高并发写入场景下的最佳实践

@@ -0,0 +1,203 @@
---
title: TiDB 高并发写入场景最佳实践
summary: 介绍了 TiDB 在高并发场景下的最佳实践。
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
summary: 介绍了 TiDB 在高并发场景下的最佳实践
summary: 了解 TiDB 在高并发写入场景下的最佳实践

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

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 f3e459f into pingcap:master Oct 12, 2019
@TomShawn TomShawn deleted the hotspot-issues-best-practice branch October 12, 2019 02:22
@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 Nov 6, 2019
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