使用yscb对MongoDB进行压测

1.安装yscb

1.1 下载yscb

文件名: ycsb-0.17.0.tar.gz

git下载地址:

https://github.com/brianfrankcooper/YCSB/releases/tag/0.17.0

下载完后解压

tar -zxvf ycsb-0.17.0.tar.gz

1.2 其他环境准备工作

安装Java:

yum install java-devel -y

安装maven:

下载地址: https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

安装:

wget https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar xzf apache-maven-*-bin.tar.gz -C /usr/local
cd /usr/local
ln -s apache-maven-* maven
vi /etc/profile.d/maven.sh

在maven.sh中加入:

export M2_HOME=/usr/local/maven
export PATH=${M2_HOME}/bin:${PATH}

Reload bash 测试mvn是否工作正常

[root@hlet-fastdfs-tracker01 maven]# bash
[root@hlet-fastdfs-tracker01 maven]# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/maven
Java version: 1.8.0_252, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-2.el7_8.x86_64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-957.el7.x86_64", arch: "amd64", family: "unix"

2.压测

2.1 准备数据

ycsb提前已经在workload文件夹下准备好了几个压测场景分别对应workload[a:f]

workloada 读写均衡型,50%读,50%写
workloadb 读多写少型,95%读,5%更新。
workloadc 只读,100%读。
workloadd 读最近写入记录型,95%读,5%插入。
workloade 扫描小区间型,95%扫描,5%插入。
workloadf 读写入记录均衡型,50%读,50%读、修改、写。

经过和开发人员沟通,workloadf最符合生产环境的实际场景,这里我们copy一份workloadf,编辑一下我们MongoDB相关测试的配置

mongodb.url=mongodb://mongouser:mongopassowrd@10.1.99.77:27017,10.1.99.78:27017/?authSource=admin
mongodb.batchsize=1000
mongodb.maxconnections=10000
table=workload_1e_2
recordcount=100000000
operationcount=100000000
workload=site.ycsb.workloads.CoreWorkload

readallfields=true

readproportion=0.5
updateproportion=0
scanproportion=0
insertproportion=0
readmodifywriteproportion=0.5

requestdistribution=zipfian

配置文件准备好了之后,我们通过load指令来生成数据:

./bin/ycsb load mongodb -P workloads/workloadf_mongo

默认会在MongoDB生成一个yscb的库,由于我们指定了collection名称,所以数据会插入到yscb.workload_1e_2这个collection里

注意,如果要测试分片集群的数据,最好提前创建好相应的集合并按_id分片:

mongos> use ycsb
switched to db ycsb
mongos> db.createCollection('workload_1e_2')
{
    "ok" : 1,
    "operationTime" : Timestamp(1595495035, 4),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1595495035, 4),
        "signature" : {
            "hash" : BinData(0,"3X4B1s5oImsWrbkS8Klk9fOSYrk="),
            "keyId" : NumberLong("6850640688736895007")
        }
    }
}
mongos> sh.shardCollection("ycsb.workload_1e_2" ,{ "_id" : 1 })
{
    "collectionsharded" : "ycsb.workload_1e_2",
    "collectionUUID" : UUID("661fd309-e737-44c4-8674-c54889cc070d"),
    "ok" : 1,
    "operationTime" : Timestamp(1595495123, 10),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1595495123, 10),
        "signature" : {
            "hash" : BinData(0,"Wz1RBvhevN8SzYc7Fb5xsiYUuao="),
            "keyId" : NumberLong("6850640688736895007")
        }
    }
}

数据准备命令输出:

[root@hlet-fastdfs-tracker01 ycsb-0.17.0]# ./bin/ycsb load mongodb -P workloads/workloadf_mongo
java -cp /root/ycsb-0.17.0/mongodb-binding/conf:/root/ycsb-0.17.0/conf:/root/ycsb-0.17.0/lib/core-0.17.0.jar:/root/ycsb-0.17.0/lib/htrace-core4-4.1.0-incubating.jar:/root/ycsb-0.17.0/lib/jackson-mapper-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/jackson-core-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/HdrHistogram-2.1.4.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongo-java-driver-3.8.0.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-classic-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/slf4j-api-1.7.25.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-async-driver-2.0.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/snappy-java-1.1.7.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-core-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-binding-0.17.0.jar site.ycsb.Client -db site.ycsb.db.MongoDbClient -P workloads/workloadf_mongo -load
Command line: -db site.ycsb.db.MongoDbClient -P workloads/workloadf_mongo -load
YCSB Client 0.17.0

