MySQL压力测试工具,值得收藏( 二 )


Pseudo-Random Numbers Generator options: # 伪随机数发生器选项
--rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special]
--rand-spec-iter=N number of iterations used for numbers generation [12]
--rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1]
--rand-spec-res=N percentage of 'special' values to use (for special distribution) [75]
--rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0]
--rand-pareto-h=N parameter h for pareto distribution [0.2]
Log options: # 日志选项
--verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3]
--percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95]
--histogram[=on|off] print latency histogram in report [off]
General database options: # 通用的数据库选项
--db-driver=STRING 指定要使用的数据库驱动程序 ('help' to get list of available drivers)
--db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto]
--db-debug[=on|off] print database-specific debug information [off]
Compiled-in database drivers: # 內建的数据库驱动程序 , 默认支持 MySQL 和 PostgreSQL
mysql - MySQL driver
pgsql - PostgreSQL driver
mysql options: # MySQL 数据库专用选项
--mysql-host=[LIST,...] MySQL server host [localhost]
--mysql-port=[LIST,...] MySQL server port [3306]
--mysql-socket=[LIST,...] MySQL socket
--mysql-user=STRING MySQL user [sbtest]
--mysql-password=STRING MySQL password []
--mysql-db=STRING MySQL database name [sbtest]
--mysql-ssl[=on|off] use SSL connections, if available in the client library [off]
--mysql-ssl-cipher=STRING use specific cipher for SSL connections []
--mysql-compression[=on|off] use compression, if available in the client library [off]
--mysql-debug[=on|off] trace all client library calls [off]
--mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205]
--mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off]
pgsql options: # PostgreSQL 数据库专用选项
--pgsql-host=STRING PostgreSQL server host [localhost]
--pgsql-port=N PostgreSQL server port [5432]
--pgsql-user=STRING PostgreSQL user [sbtest]
--pgsql-password=STRING PostgreSQL password []
--pgsql-db=STRING PostgreSQL database name [sbtest]
Compiled-in tests: # 內建测试类型
fileio - File I/O test
cpu - CPU performance test
memory - Memory functions speed test
threads - Threads subsystem performance test
mutex - Mutex performance test
See 'sysbench <testname> help' for a list of options for each test.
3、sysbench测试MySQL数据库性能
1)准备测试数据
#查看sysbench自带的lua脚本使用方法
[root@mysql ~]# sysbench /usr/share/sysbench/oltp_common.lua help
#必须创建sbtest库 , sbtest是sysbench默认使用的库名
[root@mysql ~]# mysqladmin -uroot -p123 create sbtest;
#然后 , 准备测试所用的表 , 这些测试表放在测试库sbtest中 。这里使用的lua脚本为
/usr/share/sysbench/oltp_common.lua
[root@mysql ~]# sysbench --mysql-host=127.0.0.1
> --mysql-port=3306
> --mysql-user=root
> --mysql-password=123
> /usr/share/sysbench/oltp_common.lua
> --tables=10
> --table_size=100000
> prepare
#其中--tables=10表示创建10个测试表 , 
#--table_size=100000表示每个表中插入10W行数据 , 
#prepare表示这是准备数的过程 。
2)确认测试数据以存在
[root@mysql ~]# mysql -uroot -p123 sbtest; #登录到sbtest库
mysql> show tables; #查看相应的表
+------------------+
| Tables_in_sbtest |
+------------------+
| sbtest1 |
| sbtest10 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
| sbtest7 |
| sbtest8 |
| sbtest9 |
+------------------+
10 rows in set (0.00 sec)
mysql> select count(*) from sbtest1; #随机选择一个表 , 确认其有100000条数据
+----------+
| count(*) |
+----------+
| 100000 |
+----------+
1 row in set (0.01 sec)
3)数据库测试和结果分析
稍微修改下之前准备数据的语句 , 就可以拿来测试了 。
需要注意的是 , 之前使用的lua脚本为oltp_common.lua , 它是一个通用脚本 , 是被其它lua脚本调用的 , 它不能直接拿来测试 。


推荐阅读