一、写热点现象
1.通过grafana中的TiKV-Trouble-Shooting 中 Hot Write 面板的raft store cpu观测是否有单节点的cpu高于其他节点
2.dashboard中写热点图呈现如下状态
二、解决写入热点的几种方法
- 建表的时候采用SHARD_ROW_ID_BITS 和PRE_SPLIT_REGIONS
- 使用auto_random来代替auto_inccrement
三、测试及验证
1.建表语句
create table write_hot_1(id bigint(20) not null auto_increment primary key,z_name varchar(20),z_info varchar(30));create table write_hot_2(id bigint(20) not null auto_random primary key,z_name varchar(20),z_info varchar(30));create table write_hot_3 (id bigint(20), z_name varchar(20), z_info varchar(30)) SHARD_ROW_ID_BITS = 4 PRE_SPLIT_REGIONS=3;create table write_hot_4(id bigint(20) not null auto_random primary key,z_name varchar(20),z_info varchar(30) , key idx_z_name(z_name));
2.插入脚本
import pymysql
conn = pymysql.Connect(host="", port=, user="", password="", db='')
cur = conn.cursor()
sql_str = 'insert into write_hot_4(z_name, z_info) values("csdfsdfsdfsda", "qwwerwerisdfnsdvj vsd")'
for i in range(10000):sql_str = sql_str + ',("csdfsdfsdfsda", "qwwerwerisdfnsdvj vsd")'
for i in range(1000):print(i)cur.execute(sql_str)conn.commit()
conn.close()
3.写入热力图
4.查看每张表的region分布情况
show table write_hot_1 regions;
show table write_hot_2 regions;
show table write_hot_3 regions;
show table write_hot_4 regions;
四、结论
通过热力图可以看出write_hot_1存在明显的写热点,而其他几张表的插入显的较为平均
后续更新