mysql压力测试-sysbench安装及使用说明( 四 )


sysbench 1.0.9 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 4
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 8KiB
total size: 4096MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
Total operations: 524288 (731249.24 per second)
4096.00 MiB transferred (5712.88 MiB/sec)
General statistics:
total time: 0.7150s
total number of events: 524288
Latency (ms):
min: 0.00
avg: 0.00
max: 43.03
95th percentile: 0.00
sum: 1871.33
Threads fairness:
events (avg/stddev): 131072.0000/0.00
execution time (avg/stddev): 0.4678/0.04
2.5 测试 threads
测试 threads 时 , 每个工作线程将被分配一个 mutex(一种锁) 。每次执行时 , 每个线程将循环若干次(通过 --thread-yields 的数量设置) , 循环时这个线程会锁定 , 在再次执行时解锁 。
通过调整各种参数 , 可以模拟具有单个或多个锁的高并发线程下的情况 。
帮助信息:
# sysbench threads help
sysbench 1.0.9 (using system LuaJIT 2.0.4)
threads options:
--thread-yields=N number of yields to do per request [1000]
--thread-locks=N number of locks per thread [8]
运行测试:
[root@VM_157_18_centos ~]# sysbench --thread-yields=2000 --thread-locks=8 threads run
sysbench 1.0.9 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Initializing worker threads...
Threads started!
General statistics:
total time: 10.0002s
total number of events: 16554
Latency (ms):
min: 0.50
avg: 0.60
max: 37.05
95th percentile: 0.94
sum: 9978.12
Threads fairness:
events (avg/stddev): 16554.0000/0.00
execution time (avg/stddev): 9.9781/0.00
2.6 测试 mutex
测试 mutex 时 , sysbench 将为每个线程运行一个请求 。这个请求首先会对 CPU 施加一些压力(使用一个简单的增量循环 , 通过 --mutex-loops 参数设置) , 然后随机使用一个 mutex(锁) , 递增一个全局变量并再次释放锁 。这个过程根据锁的个数(--mutex-locks)多次重复 。随机 mutex 取自大小为 --mutex-num 的参数池 。
帮助信息:
# sysbench mutex help
sysbench 1.0.9 (using system LuaJIT 2.0.4)
mutex options:
--mutex-num=N total size of mutex array [4096]
--mutex-locks=N number of mutex locks to do per thread [50000]
--mutex-loops=N number of empty loops to do outside mutex lock [10000]
运行测试:
[root@VM_157_18_centos ~]# sysbench mutex run
sysbench 1.0.9 (using system LuaJIT 2.0.4)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Initializing worker threads...
Threads started!
General statistics:
total time: 0.2132s
total number of events: 1
Latency (ms):
min: 213.10
avg: 213.10
max: 213.10
95th percentile: 211.60
sum: 213.10
Threads fairness:
events (avg/stddev): 1.0000/0.00
execution time (avg/stddev): 0.2131/0.00
2.7 OLTP 基准测试
OLTP 基准测试模拟了一个简单的事务处理系统的工作负载 。然而最新版本的 sysbench 把 OLTP 这个曾经的內建测试类型移除了 , 如果要用 , 需要在命令中指定测试类型的位置用 /usr/share/sysbench/oltp_read_only.lua 脚本代替测试类型 。
流程:指定数据库-》建表并生成数据-》运行测试-》清理测试表 。
首先生成表 , 注意替换命令中的数据库密码和 MySQL 套接字 , 如果 MySQL 安装在默认位置 , 可以去掉 --mysql-socket 选项:
sysbench --db-driver=mysql --mysql-user=root --mysql-password=<pwd>
--mysql-socket=<mysql.sock path> --mysql-db=foo --range_size=100
--table_size=10000 --tables=2 --threads=2 --events=0 --time=60
--rand-type=uniform /usr/share/sysbench/oltp_read_only.lua prepare
运行测试 , 指定了 2 个并发线程 , :
sysbench --db-driver=mysql --mysql-user=root --mysql-password=<pwd>
--mysql-socket=<mysql.sock path> --mysql-db=foo --range_size=100
--table_size=10000 --tables=2 --threads=2 --events=0 --time=60
--rand-type=uniform /usr/share/sysbench/oltp_read_only.lua run
清理测试时生成的测试表:
sysbench --db-driver=mysql --mysql-user=root --mysql-password=<pwd>


推荐阅读