硬件环境优化
操作系统级调优
/etc/sysctl.conf,调整关键参数以提升IO和网络性能,执行sysctl -p使配置生效:fs.file-max = 1000000(增加文件描述符限制,避免HBase因文件描述符耗尽无法启动);vm.swappiness = 10(减少内存交换,避免频繁IO);net.core.rmem_max = 16777216、net.core.wmem_max = 16777216(增大TCP接收/发送缓冲区,提升网络传输效率)。noatime(不更新访问时间)或relatime(减少时间戳更新),降低磁盘IO:mount -o remount,noatime /path/to/hbase/data。sudo fallocate -l 2G /swapfile → sudo chmod 600 /swapfile → sudo mkswap /swapfile → sudo swapon /swapfile → echo "/swapfile swap swap defaults 0 0" | sudo tee -a /etc/fstab。echo never > /sys/kernel/mm/transparent_hugepage/enabled → echo never > /sys/kernel/mm/transparent_hugepage/defrag,并在/etc/rc.local中添加上述命令(开机自启)。HBase配置参数优化
hbase-env.sh,设置RegionServer堆内存(根据服务器内存调整,如8GB):export HBASE_HEAPSIZE=8G、export HBASE_REGIONSERVER_OPTS="-Xms8g -Xmx8g"(堆内存需预留10%给操作系统);hbase-site.xml中添加:<property name="hbase.regionserver.global.memstore.size">0.4</property>(占堆内存40%,避免MemStore占用过多内存导致Full GC);<property name="hbase.regionserver.memstore.flush.size">268435456</property>(256MB触发刷盘,平衡写性能与数据持久性);<property name="hbase.regionserver.blockcache.size">0.4</property>(占堆内存40%,适合读多写少场景)。Splits参数预先划分Region(如按时间范围或哈希值),避免数据集中写入单个Region导致的热点问题:hbase shell> create 'my_table', {NAME => 'cf', VERSIONS => 1}, SPLITS => ['1000', '2000', '3000']。Long.MAX_VALUE - timestamp)或哈希前缀(如MD5(user_id)[0:4] + user_id),使数据均匀分布在Region上。<property name="hbase.hfile.compression">SNAPPY</property>。hbase shell> scan 'my_table', {CACHE_BLOCKS => true, CACHE_SIZE => 1000}(CACHE_BLOCKS开启缓存,CACHE_SIZE设置缓存块数)。setWriteToWAL(false)),提升写入速度,但需承担数据丢失风险(仅适用于离线场景)。<property name="hbase.regionserver.optionallogflushinterval">1000</property>(设置为1000ms,即1秒刷一次WAL)。数据操作优化
put(List<Put>)、get(List<Get>)等批量接口,减少客户端与RegionServer之间的RPC调用次数(提升写入/读取效率)。setCaching(500)),减少多次IO;addColumn(Bytes.toBytes("cf"), Bytes.toBytes("col1"))),避免全表扫描。ROW或ROWCOL类型),减少无效磁盘读取(适用于读多写少场景):<property name="hbase.mapreduce.hfileoutputformat.bloom.enabled">true</property>。JVM与GC调优
ParallelGC(JDK8默认,吞吐量高);G1GC(低延迟,适合大内存):export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:+UseG1GC -XX:MaxGCPauseMillis=200"(设置最大GC停顿时间为200ms)。export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -XX:+UseMemStoreLocalAllocationBuffer -XX:MemStoreChunkSize=64m"(MemStoreChunkSize设置为64MB,适合大多数场景)。监控与持续调优
hbase.jmx.enabled=true)获取详细性能指标(如GC时间、内存使用率)。hbase hbck检查表一致性;每月清理无用HFile(hbase clean);根据数据增长情况调整Region大小(hbase.hregion.max.filesize,如从10GB调整为20GB),避免Region过大导致查询性能下降。