-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
reference: add tidb best practices under high concurrency #1823
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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/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) | |||
+ 最佳实践 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [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 |
There was a problem hiding this comment.
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 使用的 “反模式”。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 TiDB 的使用过程中,一个典型场景是高并发批量写入数据到 TiDB。本文阐述了该场景中的常见问题,旨在给出一个业务的最佳实践,帮助读者在开发业务时避免陷入 TiDB 使用的 “反模式”。 | |
高并发批量写入数据到 TiDB 是使用 TiDB 过程中的一个典型场景。本文阐述了该场景中的常见问题,并提供了业务的最佳实践,旨在帮助用户在开发业务时避免陷入 TiDB 使用的“反模式”。 |
There was a problem hiding this comment.
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/)。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
本文读者应该对 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上。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
短时间内大量数据会持续写入到同一个 Region上。 | |
短时间内大量数据会持续写入到同一个 Region 上。 |
SPLIT TABLE table_name [INDEX index_name] BY (value_list) [, (value_list)] | ||
``` | ||
|
||
但是 TiDB 并不自动提前完成这个切分操作。原因如下: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但是 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果表没有主键或者主键不是 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 功能关闭,以减少细小内存对象的分配: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 机制 |
There was a problem hiding this comment.
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 在高并发场景下的最佳实践。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
summary: 介绍了 TiDB 在高并发场景下的最佳实践。 | |
summary: 了解 TiDB 在高并发写入场景下的最佳实践。 |
@@ -0,0 +1,203 @@ | |||
--- | |||
title: TiDB 高并发写入场景最佳实践 | |||
summary: 介绍了 TiDB 在高并发场景下的最佳实践。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
summary: 介绍了 TiDB 在高并发场景下的最佳实践。 | |
summary: 了解 TiDB 在高并发写入场景下的最佳实践。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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