HBase性能测试工具YCSB怎么安装
这篇文章给大家分享的是有关HBase性能测试工具YCSB怎么安装的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
YCSB
一、背景概念英文全称:Yahoo!CloudServing Benchmark(YCSB)。是Yahoo公司的一个用来对云服务进行基础测试的工具。目标是促进新一代云数据服务系统的性能比较。为四个广泛使用的系统:Cassandra、HBase、PNUTS和一个简单的片式MySQL执行,订了套核心基础测试和结果报告。
二、资源获取首先在官网上下载源码编译或者直接下载软件包
https://github.com/brianfrankcooper/YCSB/releases/tag/0.10.0
编译的话需要maven工程和其他资源包的依赖比较麻烦,建议直接下载软件包。
补充一点编译的内容:
下载好最新源码
解压到本地并进入源码根目录YCSB-0.10.0
如果想编译出完整版的话直接输入
mvn clean package
编译成功的话,在YCSB-0.10.0/distribution目录下会有对应的ycsb的压缩包,拷贝解压即可使用
这种方法编译出的完整版ycsb适用于多种数据库所以依赖的库太多,目标文件太大,耗费时间太长,不建议用这种方式编译。
建议单独编一个只用于测试某个数据库(例如hbase)的ycsb可输入
mvn -pl com.yahoo.ycsb:hbase10-binding -am clean package #我就是用这种方法编的
编译结果节选:
…..
[INFO] Building tar: /opt/YCSB-0.10.0/hbase10/target/ycsb-hbase10-binding-0.10.0.tar.gz
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] YCSB Root ......................................... SUCCESS [1.903s]
[INFO] Core YCSB ......................................... SUCCESS [8.384s]
[INFO] Per Datastore Binding descriptor .................. SUCCESS [0.497s]
[INFO] YCSB Datastore Binding Parent ..................... SUCCESS [0.582s]
[INFO] HBase 1.0 DB Binding .............................. SUCCESS [51.209s]
[INFO] ------------------------------------------------------------------------
[INFO]BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:03.143s
[INFO] Finished at: Sat Jul 09 11:30:05 PHT 2016
[INFO] Final Memory: 52M/1694M
[INFO] ------------------------------------------------------------------------
这种方法编译成功的话,在YCSB-0.10.0/hbase10/target目录下会有
ycsb-hbase10-binding-0.10.0.tar.gz压缩包即我们的目标文件,解压之后即可使用
环境中的mvn仓库使用的是172.7.1.216上的资源,在实际编译的过程中会遇到依赖包不匹配或者依赖包不存在的问题,可以手动的在search.maven.org上去搜索下载相应的资源放在本地的~/.m2/repository/的对应目录下即可
我们这里测的是hbase所以就是直接下载了ycsb-hbase10-binding-0.10.0.tar.gz(注意这个只是对hbase10即hbase1.0的适用,官网上有一个对所有数据库全适用的软件包,300M太大了网络不好没有必要去下)使用。
三、配置与使用这里首先要去检查下hbase-site.xml中的配置是否正确,不然在运行ycsb时会报错
<property>
<name>hbase.regionserver.global.memstore.size</name>
<value>0.4</value>
</property>
.
.
.
<property>
<name>hfile.block.cache.size</name>
<value>0.2</value>
</property>
将下载好的ycsb-hbase10-binding-0.10.0.tar.gz解压使用
目录结构:
[root@node1 ycsb-hbase10-binding-0.10.0]# ll
total 24
drwxr-xr-x 2 root root 46 Jul 8 15:12 bin
drwxr-xr-x 2 root root 4096 Jul 8 15:12lib
-rw-r--r-- 1 root root 8082 Jul 7 20:45 LICENSE.txt
-rw-r--r-- 1 root root 615 Jul 7 20:45 NOTICE.txt
-rw-r--r-- 1 root root 5484 Jul 7 20:45 README.md
drwxrwxr-x 2 root root 126 Jul 7 20:45workloads
这里额外介绍一下一个完全版本的ycsb的目录结构
[root@node1 ycsb-0.1.4]# ll
total 20
drwxrwxrwx 2 501 games 31 Feb 24 2012 bin
drwxr-xr-x 3 root root 16 Jul 8 11:49 cassandra-binding
-rw-r--r-- 1 501 games 2291 Feb 24 2012 CHANGELOG
drwxr-xr-x 3 root root 16 Jul 8 11:49 core
drwxr-xr-x 4 root root 27 Jul 8 11:49 gemfire-binding
drwxr-xr-x 4 root root 27 Jul 8 11:49hbase-binding
drwxr-xr-x 4 root root 27 Jul 8 11:49 infinispan-binding
drwxr-xr-x 4 root root 27 Jul 8 11:49 jdbc-binding
-rw-r--r-- 1 501 games 8082 Feb 19 2012 LICENSE.txt
drwxr-xr-x 3 root root 29 Jul 8 11:49 mapkeeper-binding
drwxr-xr-x 3 root root 16 Jul 8 11:49 mongodb-binding
drwxr-xr-x 4 root root 40 Jul 8 11:49 nosqldb-binding
-rw-r--r-- 1 501 games 479 Feb 19 2012 NOTICE.txt
-rw-r--r-- 1 501 games 952 Feb 24 2012 README
drwxr-xr-x 3 root root 16 Jul 8 11:49 redis-binding
drwxr-xr-x 2 root root 27 Jul 8 14:38 results
drwxr-xr-x 4 root root 27 Jul 8 11:49 voldemort-binding
drwxrwxrwx 2 501 games 102 Feb 22 2012 workloads
完整版需要手动去拷贝相关hbase库到hbase-binding的lib目录下,并将hbase-site.xml拷贝至hbase-binding的conf目录下。
而我们ycsb-hbase10-binding-0.10.0针对性更强更加精简,在lib目录下面有所需的各种库文件,无需手动从hbase的lib目录下去cp过来了,也没有conf目录,我们只需直接使用bin下面的ycsb即可。
下面介绍下具体的使用方法:
1、 hbase上建表,YCSB需要在HBase中创建一张叫usertable的表,表中包含一个Cloumn Family,CF的名称可以自定义。先后执行以下两个命令:
hbase(main):011:0*n_splits=120
=> 120
hbase(main):015:0>create 'usertable','family',{SPLITS => (1...n_splits).map{|i| "user#{1000+i*(9999-1000)/n_splits}"}}
0 row(s) in 18.3610 seconds
=> Hbase::Table - usertable
命令含义:pre-splittingstrategy预分区和建表
使用HBase shell建表的同时建立一些预分区,这样可以防止初次插入数据时的热点问题
2、使用以下命令进行测试
首先初始化数据
-cp指定了hbase的配置文件所在的路径/usr/hdp/2.4.2.0-258/hbase/conf/(前面提到过精简版的ycsb没有conf目录)
用户首先需要用load初始化数据库,然后用run运行负载。dbname指定了目标数据库。
目前YCSB自带了6种负载(workloads/目录下),其中五种如下表。用户可以自定义操作(read、update、insert和scan)的比例,以及选择操作目标记录的分布:Uniform(等概率随机选择记录)、Zipfian(随机选择记录,存在热纪录)和Latest(近期写入的记录是热记录)。
-P指定负载文件的位置。
-p用来设置一些参数,比如数据库的 ip和port。当然,在运行YCSB之前,目标数据库必须是开启的。测试完成后,YCSB会打印平均/最小/最大延迟等信息。后面可以带参数threads recordcount 等等
-s 输出运行状态,在运行时间较长时比较有用
[root@node1ycsb-hbase10-binding-0.10.0]#bin/ycsb load hbase10 -P workloads/workloada -cp/usr/hdp/2.4.2.0-258/hbase/conf/ -p table=usertable -p columnfamily=family -s -threads10 -p recordcount=100
#这里加载的是workloada负载,read和update操作各占一半
2016-07-08 16:19:37,129 WARN [Thread-2] util.DynamicClassLoader: Failed to identify the fs of dir hdfs://node1.dcom:8020/apps/hbase/data/lib, ignored
java.io.IOException: No FileSystem for scheme: hdfs该错误可以忽略!!!
at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2579)
at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2586)
at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:89)
at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2625)
at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2607)
at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:368)
at org.apache.hadoop.fs.Path.getFileSystem(Path.java:296)
at org.apache.hadoop.hbase.util.DynamicClassLoader.<init>(DynamicClassLoader.java:104)
at org.apache.hadoop.hbase.protobuf.ProtobufUtil.<clinit>(ProtobufUtil.java:232)
at org.apache.hadoop.hbase.ClusterId.parseFrom(ClusterId.java:64)
at org.apache.hadoop.hbase.zookeeper.ZKClusterId.readClusterIdZNode(ZKClusterId.java:75)
at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getClusterId(ZooKeeperRegistry.java:86)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.retrieveClusterId(ConnectionManager.java:833)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.<init>(ConnectionManager.java:623)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:238)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:218)
at org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(ConnectionFactory.java:119)
at com.yahoo.ycsb.db.HBaseClient10.init(HBaseClient10.java:149)
at com.yahoo.ycsb.DBWrapper.init(DBWrapper.java:99)
at com.yahoo.ycsb.ClientThread.run(Client.java:418)
at java.lang.Thread.run(Thread.java:745)
Ycsb运行完之后的结果打印和分析:
[OVERALL], RunTime(ms), 2787.0数据加载所用时间:2.787秒
[OVERALL], Throughput(ops/sec), 35.88087549336204加载操作的吞吐量,平均并发量每秒35.88条
[TOTAL_GCS_PS_Scavenge], Count, 1.0
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 20.0
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.7176175098672408
[TOTAL_GCS_PS_MarkSweep], Count, 0.0
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0.0
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0
[TOTAL_GCs], Count, 1.0
[TOTAL_GC_TIME], Time(ms), 20.0
[TOTAL_GC_TIME_%], Time(%), 0.7176175098672408
[CLEANUP], Operations, 2.0执行cleanup的操作总数,2
[CLEANUP], AverageLatency(us), 63575.0平均响应时间63.575ms
[CLEANUP], MinLatency(us), 14.0最小响应时间0.014ms
[CLEANUP], MaxLatency(us), 127167.0最大响应时间127.167ms
[CLEANUP], 95thPercentileLatency(us), 127167.0 95%的cleanup操作延时在127.167ms以内
[CLEANUP], 99thPercentileLatency(us), 127167.0 99%的cleanup操作延时在127.167ms以内
[INSERT], Operations, 100.0执行insert操作的总数,100
[INSERT], AverageLatency(us), 13681.54每次insert操作的平均时延,13.68154ms
[INSERT], MinLatency(us), 5556.0所有insert操作最小延时,5.556ms
[INSERT], MaxLatency(us), 201343.0所有insert操作最大延时,201.343ms
[INSERT], 95thPercentileLatency(us), 30063.0 95%的insert操作延时在30.063ms以内
[INSERT], 99thPercentileLatency(us), 53183.0 99%的insert操作延时在53.183ms以内
[INSERT], Return=OK, 1000成功返回数,1000
然后执行run程序
[root@node1ycsb-hbase10-binding-0.10.0]#bin/ycsb run hbase10 -Pworkloads/workloada -cp /usr/hdp/2.4.2.0-258/hbase/conf/ -p table=usertable -pcolumnfamily=family -s –threads 10 -p recordcount=100
Ycsb运行完成结果打印与分析:
[OVERALL], RunTime(ms), 6921.0数据加载所用时间:6.921秒
[OVERALL], Throughput(ops/sec), 144.48779078167894加载操作的吞吐量,平均并发量每秒144.48条
[TOTAL_GCS_PS_Scavenge], Count, 1.0
[TOTAL_GC_TIME_PS_Scavenge], Time(ms), 20.0
[TOTAL_GC_TIME_%_PS_Scavenge], Time(%), 0.2889755815633579
[TOTAL_GCS_PS_MarkSweep], Count, 0.0
[TOTAL_GC_TIME_PS_MarkSweep], Time(ms), 0.0
[TOTAL_GC_TIME_%_PS_MarkSweep], Time(%), 0.0
[TOTAL_GCs], Count, 1.0
[TOTAL_GC_TIME], Time(ms), 20.0
[TOTAL_GC_TIME_%], Time(%), 0.2889755815633579
[CLEANUP], Operations, 2.0执行cleanup的操作总数,2
[CLEANUP], AverageLatency(us), 71591.5平均响应时间71.5915ms
[CLEANUP], MinLatency(us), 15.0最小响应时间0.015ms
[CLEANUP], MaxLatency(us), 143231.0最大响应时间143.231ms
[CLEANUP], 95thPercentileLatency(us), 143231.0 95%的insert操作延时在143.231ms以内
[CLEANUP], 99thPercentileLatency(us), 143231.0 99%的insert操作延时在143.231ms以内
[READ], Operations, 480.0执行read的操作总数,480
[READ], AverageLatency(us), 5027.9625平均响应时间5.027ms
[READ], MinLatency(us), 2254.0最小响应时间2.254ms
[READ], MaxLatency(us), 158847.0最大响应时间158.847ms
[READ], 95thPercentileLatency(us), 10767.0 95%的read操作延时在10.767ms以内
[READ], 99thPercentileLatency(us), 14599.0 99%的read操作延时在14.599ms以内
[READ], Return=OK, 480成功返回数,480
[UPDATE], Operations, 520.0执行read的操作总数,520
[UPDATE], AverageLatency(us), 5812.123076923077平均响应时间5.812ms
[UPDATE], MinLatency(us), 3302.0最小响应时间3.302ms
[UPDATE], MaxLatency(us), 86207.0最大响应时间86.207ms
[UPDATE], 95thPercentileLatency(us), 9991.0 95%的read操作延时在9.991ms以内
[UPDATE], 99thPercentileLatency(us), 11839.0 99%的insert操作延时在11.839ms以内
[UPDATE], Return=OK, 520成功返回数,520
四、用例介绍这里介绍下,我们在用ycsb进行hbase性能测试时的用例方法。
首先,测试使用了ycsb_load.sh和ycsb_run.sh这两个脚本来直接进行,用户只需自定义一个类似于workload类型的配置文件即可。
对应目录结构:
[root@node5 test]# pwd
/root/ycsb-hbase10-binding-0.10.0/workloads/test
[root@node5 test]# ll
total 4338592
-rw-r--r-- 1 root hadoop 1189 Aug 27 22:35 TR1003
-rw-r--r-- 1 root hadoop 4080039015 Aug 29 03:12 TR1003.report
-rw-r--r-- 1 root hadoop 800 Aug 30 16:20 TR1004
-rw-r--r-- 1 root hadoop 306542869 Aug 30 16:31 TR1004.report
-rw-r--r-- 1 root hadoop 751 Aug 30 10:06 TR1005
-rw-r--r-- 1 root hadoop 56106292 Aug 30 10:20 TR1005.report
-rw-r--r-- 1 root hadoop 631 Aug 23 19:07 workload_test_template
-rwxr-xr-x 1 root hadoop 590 Aug 23 17:52 ycsb_load.sh
-rwxr-xr-x 1 root hadoop 609 Aug 30 16:35 ycsb_run.sh
其中后缀名为report的文件是脚本运行和ycsb运行时的所有终端打印记录(文件较大,测完之后取得关键数值后可以删除)。
Ycsb_load.sh脚本内容:
echo "******Loading test begin******"
# define the path of ycsb
YCSB="/root/ycsb-hbase10-binding-0.10.0"
# define the path of hbase_site.xml
hbase=$YCSB"/bin"
# define test path
test=$YCSB"/workloads/test/"
# define the file path of workload
workload=$test$1
# define the log file name
report=$test$1".report"
# define ycbs runner
runner=$YCSB"/bin/ycsb"
# define measurement param
raw_file=$test$1".raw"
measurement_param="measurement.raw.output_file="$raw_file
# run test
$runner load hbase10 -cp $hbase -P $workload -s -jvm-args='-Xmx32g' 1>>$report 2>>$report
echo "******Loading test end******"
脚本内容较为简单,ycsb_run.sh脚本的内容与上述内容几乎一样(最后一句的ycsb运行命令中的load改为run),其中$1变量时用户在运行时所指定的配置文件(workload、TR1003等)。
-jvm-args='-Xmx32g'这个是用来配置ycsb运行时jvm虚拟机的内存大小的,这里的意思是最多给ycsb clinet进程分配32G的内存
具体用法:sh ycsb_load.sh TR1003
ycsb配置文件TR1003(作用跟workload文件相同)
# The thread count
threadcount=20
# The number of fields in a record
fieldcount=1
# The size of each field (in bytes)
fieldlength=9216
# Number of Records will be loaded
recordcount=1500000000
# Number of Operations will be handle in run parsh
operationcount=1500000000
readallfields=true
insertorder=hashed
insertstart=0
insertcount=500000000
# Control Porption of hbase operation type
readproportion=0
updateproportion=0
scanproportion=1
insertproportion=0
# The following param always be fixed
# The table name
table=usertable
# The colume family
columnfamily=cf
# The workload class
workload=com.yahoo.ycsb.workloads.CoreWorkload
# The measurement type
measurementtype=raw
clientbuffering=true
writebuffersize=25165824
#requestdistribution=zipfian
这个配置文件是单独用来load阶段加载数据库时候用的,其中clientbuffer配置项是配置hbase client端的写缓存,配置写缓存有利用减少写hbase操作时的rpc开销,具体作用可以查看hbase测试调优文档,默认是不配的,该配置项默认的值是配置项writebuffersize=1024*1024*12(12M),requestdistribution是指操作需求分布采用的方式,。
Run阶段配置文件TR1003:
# The thread count
threadcount=100
# The number of fields in a record
fieldcount=1
# The size of each field (in bytes)
fieldlength=9216
# Number of Records will be loaded
recordcount=1500000000
# Number of Operations will be handle in run parsh
operationcount=2000000
readallfields=true
#insertorder=hashed
#insertstart=0
#insertcount=500000000
# Control Porption of hbase operation type
readproportion=0
updateproportion=0
scanproportion=1
insertproportion=0
# The following param always be fixed
# The table name
table=usertable
# The colume family
columnfamily=cf
# The workload class
workload=com.yahoo.ycsb.workloads.CoreWorkload
# The measurement type
measurementtype=raw
maxscanlength=1000000
#hbase.usepagefilter=false
#scanlengthdistribution=zipfian
#requestdistribution=latest
这个配置文件用在run阶段,与ycsb_run.sh配合使用,这里run阶段主要就是读hbase数据库的数据。
scan:
Maxscanlength配置项用来指定scan的条数(在ycsb代码中的实现方式是取1~Maxscanlength中的随机值作为一次scan的条数)
hbase.usepagefilter配置项是scan一次的结果是否采取分页显示,默认是开启的
scanlengthdistribution配置项决定了以何种方式从1~Maxscanlength区间中取值,还是默认的uniform(等概率随机分布)。
另外值得注意的是在执行scan操作中,ycsb每秒操作数currentops/sec可能会很小:
2016-08-30 04:21:40:791 60 sec: 1 operations;0.1current ops/sec; est completion in 1388 days 21hours SCAN count: 1, average latency(us): 49083737.00
这个是由于ycsb计算方式的原因,它只计算每次具体的操作数,而不是scan总数,所以0.1可以理解为在10秒钟的时间内执行了1次scan操作,所以这10秒的平均操作数是0.1 current ops/sec。
对于scan操作我们可以通过带宽来计算一次操作到底扫描了多少条数据。
Read:
Read的话跟load阶段输出类似,每次查找一条读取。
注意!!!:
Load阶段其实就是装载数据即往hbase中插入数据,workload文件中的recordcount就是将要插入的条数,run阶段就是对hbase进行各种操作,operationcount就是操作数,因此load阶段必须要正确执行完成,否则在run阶段会有类似于[READ-FAILED]之类的错误。
感谢各位的阅读!关于“HBase性能测试工具YCSB怎么安装”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。