mysql读写性能测试

用mysqlslap进行mysql压力测试

mysqlslap官方文档  

mysqlslap菜鸟译文

概述和测试环境

压测的目的是为了尽量模拟真实情况。测试的表都是由10个int型字段和10个字符串型字段组成。每个测试项目都测试了myisam和innodb两个引擎。测试的方法都是用两个线程并发,一共跑10000个请求。

压测的机器用的是自己的笔记本。CPU是Intel(R) Core(TM)2 Duo CPU     P8400, 4G内存, SATA硬盘。

mysql服务器端和压测的客户端跑在同一台机器上。mysql的版本是5.5.

用到的mysqlslap参数解释如下:

--concurrency=2 两个线程

--iterations=1 执行一次

--number-int-cols=10 10个int型字段
--number-char-cols=10 10个字符串字段
-a 等同于--auto-generate-sql

--auto-generate-sql-add-autoincrement 创建auto increment的主键
--auto-generate-sql-secondary-indexes=2 创建2列索引

--auto-generate-sql-guid-primary 创建guid作为主键

--number-of-queries=10000 所有并发线程的请求次数和
--auto-generate-sql-load-type=write/key/read/update/mixed 测试的query类型
--engine=myisam,innodb 存储引擎

写性能测试

写性能测试1,不开binlog, guid做主键, 无索引

测试命令:

1 mysqlslap   --concurrency=2\
2             --iterations=1\
3             --number-int-cols=10\
4             --number-char-cols=10\
5             -a\
6             --auto-generate-sql-guid-primary\
7             --number-of-queries=10000\
8             --auto-generate-sql-load-type=write\
9             --engine=myisam,innodb\
结果:
01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 6.110 seconds
04         Minimum number of seconds to run all queries: 6.110 seconds
05         Maximum number of seconds to run all queries: 6.110 seconds
06         Number of clients running queries: 2
07         Average number of queries per client: 5000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 10.291 seconds
12         Minimum number of seconds to run all queries: 10.291 seconds
13         Maximum number of seconds to run all queries: 10.291 seconds
14         Number of clients running queries: 2
15         Average number of queries per client: 5000
用myisam每秒处理1639次。

用innodb每秒处理971次。

真实环境中一般会用binlog做数据备份与同步,所以性能会有所下降,有binlog的情况请继续看后面的实验。

写性能测试2, 开binlog, guid做主键, 无索引

测试命令与“写性能测试1”相同,

结果如下:

01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 14.809 seconds
04         Minimum number of seconds to run all queries: 14.809 seconds
05         Maximum number of seconds to run all queries: 14.809 seconds
06         Number of clients running queries: 2
07         Average number of queries per client: 5000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 26.721 seconds
12         Minimum number of seconds to run all queries: 26.721 seconds
13         Maximum number of seconds to run all queries: 26.721 seconds
14         Number of clients running queries: 2
15         Average number of queries per client: 5000
myisam每秒处理675次

innodb每秒处理374次

写性能测试3, 开binlog, guid做主键, 有索引

现实情况中,有索引的情况较多。采用 --auto-generate-sql-secondary-indexes=2 创建两列索引。

命令如下:

01 mysqlslap   --concurrency=2\
02             --iterations=1\
03             --number-int-cols=10\
04             --number-char-cols=10\
05             -a\
06             --auto-generate-sql-guid-primary\
07             --auto-generate-sql-secondary-indexes=2\
08             --number-of-queries=10000\
09             --auto-generate-sql-load-type=write\
10             --engine=myisam,innodb\

结果如下:

01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 16.693 seconds
04         Minimum number of seconds to run all queries: 16.693 seconds
05         Maximum number of seconds to run all queries: 16.693 seconds
06         Number of clients running queries: 2
07         Average number of queries per client: 5000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 30.418 seconds
12         Minimum number of seconds to run all queries: 30.418 seconds
13         Maximum number of seconds to run all queries: 30.418 seconds
14         Number of clients running queries: 2
15         Average number of queries per client: 5000
myisam每秒处理599次。

innodb每秒处理329次。

