mysql读写性能测试

来源:oschina 作者:costaxu
  

作者: costaxu  原文链接 

近来工作中用mysql较多,但其实自己对mysql性能并不十分了解。前阵子正好读到一篇写用mysqlslap压测mysql性能的文章,于是自己也尝试了一下mysqlslap并且得到一些数据和结论。把压测到的数据与大家分享,如有谬误之处请指正。

 

概述和测试环境

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

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

mysql服务器端和压测的客户端跑在同一台机器上。

用到的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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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         Running for engine 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相比,写的速度更快(快80%), 读的速度差不多。

 


时间:2013-02-14 10:08 来源:oschina 作者:costaxu 原文链接

好文,顶一下
(3)
100%
文章真差,踩一下
(0)
0%
------分隔线----------------------------


把开源带在你的身边-精美linux小纪念品
无觅相关文章插件,快速提升流量