Loading workload...
Starting test.
mongo client connection created with mongodb://mongouser:mongopassowrd@10.1.99.77:27017,10.1.99.78:27017/?authSource=admin&maxPoolSize=10000
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []

[OVERALL], RunTime(ms), 1678202
[OVERALL], Throughput(ops/sec), 59587.58242452339
[TOTAL_GCS_PS_Scavenge], Count, 7024
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 16525
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.984684799565249
[TOTAL_GCS_PS_MarkSweep], Count, 4
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 187
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.011142877913385875
[TOTAL_GCs], Count, 7028
[TOTAL_GC_TIME], Time(ms), 16712
[TOTAL_GC_TIME_%], Time(%), 0.9958276774786348
[CLEANUP], Operations, 128
[CLEANUP], AverageLatency(us), 137.578125
[CLEANUP], MinLatency(us), 1
[CLEANUP], MaxLatency(us), 17375
[CLEANUP], 95thPercentileLatency(us), 3
[CLEANUP], 99thPercentileLatency(us), 27
[INSERT], Operations, 100000000
[INSERT], AverageLatency(us), 2141.56641891
[INSERT], MinLatency(us), 545
[INSERT], MaxLatency(us), 1204223
[INSERT], 95thPercentileLatency(us), 4771
[INSERT], 99thPercentileLatency(us), 8695
[INSERT], Return=OK, 100000000

2.2 实际压测

这次换成run命令来实际运行workloadf场景

./bin/ycsb run mongodb -P workloads/workloadf_mongo

输出:

[root@hlet-fastdfs-tracker01 ycsb-0.17.0]# ./bin/ycsb run mongodb -P workloads/workloadf_mongo
java -cp /root/ycsb-0.17.0/mongodb-binding/conf:/root/ycsb-0.17.0/conf:/root/ycsb-0.17.0/lib/core-0.17.0.jar:/root/ycsb-0.17.0/lib/htrace-core4-4.1.0-incubating.jar:/root/ycsb-0.17.0/lib/jackson-mapper-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/jackson-core-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/HdrHistogram-2.1.4.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongo-java-driver-3.8.0.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-classic-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/slf4j-api-1.7.25.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-async-driver-2.0.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/snappy-java-1.1.7.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-core-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-binding-0.17.0.jar site.ycsb.Client -db site.ycsb.db.MongoDbClient -P workloads/workloadf_mongo -t
Command line: -db site.ycsb.db.MongoDbClient -P workloads/workloadf_mongo -t
YCSB Client 0.17.0

Loading workload...
Starting test.
mongo client connection created with mongodb://mongouser:mongopassowrd@10.1.99.77:27017,10.1.99.78:27017/?authSource=admin&maxPoolSize=10000
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []
[OVERALL], RunTime(ms), 1666002
[OVERALL], Throughput(ops/sec), 60023.93754629346
[TOTAL_GCS_PS_Scavenge], Count, 7050
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 15970
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.9585822826143067
[TOTAL_GCS_PS_MarkSweep], Count, 17
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 633
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.03799515246680376
[TOTAL_GCs], Count, 7067
[TOTAL_GC_TIME], Time(ms), 16603
[TOTAL_GC_TIME_%], Time(%), 0.9965774350811104
[READ], Operations, 100000000
[READ], AverageLatency(us), 1410.02291897
[READ], MinLatency(us), 508
[READ], MaxLatency(us), 2095103
[READ], 95thPercentileLatency(us), 2133
[READ], 99thPercentileLatency(us), 5599
[READ], Return=OK, 100000000
[READ-MODIFY-WRITE], Operations, 49997401
[READ-MODIFY-WRITE], AverageLatency(us), 2841.3056152658814
[READ-MODIFY-WRITE], MinLatency(us), 1108
[READ-MODIFY-WRITE], MaxLatency(us), 2144255
[READ-MODIFY-WRITE], 95thPercentileLatency(us), 4019
[READ-MODIFY-WRITE], 99thPercentileLatency(us), 7759
[CLEANUP], Operations, 128
[CLEANUP], AverageLatency(us), 134.71875
[CLEANUP], MinLatency(us), 1
[CLEANUP], MaxLatency(us), 16975
[CLEANUP], 95thPercentileLatency(us), 3
[CLEANUP], 99thPercentileLatency(us), 24
[UPDATE], Operations, 49997401
[UPDATE], AverageLatency(us), 1428.009917735524
[UPDATE], MinLatency(us), 516
[UPDATE], MaxLatency(us), 2055167
[UPDATE], 95thPercentileLatency(us), 2087
[UPDATE], 99thPercentileLatency(us), 3955
[UPDATE], Return=OK, 49997401

