测试机配置:
cup: 1物理4核 Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
内存:4g
机械硬盘,无raid.
测试硬盘读写速率:
[root mysql]# hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 394 MB in 3.05 seconds = 129.10 MB/sec
[root /]# time dd if=/dev/zero bs=1024 count=1000000 of=/1Gb.file
记录了1000000+0 的读入
记录了1000000+0 的写出
1024000000字节(1.0 GB)已复制,6.44308 秒,159 MB/秒
real 0m6.484s
user 0m0.082s
sys 0m2.213s
mysql 5.6, my.cf 主要参数:
innodb_buffer_pool_size = 1024M
max_connections = 10000
/etc/init.d/mysql restart, cpu:0.3% mem:65.9%
新建表:id,name,nick,mark,id自增,name建BTREE索引。
写:insert into usertest(name,nick,mark) value(CONCAT("test",NOW(3)),NOW(),"hello world");
单条执行平均:0.063s
单表写两千万数据,平均并发数2500-4000/s
cpu:50%-350%
mem:70%+
读:
1.索引命中,返回值一条,select * from usertest where name = 'test2017-12-22 10:08:05.331'
单条执行平均:0.002s
当线程组设置为5000,ramp-up period 1:
单表读数据,平均并发数4000+/s
cpu:50%-70%
mem:70%+
2.无索引,返回值多条(804条),select * from usertest where nick = '2017-12-22 10:08:05'
单条执行平均:56s
当线程组设置为10,ramp-up period 1:
并发速度大大降低,8.9/min
cpu:150%-350%
mem:70%+
3.索引命中,返回值多条(34万条):select * from usertest where name like 'test2017-12-22 10:0%'
单条执行平均:12.43s
当线程组设置为10,ramp-up period 1:
并发速度大大降低,6.7/min
cpu:50%-350%
mem:70%+
4.索引命中,返回值多条(804):select * from usertest where name like 'test2017-12-22 10:08:05%'
单条执行平均:0.015s
当线程组设置为100,ramp-up period 1:
并发速度大大降低,144.1/s
cpu:50%+
mem:70%+
5.更新,索引命中,返回值多条(5):update usertest set mark='test' where name = 'test2017-12-22 10:08:05.328'
cpu:100%+
mem:70%+
当线程组设置为200,ramp-up period 1:
并发数:2322.2/s
当线程组设置为2000,ramp-up period 1:
并发数:22.9/s
error :Lock wait timeout exceeded; try restarting transaction。
结论:在一定的硬件及mysql配置条件下,单表千万级数据,插入性能几千,具有索引的命中一行的查询性能几千,命中很多行性能下降,和单条的sql速度有关,更新性能由于锁的关系,在几十到几千,和访问数有关,注意做好sql优化,限流,扩容等策略,防止被hang死