# 1 mongodb环境
已安装mongodb单节点服务或副本集模式选择对主节点测试即可
# 2 安装 JAVA 和 Maven
yum install java-devel -y
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
# 编辑 maven.sh 添加内容:
vim /etc/profile.d/maven.sh
# 加入如下内容:
export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}
source /etc/profile
# 确定 mvn 是否安装成功:
mvn -version
# 3 下载 YCSB
cd /usr/src
curl -O --location https://github.com/brianfrankcooper/YCSB/releases/download/0.5.0/ycsb-0.5.0.tar.gz
tar xfz ycsb-0.5.0.tar.gz
cd ycsb-0.5.0
# 4 编辑配置文件
vim workloads/workloada
# 修改如下内容:
mongodb.url=mongodb://root:密码@192.168.100.23:27017 # mongodb://用户名:密码@IP:端口
recordcount=100000
operationcount=500000
workload=com.yahoo.ycsb.workloads.CoreWorkload
readallfields=true
readproportion=1
updateproportion=0
scanproportion=0
insertproportion=0
requestdistribution=zipfian
# 关于 YCSB 的压测文件的每个参数的解释如下:
recordcount:加载到数据库的记录数;
operationcount:执行的操作数;
workload:工作负载类型;
readproportion:读取操作的比例;
updateproportion:更新操作的比例;
scanproportion:扫描操作的比例;
insertproportion:插入操作的比例;
requestdistribution:应该使用什么分布方式来选择要操作的记录,包括:uniform, zipfian, hotspot, sequential, exponential 和 latest。
# 5 运行压测
#加载压测数据:
./bin/ycsb load mongodb -P workloads/workloada
#进行压测:
./bin/ycsb run mongodb -P workloads/workloada
#可看到如下结果:
......
[OVERALL], RunTime(ms), 27187.0
[OVERALL], Throughput(ops/sec), 1839.1142825615184
[READ], Operations, 25202.0
[READ], AverageLatency(us), 413.5915800333307
[READ], MinLatency(us), 226.0
[READ], MaxLatency(us), 120703.0
[READ], 95thPercentileLatency(us), 558.0
[READ], 99thPercentileLatency(us), 1021.0
[READ], Return=OK, 25202
[CLEANUP], Operations, 1.0
[CLEANUP], AverageLatency(us), 1297.0
[CLEANUP], MinLatency(us), 1297.0
[CLEANUP], MaxLatency(us), 1297.0
[CLEANUP], 95thPercentileLatency(us), 1297.0
[CLEANUP], 99thPercentileLatency(us), 1297.0
[UPDATE], Operations, 24798.0
[UPDATE], AverageLatency(us), 651.412371965481
[UPDATE], MinLatency(us), 344.0
[UPDATE], MaxLatency(us), 753663.0
[UPDATE], 95thPercentileLatency(us), 761.0
[UPDATE], 99thPercentileLatency(us), 1317.0
[UPDATE], Return=OK, 24798
通过 “[OVERALL], Throughput(ops/sec)”,可看出我们压测的实例 OPS 大概为:1839。当然,压测过程也需要关注 CPU、内存等,看是否已经到极限了。
完成测试后清理数据,根据需求调整配置文件workloads/workloada的参数,可再继续测试
mongo --port 27017 -u root -p '密码'
use ycsb
db.dropDatabase()