使用100%读的场景再测一次:

workloadc_mongo:

[root@hlet-fastdfs-tracker01 ycsb-0.17.0]# cat workloads/workloadc_mongo
mongodb.url=mongodb://mongouser:mongopassowrd@10.1.99.77:27017,10.1.99.78:27017/?authSource=admin
mongodb.batchsize=10000
mongodb.maxconnections=10000
threadcount=128
table=workload_1e_2
recordcount=100000000
operationcount=100000000
workload=site.ycsb.workloads.CoreWorkload

readallfields=true

readproportion=1
updateproportion=0
scanproportion=0
insertproportion=0

requestdistribution=zipfian

由于数据总量是一样的,这里就不重复生成数据了,直接run

[root@hlet-fastdfs-tracker01 ycsb-0.17.0]# ./bin/ycsb run mongodb -P workloads/workloadc_mongo
java -cp /root/ycsb-0.17.0/mongodb-binding/conf:/root/ycsb-0.17.0/conf:/root/ycsb-0.17.0/lib/core-0.17.0.jar:/root/ycsb-0.17.0/lib/htrace-core4-4.1.0-incubating.jar:/root/ycsb-0.17.0/lib/jackson-mapper-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/jackson-core-asl-1.9.4.jar:/root/ycsb-0.17.0/lib/HdrHistogram-2.1.4.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongo-java-driver-3.8.0.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-classic-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/slf4j-api-1.7.25.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-async-driver-2.0.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/snappy-java-1.1.7.1.jar:/root/ycsb-0.17.0/mongodb-binding/lib/logback-core-1.1.2.jar:/root/ycsb-0.17.0/mongodb-binding/lib/mongodb-binding-0.17.0.jar site.ycsb.Client -db site.ycsb.db.MongoDbClient -P workloads/workloadc_mongo -t
Command line: -db site.ycsb.db.MongoDbClient -P workloads/workloadc_mongo -t
YCSB Client 0.17.0

Loading workload...
Starting test.
mongo client connection created with mongodb://mongouser:mongopassowrd@10.1.99.77:27017,10.1.99.78:27017/?authSource=admin&maxPoolSize=10000
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []
DBWrapper: report latency for each error is false and specific error codes to track for latency are: []
[OVERALL], RunTime(ms), 1237596
[OVERALL], Throughput(ops/sec), 80801.81254625904
[TOTAL_GCS_PS_Scavenge], Count, 5132
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 11950
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.9655816599277954
[TOTAL_GCS_PS_MarkSweep], Count, 14
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 508
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.041047320773499596
[TOTAL_GCs], Count, 5146
[TOTAL_GC_TIME], Time(ms), 12458
[TOTAL_GC_TIME_%], Time(%), 1.0066289807012951
[READ], Operations, 100000000
[READ], AverageLatency(us), 1579.5437729
[READ], MinLatency(us), 527
[READ], MaxLatency(us), 2426879
[READ], 95thPercentileLatency(us), 2071
[READ], 99thPercentileLatency(us), 2815
[READ], Return=OK, 100000000
[CLEANUP], Operations, 128
[CLEANUP], AverageLatency(us), 134.296875
[CLEANUP], MinLatency(us), 1
[CLEANUP], MaxLatency(us), 16991
[CLEANUP], 95thPercentileLatency(us), 3
[CLEANUP], 99thPercentileLatency(us), 27

根据监控信息和结果粗略的算了一下,108G的数据,20多分钟跑完,已经是千兆网络的极限了...包括上面的读写混合测试,混合上传下载,网络也是到达了极限,所以暂时还没有测出这个集群的完整实力...

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343