Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 请问大家,随着一个表的数据量增加,插入也开始变慢了,是什么原因
[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Problem Phenomenon and Impact]
[Resource Configuration]
[Attachments: Screenshots / Logs / Monitoring]
We have a table that needs to store 6 billion records. During testing, we found that after the data increased to 3 billion, the insertion speed slowed down by half. What could be the reason? How can we investigate and resolve this?
Check if there is any change in disk IOPS before and after.
From the point in time when it started to slow down, were there any changes in the cluster monitoring? How about the hotspot issue?
What method is used for insertion? How many records are inserted at a time?
You can refer to this troubleshooting process for slow read and write performance:
Check the dashboard to see if there are any write hotspots.
Is the hotspot caused by the primary key being auto-incremented or randomly assigned? Check if the underlying region distribution is even.
Regions are evenly distributed, with random primary keys. However, there is a date index, and I’m not sure if it is affecting it.
Indexes might also have some impact. Is the table partitioned?
What benefits can partitioning bring if there are no partitions?
Benefits of Table Partitioning:
- Improved Query Performance: Queries on partitioned objects can search only the relevant partitions, increasing retrieval speed.
- Enhanced Availability: If a partition of the table fails, the data in other partitions remains available.
- Easier Maintenance: If a partition of the table fails and data needs to be repaired, only that partition needs to be fixed.
- Balanced I/O: Different partitions can be mapped to different disks to balance I/O, improving overall system performance.
The larger it gets, the slower it becomes. This is often the norm. You can partition it.
You can think of partitioning as a single table being physically multiple tables, with each partition being a separate table. Generally speaking, large tables of your scale should be partitioned. The most obvious benefit is the ease of deleting data. Deleting is slow, but dropping a partition is fast and can also free up disk space.
The CPU of TiKV is unbalanced.
In TiDB, the prewrite in KV request duration and kv_prewrite in TiKV differ by 100 ms.
Check the heatmap in the dashboard to see if there is a write hotspot. If there is, use split region to divide the region.
Previously, there was an index on the timestamp, which has now been changed to a composite index. Currently observing the results.