YCSB压力测试工具安装
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了YCSB压力测试工具安装相关的知识,希望对你有一定的参考价值。
YCSB(Yahoo! Cloud System Benchmark)作为测试客户端工具。YCSB是Yahoo开源的一个nosql测试工具,用来测试比较各种nosql的性能。
YCSB支持常见的nosql数据库读写,如插入,修改,删除,读取等。它可以使用多线程来提高客户端的性能。可以方便的自定义各种场景,如95%插入5%读, 或者90%读5%更新5%插入等等。可以自定义数据请求分布方式:平均分布,zipfian(大约20%数据获得80%访问请求)。
1.下载地址
https://github.com/brianfrankcooper/YCSB
2.环境准备
jdk
maven
argparse
3.安装jdk
yum install jdk-8u65-linux-x64.rpm
4.安装maven
wget http://ftp.heanet.ie/mirrors/www.apache.org/dist/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
tar xzf apache-maven-*-bin.tar.gz -C /usr/local
cd /usr/local
ln -s apache-maven-* maven
vim /etc/profile.d/maven.sh
export M2_HOME=/usr/local/maven
export PATH=$M2HOME/bin:$PATH
验证是否安装成功
bash
mvn -version
5.安装argparse
yum install python-setuptools python-devel
easy_install pip
pip install argparse
6.安装YCSB
wget https://github.com/brianfrankcooper/YCSB/releases/download/0.12.0/ycsb-0.12.0.tar.gz
tar xfvz ycsb-0.12.0.tar.gz
mv ycsb-0.12.0 /usr/local/
7.运行YCSB
(1).YCSB目录结构
安装好YCSB之后,查看YCSB目录如下:
主要目录及作用:
bin:目录下有个可执行的ycsb文件,是个python脚本,是用户操作的命令行接口。ycsb主逻辑是:解析命令行、设置java环境,
加载java-libs,封装成可以执行的java命令,并执行
workloads:目录下有各种workload的模板,可以基于workload模板进行个性化修改
core:包含ycsb里各种核心实现,比如DB的虚拟类DB.java,各个db子类都要继承该类;还有比如workload抽象类,
如果我们要自定义workload实现也需要继承该类
各种DB的目录:比如mongo,redis等,里面包含了对应测试的源码等,当ycsb mvn编译后,会在对应的目录下生成target文件,ycsb会加载对应target文件中的class类。
(2).mongodb参数
-P file Specify workload file // workload文件 用于设置一些对应的参数,如果workload中的参数,也可以以-p的方式放在命令行中设置
-cp path Additional Java classpath entries
-jvm-args args Additional arguments to the JVM
-p key=value Override workload property // 一些设置
-s Print status to stderr // 把状态达到stderr中
在运行中,把一些状态打印到stderr中,一般status信息,用于表示在运行中的一些中间状态(比如当前处理了多少请求,还有多少请求等)
-target n Target ops/sec (default: unthrottled) // 每秒总共操作的次数
表示1s中总共的操作次数(各个线程加起来的),如果性能不满足,比如最高性能只有100,你设置了1000,那么ycsb会尽量往这个数目去靠近。默认是不做限制
-threads n Number of client threads (default: 1) // 客户端线程数
设置ycsb client的并发测试线程数,默认是1,单线程,所以再测试的时候,一定要设置这个选项
(3).-P workload文件 基础配置:
recordcount=1000 # 总共的操作条数
operationcount=1000 # 总共操作的次数
workload=com.yahoo.ycsb.workloads.CoreWorkload=
readallfields=true # 在读取的时候,是否需要读取所有字段
readproportion=0.5 # 读取比例
updateproportion=0.5 # update比例
scanproportion=0
insertproportion=0
requestdistribution=zipfian
mongodb.url=mongodb://10.2.10.167:27017/ycsb? # mongodb对应的uri等
mongodb.database=ycsb # 对应的db
mongodb.writeConcern=0# 写级别
(4).YCSB的运行分为两个阶段:测试数据加载阶段和测试操作执行阶段,每个阶段又可以分同步与异步
该阶段主要用于构造测试数据,ycsb会基于参数设定,往db里面构造测试需要的数据(目前是关闭了mongodb的authorization进行测试的)
./bin/ycsb load mongodb -s -P workloads/workloada -p mongodb.url=mongodb://10.2.10.167:27017/ycsb?w=0 > outputLoad.txt
加载结束后可以看到类似于如下输出:
执行阶段
./bin/ycsb run mongodb -s -P workloads/workloada -p mongodb.url=mongodb://10.2.10.167:27017/ycsb?w=0 > outputRun.txt
运行结束后可以看到类似于如下输出:
mongo client connection created with mongodb://10.2.10.167:27017/ycsb?w=0
[OVERALL], RunTime(ms), 1897.0 #执行时间
[OVERALL], Throughput(ops/sec), 527.1481286241434 #每秒操作数,吞吐量
[TOTAL_GCS_Copy], Count, 7.0
[TOTAL_GC_TIME_Copy], Time(ms), 23.0
[TOTAL_GC_TIME_%_Copy], Time(%), 1.2124406958355298
[TOTAL_GCS_MarkSweepCompact], Count, 0.0
[TOTAL_GC_TIME_MarkSweepCompact], Time(ms), 0.0
[TOTAL_GC_TIME_%_MarkSweepCompact], Time(%), 0.0
[TOTAL_GCs], Count, 7.0
[TOTAL_GC_TIME], Time(ms), 23.0
[TOTAL_GC_TIME_%], Time(%), 1.2124406958355298
[READ], Operations, 512.0 #操作数
[READ], AverageLatency(us), 1282.00390625 #平均操作时间
[READ], MinLatency(us), 164.0 #最小操作时间
[READ], MaxLatency(us), 94847.0 #最大操作时间
[READ], 95thPercentileLatency(us), 3857.0 #95%操作时间
[READ], 99thPercentileLatency(us), 6327.0 #99%操作时间
[READ], Return=OK, 512 #操作成功数
[CLEANUP], Operations, 1.0
[CLEANUP], AverageLatency(us), 6066.0
[CLEANUP], MinLatency(us), 6064.0
[CLEANUP], MaxLatency(us), 6067.0
[CLEANUP], 95thPercentileLatency(us), 6067.0
[CLEANUP], 99thPercentileLatency(us), 6067.0
[UPDATE], Operations, 488.0
[UPDATE], AverageLatency(us), 963.094262295082
[UPDATE], MinLatency(us), 165.0
[UPDATE], MaxLatency(us), 20431.0
[UPDATE], 95thPercentileLatency(us), 3787.0
[UPDATE], 99thPercentileLatency(us), 6035.0
[UPDATE], Return=OK, 488
使用ycsb对mariadb做性能测试
本文详细演示在16G,4核cpu配置下用ycsb(版本0.17)对mariadb(版本10.3.18)单实例进行性能测试。
测试表数据量:一百万条数据
一 安装ycsb
安装包下载地址:
https://github.com/brianfrankcooper/YCSB/releases/download/0.17.0/ycsb-0.17.0.tar.gz
tar xfvz ycsb-0.17.0.tar.gz
cd ycsb-0.17.0
二 配置mariadb
2.1 建库建表
create database ycsb;
use ycsb;
CREATE TABLE usertable (
YCSB_KEY VARCHAR(255) PRIMARY KEY,
FIELD0 TEXT, FIELD1 TEXT,
FIELD2 TEXT, FIELD3 TEXT,
FIELD4 TEXT, FIELD5 TEXT,
FIELD6 TEXT, FIELD7 TEXT,
FIELD8 TEXT, FIELD9 TEXT
);
三 使用ycsb对mariadb做性能测试
3.1 配置ycsb的连接信息
cd jdbc-binding/conf
mv db.properties db.properties_bak
vi db.properties
db.driver=com.mysql.jdbc.Driver
db.url=jdbc:mysql://172.18.16.116:3306/ycsb
db.user=root
db.passwd=123456
3.2 将JDBC驱动程序添加到CLASSPATH下
jdbc驱动下载地址:
MySQL :: Download MySQL Connector/J (Archived Versions)
cd /opt/
tar -xvf mysql-connector-java-5.1.49.tar.gz
cp mysql-connector-java-5.1.49/mysql-connector-java-5.1.49.jar /opt/ycsb-0.17.0/jdbc-binding/lib/
3.3 验证50/50 的读取和写入
3.3.1 配置workload
cd ycsb-0.17.0/workloads/
mv workloada workloada_bak
vi workloada
recordcount=1000000
operationcount=100000
workload=site.ycsb.workloads.CoreWorkload
readallfields=true
readproportion=0.5
updateproportion=0.5
scanproportion=0
insertproportion=0
requestdistribution=zipfian
threadcount=100
3.3.2 加载数据
../bin/ycsb load jdbc -P workloada -P ../jdbc-binding/conf/db.properties > a_load.txt
cat a_load.txt
[OVERALL], RunTime(ms), 131983
[OVERALL], Throughput(ops/sec), 7576.733367176075
[TOTAL_GCS_PS_Scavenge], Count, 318
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 423
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.32049582143154803
[TOTAL_GCS_PS_MarkSweep], Count, 0
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0
[TOTAL_GCs], Count, 318
[TOTAL_GC_TIME], Time(ms), 423
[TOTAL_GC_TIME_%], Time(%), 0.32049582143154803
[CLEANUP], Operations, 100
[CLEANUP], AverageLatency(us), 117.64
[CLEANUP], MinLatency(us), 43
[CLEANUP], MaxLatency(us), 4627
[CLEANUP], 95thPercentileLatency(us), 104
[CLEANUP], 99thPercentileLatency(us), 506
[INSERT], Operations, 1000000
[INSERT], AverageLatency(us), 13123.248375
[INSERT], MinLatency(us), 1183
[INSERT], MaxLatency(us), 157567
[INSERT], 95thPercentileLatency(us), 22943
[INSERT], 99thPercentileLatency(us), 42719
[INSERT], Return=OK, 1000000
OPS为7576。
3.3.3 开始读写测试
../bin/ycsb run jdbc -P workloada -P ../jdbc-binding/conf/db.properties > a_run.txt
cat a_run.txt
[OVERALL], Throughput(ops/sec), 7672.830507174097
[TOTAL_GCS_PS_Scavenge], Count, 5
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 29
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.22251208470804879
[TOTAL_GCS_PS_MarkSweep], Count, 0
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0
[TOTAL_GCs], Count, 5
[TOTAL_GC_TIME], Time(ms), 29
[TOTAL_GC_TIME_%], Time(%), 0.22251208470804879
[READ], Operations, 50193
[READ], AverageLatency(us), 622.6863307632539
[READ], MinLatency(us), 196
[READ], MaxLatency(us), 37695
[READ], 95thPercentileLatency(us), 1305
[READ], 99thPercentileLatency(us), 3097
[READ], Return=OK, 50193
[CLEANUP], Operations, 100
[CLEANUP], AverageLatency(us), 119.21
[CLEANUP], MinLatency(us), 44
[CLEANUP], MaxLatency(us), 4403
[CLEANUP], 95thPercentileLatency(us), 131
[CLEANUP], 99thPercentileLatency(us), 505
[UPDATE], Operations, 49807
[UPDATE], AverageLatency(us), 22214.912783343705
[UPDATE], MinLatency(us), 1249
[UPDATE], MaxLatency(us), 650239
[UPDATE], 95thPercentileLatency(us), 22063
[UPDATE], 99thPercentileLatency(us), 451839
[UPDATE], Return=OK, 49807
ops为7672。
3.4 验证95/5的读/写混合
3.4.1 配置workload
mv workloadb workloadb_bak
vi workloadb
recordcount=1000000
operationcount=100000
workload=site.ycsb.workloads.CoreWorkload
readallfields=true
readproportion=0.95
updateproportion=0.05
scanproportion=0
insertproportion=0
requestdistribution=zipfian
threadcount=100
3.4.2 开始读写测试
../bin/ycsb run jdbc -P workloadb -P ../jdbc-binding/conf/db.properties > b_run.txt
cat b_run.txt
[OVERALL], RunTime(ms), 3374
[OVERALL], Throughput(ops/sec), 29638.41138114997
[TOTAL_GCS_PS_Scavenge], Count, 5
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 49
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 1.4088556641748131
[TOTAL_GCS_PS_MarkSweep], Count, 0
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0
[TOTAL_GCs], Count, 5
[TOTAL_GC_TIME], Time(ms), 49
[TOTAL_GC_TIME_%], Time(%), 1.4088556641748131
[READ], Operations, 94901
[READ], AverageLatency(us), 1856.332915353895
[READ], MinLatency(us), 173
[READ], MaxLatency(us), 423935
[READ], 95thPercentileLatency(us), 4883
[READ], 99thPercentileLatency(us), 17327
[READ], Return=OK, 94901
[CLEANUP], Operations, 100
[CLEANUP], AverageLatency(us), 179.95
[CLEANUP], MinLatency(us), 43
[CLEANUP], MaxLatency(us), 5763
[CLEANUP], 95thPercentileLatency(us), 131
[CLEANUP], 99thPercentileLatency(us), 5055
[UPDATE], Operations, 5099
[UPDATE], AverageLatency(us), 16231.637183761522
[UPDATE], MinLatency(us), 1532
[UPDATE], MaxLatency(us), 245887
[UPDATE], 95thPercentileLatency(us), 43839
[UPDATE], 99thPercentileLatency(us), 108031
[UPDATE], Return=OK, 5099
OPS为29638。
本篇文章参考了:
YCSB/jdbc at master · brianfrankcooper/YCSB · GitHub
使用YCSB测试Hbase与Mysql数据库性能_neymar1204的博客-CSDN博客
以上是关于YCSB压力测试工具安装的主要内容,如果未能解决你的问题,请参考以下文章