JAVA_HOME
环境变量。hbase-site.xml
、hbase-env.sh
)。关键配置包括:
hbase.rootdir
:指定HDFS存储路径(如hdfs://namenode:8020/hbase
)或本地路径(单节点测试用file:///tmp/hbase
);hbase.zookeeper.quorum
:ZooKeeper地址(单节点设为localhost
);hbase.cluster.distributed
:分布式模式设为true
(集群)或false
(单节点)。YCSB是针对分布式数据库设计的开源性能测试工具,支持HBase绑定,提供丰富的测试场景(如读/写混合、批量导入等)。
wget https://github.com/brianfrankcooper/YCSB/releases/download/0.17.0/ycsb-hbase20-binding-0.17.0.tar.gz
sudo tar -xzf ycsb-hbase20-binding-0.17.0.tar.gz -C /opt
export YCSB_HOME="/opt/ycsb-hbase20-binding-0.17.0"
usertable
),并设置预分区(提升批量写入性能):cat << EOF | hbase shell
disable 'usertable'
drop 'usertable'
n_splits = 30 # 建议为RegionServer数量的10倍
create 'usertable', 'cf', {SPLITS => (1..n_splits).map {|i| "user#{1000+i*(9999-1000)/n_splits}"}}
describe 'usertable'
EOF
workloada
:读/写比例9:1;workloadb
:读/写比例50:50),可根据测试目标选择。修改workloads
目录下的Workload文件(如workloada
),调整参数:recordcount=1000000 # 总记录数
operationcount=1000000 # 总操作数
columnfamily=cf # 列簇名称
table=usertable # 表名
HBase PE是HBase自带的性能测试工具,适合简单的压测场景(如批量写入、扫描)。
./bin/hbase pe -Dmapreduce.output.fileoutputformat.compress=true -Dmapreduce.task.timeout=60000
--rows
:每个客户端的行数(如--rows=100000
);--size
:数据总大小(如--size=10G
);--nomapred
:使用多线程而非MapReduce(适合小数据量测试);-t
:测试类型(如-t put
:批量写入;-t scan
:扫描)。$YCSB_HOME/bin/ycsb load hbase20 -cp /etc/hbase/conf/ -p columnfamily=cf -P $YCSB_HOME/workloads/workloada
nohup $YCSB_HOME/bin/ycsb run hbase20 -cp /etc/hbase/conf/ -p columnfamily=cf -P $YCSB_HOME/workloads/workloadb -threads 32 -s &> ycsb_result.log &
(-threads
:并发线程数;-s
:打印统计信息到控制台)./bin/hbase pe -Dmapreduce.output.fileoutputformat.compress=true -Dmapreduce.task.timeout=60000 --rows=1000000 --threads=32 -t put
top
、htop
、iotop
命令监控CPU、内存、磁盘I/O使用情况;使用jstat
、jstack
监控JVM垃圾回收(GC)情况(如jstat -gcutil <pid> 1000
)。ycsb_result.log
会包含吞吐量(Throughput,ops/sec)、延迟(Latency,avg/p99/p999)、错误率等指标。-threads
)、调整HBase块大小(hbase.hregion.max.filesize
)、优化RowKey设计(避免热点)。hbase.regionserver.handler.count
(RegionServer处理线程数,默认30,可根据并发量增加);hfile.block.cache.size
,默认0.4,可设为0.6);hbase.hregion.compress
,设为SNAPPY
,减少磁盘占用)。vm.swappiness
设为10,减少交换分区使用);hbase.regionserver.heapsize
,根据节点资源调整,如16GB)。通过以上流程,可在Debian环境下完成HBase的性能测试,并通过监控与分析定位瓶颈,优化系统性能。