基准测试,指通过设计科学的测试方法、测试工具和测试系统,实现对一类测试对象的某项性能指标进行定量的和可对比的测试,比如常用的网页性能测试工具ab(全称Apache Benchmark),就是一款有Apache组织下的一款网页压测工具。
序列号 | CPU | RAM | HDD | 带宽 | 售价(美元) | 免费试用 |
---|---|---|---|---|---|---|
香港服务器1 | E5-2620 | 32G | 1T HDD | 50M/无限流量 | $196.00 | 立即申请 |
香港服务器2 | E5-2650 | 32G | 1T HDD | 50M/无限流量 | $256.00 | 立即申请 |
香港服务器3 | E5-2680 | 32G | 1T HDD | 50M/无限流量 | $316.00 | 立即申请 |
香港服务器4 | E5-2690 | 32G | 1T HDD | 50M/无限流量 | $336.00 | 立即申请 |
香港服务器5 | E5-2697 | 32G | 1T HDD | 50M/无限流量 | $376.00 | 立即申请 |
香港服务器6 | E5-2620*2 | 32G | 1T HDD | 50M/无限流量 | $376.00 | 立即申请 |
香港服务器7 | E5-2650*2 | 32G | 1T HDD | 50M/无限流量 | $436.00 | 立即申请 |
香港服务器8 | E5-2680*2 | 32G | 1T HDD | 50M/无限流量 | $476.00 | 立即申请 |
香港服务器9 | E5-2690*2 | 32G | 1T HDD | 50M/无限流量 | $556.00 | 立即申请 |
香港服务器10 | E5-2697*2 | 32G | 1T HDD | 50M/无限流量 | $596.00 | 立即申请 |
香港服务器11 | E5-2680v4*2 | 32G | 1T HDD | 50M/无限流量 | $696.00 | 立即申请 |
香港服务器12 | E5-2698v4*2 | 32G | 1T HDD | 50M/无限流量 | $796.00 | 立即申请 |
今天的主题不是ab,而是数据库的基准测试工具-Sysbench。
sysbensh是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况,可进行的测试:
1.cpu :提供一个简单的cpu 基准测试
2.fileio:文件磁盘io基准测试
3.memory:内存访问基准测试
4.thread:线程调度基准测试
5.mutex:POSIX的锁基准测试
6.OLTP:数据库基准测试,支持MySQL,Pgsql,Oracle
安装
由于我习惯使用CentOS系统,直接使用yum安装
yuminstallsysbench
安装后在环境变量添加
exportLD_LIBRARY_PATH=数据库地址
使用
CPU测试
sysbench CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间:
sysbench--test=cpu--cpu-max-prime=2000run
补充:
查看CPU信息方法
查看物理cpu个数
grep “physical id” /proc/cpuinfo | sort -u | wc -l
查看核心数量
grep “core id” /proc/cpuinfo | sort -u | wc -l
查看线程数量
grep “processor” /proc/cpuinfo | sort -u | wc -l
线程测试
测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用
sysbench--test=threads--num-threads=64--thread-yields=100--thread-locks=2run
MySQL数据库OLTP测试(主要)
先准备好测试用数据
sysbench--mysql-host=1.2.3.4--mysql-port=3317--mysql-user=tpcc--mysql-password=tpcc--test=tests/db/oltp.lua--oltp_tables_count=10--oltp-table-size=100000--rand-init=onprepare
参数解释(前面四个参数就不解释了)
—test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
—oltp_tables_count=10 表示会生成 10 个测试表
—oltp-table-size=100000 表示每个测试表填充数据量为 100000
—rand-init=on 表示每个测试表都是用随机数据来填充的
在上面的生成数据命令基础上,修改一下,变成测试命令
sysbench--mysql-host=1.2.3.4.--mysql-port=3306--mysql-user=tpcc--mysql-password=tpcc--test=tests/db/oltp.lua--oltp_tables_count=10--oltp-table-size=10000000--num-threads=8--oltp-read-only=off--report-interval=10--rand-type=uniform--max-time=3600--max-requests=0--percentile=99run>>./log/sysbench_oltpX_8_20140921.log
参数解释
—num-threads=8 表示发起 8个并发连接
—oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
—report-interval=10 表示每10秒输出一次测试进度报告
—rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
—max-time=120 表示最大执行时长为 120秒
—max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
—percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
测试结果解读
测试结果解读如下:
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:Number of threads: 8Report intermediate results every 10 second(s)Random number generator seed is 0 and will be ignored
Threads started!-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计[ 10s] threads: 8, tps: 1111.51, reads/s: 15568.42, writes/s: 4446.13, response time: 9.95ms (99%)[ 20s] threads: 8, tps: 1121.90, reads/s: 15709.62, writes/s: 4487.80, response time: 9.78ms (99%)[ 30s] threads: 8, tps: 1120.00, reads/s: 15679.10, writes/s: 4480.20, response time: 9.84ms (99%)[ 40s] threads: 8, tps: 1114.20, reads/s: 15599.39, writes/s: 4456.30, response time: 9.90ms (99%)[ 50s] threads: 8, tps: 1114.00, reads/s: 15593.60, writes/s: 4456.70, response time: 9.84ms (99%)[ 60s] threads: 8, tps: 1119.30, reads/s: 15671.60, writes/s: 4476.50, response time: 9.99ms (99%)OLTP test statistics: queries performed: read: 938224 -- 读总数 write: 268064 -- 写总数 other: 134032 -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等) total: 1340320 -- 全部总数 transactions: 67016 (1116.83 per sec.) -- 总事务数(每秒事务数) deadlocks: 0 (0.00 per sec.) -- 发生死锁总数 read/write requests: 1206288 (20103.01 per sec.) -- 读写总数(每秒读写次数) other operations: 134032 (2233.67 per sec.) -- 其他操作总数(每秒其他操作次数)
General statistics: -- 一些统计结果 total time: 60.0053s -- 总耗时 total number of events: 67016 -- 共发生多少事务数 total time taken by event execution: 479.8171s -- 所有事务耗时相加(不考虑并行因素) response time: -- 响应时长统计 min: 4.27ms -- 最小耗时 avg: 7.16ms -- 平均耗时 max: 13.80ms -- 最长耗时 approx. 99 percentile: 9.88ms -- 超过99%平均耗时
Threads fairness: events (avg/stddev): 8377.0000/44.33 execution time (avg/stddev): 59.9771/0.00