写性能测试4,开binglog,auto increment主键,有索引

命令如下:

01 mysqlslap   --concurrency=2\
02             --iterations=1\
03             --number-int-cols=10\
04             --number-char-cols=10\
05             -a\
06             --auto-generate-sql-add-autoincrement\
07             --auto-generate-sql-secondary-indexes=2\
08             --number-of-queries=10000\
09             --auto-generate-sql-load-type=write\
10             --engine=myisam,innodb\
结果如下:
01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 16.785 seconds
04         Minimum number of seconds to run all queries: 16.785 seconds
05         Maximum number of seconds to run all queries: 16.785 seconds
06         Number of clients running queries: 2
07         Average number of queries per client: 5000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 28.809 seconds
12         Minimum number of seconds to run all queries: 28.809 seconds
13         Maximum number of seconds to run all queries: 28.809 seconds
14         Number of clients running queries: 2
15         Average number of queries per client: 5000
myisam每秒处理595次。

innodb每秒处理347次。



读性能测试

在真实的情况中,我们最主要的读操作其实就是用主键去查找表中的一行。 我主要是对这种行为进行测试。所以采用的load-type = key ,而不是read。 read是对全表进行读取,可是实际上这种情况很少出现。

读性能测试1,guid主键

命令如下:

01 mysqlslap   --concurrency=2\
02             --iterations=1\
03             --number-int-cols=10\
04             --number-char-cols=10\
05             -a\
06             --auto-generate-sql-guid-primary\
07             --auto-generate-sql-unique-query-number=10000\
08             --auto-generate-sql-load-type=key\
09             --number-of-queries=10000\
10             --engine=myisam,innodb\
结果如下:
01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 4.215 seconds
04         Minimum number of seconds to run all queries: 4.215 seconds
05         Maximum number of seconds to run all queries: 4.215 seconds
06         Number of clients running queries: 2
07         Average number of queries per client: 5000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 3.917 seconds
12         Minimum number of seconds to run all queries: 3.917 seconds
13         Maximum number of seconds to run all queries: 3.917 seconds
14         Number of clients running queries: 2
15         Average number of queries per client: 5000
myisam每秒处理2372次

innodb每秒处理2553次

读性能测试2,auto increment主键

命令如下

01 mysqlslap   --concurrency=1\
02             --iterations=1\
03             --number-int-cols=10\
04             --number-char-cols=10\
05             -a\
06             --auto-generate-sql-add-autoincrement\
07             --auto-generate-sql-unique-query-number=10000\
08             --auto-generate-sql-load-type=key\
09             --number-of-queries=10000\
10             --engine=myisam,innodb\
结果如下:
01 Benchmark
02         Runningforengine myisam
03         Average number of seconds to run all queries: 4.555 seconds
04         Minimum number of seconds to run all queries: 4.555 seconds
05         Maximum number of seconds to run all queries: 4.555 seconds
06         Number of clients running queries: 1
07         Average number of queries per client: 10000
08  
09 Benchmark
10         Runningforengine innodb
11         Average number of seconds to run all queries: 4.402 seconds
12         Minimum number of seconds to run all queries: 4.402 seconds
13         Maximum number of seconds to run all queries: 4.402 seconds
14         Number of clients running queries: 1
15         Average number of queries per client: 10000
myisam每秒处理2195次。

innodb每秒处理2273次。


实验结果

项目 myisam每秒吞吐量 innodb每秒吞吐量

写性能测试1,不开binlog, guid主键, 无索引

1639 971

写性能测试2,开binlog,guid主键,无索引

675 374

写性能测试3, 开binlog, guid做主键, 有索引

599 329

写性能测试4,开binglog,auto increment主键,有索引

595 347

读性能测试1,guid主键

2372 2553

读性能测试2,auto increment主键

2195 2273


结论

1 在开启了binlog后, mysql写性能下降60%

2 myisam与innodb相比,写的速度更快(快40%), 读的速度差不多。


转载

转载地址


上一篇:那些年用过的Redis集群架构(含面试解析)


下一篇:C#开发微信门户及应用(1)--开始使用微信接口