HBase设计:看上去很美

本文涉及的产品
服务治理 MSE Sentinel/OpenSergo,Agent数量 不受限
简介:

缘起

随着hadoop系列的兴起,基于HDFS的大规模KV存储系统HBase也进入“大规模使用阶段”。网上的Hbase资料很多,学习成本正在下降。从公开的资料看,国外facebook、国内taobao均宣称在线上环境大规模使用hbase。一切都让人很兴奋。于是,在项目中引入Hbase做存储,最终却选择放弃。

HBase设计:看上去很美

HBase是模仿google bigtable的开源产品,又是hadoop的衍生品,hadoop作为离线计算系统已经得到业界的普遍认可,并经过N多公司大规模使用的验证,自然地认为Hbase也将随之获得成功。

《HBase: The Definitive Guide》第8章讲述hbase的架构,从架构上看,其架构很完美:

LSM - 解决磁盘随机写问题(顺序写才是王道);

HFile - 解决数据索引问题(只有索引才能高效读);

WAL - 解决数据持久化(面对故障的持久化解决方案);

zooKeeper - 解决核心数据的一致性和集群恢复;

Replication - 引入类似MySQL的数据复制方案,解决可用性;

此外还有:自动分拆Split、自动压缩(compaction,LSM的伴生技术)、自动负载均衡、自动region迁移。

看上去如此美好,完全无需人工干预,貌似只要将Hbase搭建好,一切问题Hbase都将应对自如。面对如此完美的系统,不动心很难。

但是,如此完美的系统或许也意味着背后的复杂性是不容忽略的。hbase的代码量也不是一星半点的。假如系统工作不正常,谁来解决?这是至关重要的。

性能与测试

Hbase系统自身提供了性能测试工具:./bin/hbase org.apache.hadoop.hbase.PerformanceEvaluation,该工具提供了随机读写、多客户端读写等性能测试功能。根据工具测试的结果看,hbase的性能不算差。

对于hbase这样的系统长期稳定运行比什么都重要。然而,这或许就不那么"完美"。

测试版本:hbase 0.94.1、 hadoop 1.0.2、 jdk-6u32-linux-x64.bin、snappy-1.0.5.tar.gz

测试hbase搭建:14台存储机器+2台master、DataNode和regionserver放在一起。

hbase env配置:

 
  1. View Code
  2. ulimit -n 65536
  3. export HBASE_OPTS="$HBASE_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode"
  4. export HBASE_REGIONSERVER_OPTS="$HBASE_REGIONSERVER_OPTS -Xmx20g -Xms20g -Xmn512m -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSIn
  5. itiatingOccupancyFraction=60 -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -Xloggc:$HBASE_HOME/logs/gc-$(hostname)-hbase.lo
  6. g"

hbase-size.xml关键配置(根据《HBase: The Definitive Guide》第11章优化):

 
  1. View Code
  2. <property>
  3. <name>hbase.regionserver.handler.count</name>
  4. <value>16</value>
  5. <description>Count of RPC Listener instances spun up on RegionServers.
  6. Same property is used by the Master for count of master handlers.
  7. Default is 10.
  8. </description>
  9. </property>
  10. <property>
  11. <name>hbase.regionserver.global.memstore.upperLimit</name>
  12. <value>0.35</value>
  13. <description>Maximum size of all memstores in a region server before new
  14. updates are blocked and flushes are forced. Defaults to 40% of heap
  15. </description>
  16. </property>
  17. <property>
  18. <name>hbase.regionserver.global.memstore.lowerLimit</name>
  19. <value>0.3</value>
  20. <description>When memstores are being forced to flush to make room in
  21. memory, keep flushing until we hit this mark. Defaults to 35% of heap.
  22. This value equal to hbase.regionserver.global.memstore.upperLimit causes
  23. the minimum possible flushing to occur when updates are blocked due to
  24. memstore limiting.
  25. </description>
  26. </property>
  27. <property>
  28. <name>hfile.block.cache.size</name>
  29. <value>0.35</value>
  30. <description>
  31. Percentage of maximum heap (-Xmx setting) to allocate to block cache
  32. used by HFile/StoreFile. Default of 0.25 means allocate 25%.
  33. Set to 0 to disable but it's not recommended.
  34. </description>
  35. </property>
  36. <property>
  37. <name>zookeeper.session.timeout</name>
  38. <value>600000</value>
  39. <description>ZooKeeper session timeout.
  40. HBase passes this to the zk quorum as suggested maximum time for a
  41. session (This setting becomes zookeeper's 'maxSessionTimeout'). See
  42. http://hadoop.apache.org/zookeeper/docs/current/zookeeperProgrammers.html#ch_zkSessions
  43. "The client sends a requested timeout, the server responds with the
  44. timeout that it can give the client. " In milliseconds.
  45. </description>
  46. </property>
  47. <property>
  48. <name>hbase.zookeeper.property.tickTime</name>
  49. <value>60000</value>
  50. </property>
  51. <property>
  52. <name>hbase.regionserver.restart.on.zk.expire</name>
  53. <value>true</value>
  54. </property>
  55. <property>
  56. <name>hbase.hregion.majorcompaction</name>
  57. <value>0</value>
  58. <description>The time (in miliseconds) between 'major' compactions of all
  59. HStoreFiles in a region. Default: 1 day(86400000).
  60. Set to 0 to disable automated major compactions.
  61. </description>
  62. </property>
  63. <property>
  64. <name>hbase.hregion.max.filesize</name>
  65. <value>536870912000</value>
  66. <description>
  67. Maximum HStoreFile size. If any one of a column families' HStoreFiles has
  68. grown to exceed this value, the hosting HRegion is split in two.
  69. Default: 1G(1073741824). Set 500G, disable file split!
  70. </description>
  71. </property>

测试一:高并发读(4w+/s) + 少量写(允许分拆、负载均衡)

症状:1-2天后,hbase挂掉(系统性能极差,不到正常的10%)。其实并非全部挂掉,而是某些regionserver挂了,并在几个小时内引发其他regionserver挂掉。系统无法恢复:单独启regionserver无法恢复正常。重启后正常。

测试二:高并发读(4w+/s)

症状:1-2天后,hbase挂掉(系统性能极差,不到正常的10%)。后发现是由于zookeeper.session.timeout设置不正确导致(参见regionserver部分:http://hbase.apache.org/book.html#trouble)。重启后正常。

测试三:高并发读(4w+/s)

症状:1-2天后,hbase挂掉(系统性能极差,不到正常的10%)。从log未看出问题,但regionserver宕机,且datanode也宕机。重启后正常。

测试四:高并发读(4w+/s)+禁止分拆、禁止majorcompaction、禁止负载均衡(balance_switch命令)

症状:1-2天后,hbase挂掉(系统性能极差,不到正常的10%)。从log未看出问题,但regionserver宕机,且datanode也宕机。重启后正常。

测试期间,还发现过:无法获取".MATE."表的内容(想知道regionserver的分布情况)、hbase无法正确停止、hbase无法正确启动(日志恢复失败,文件错误,最终手动删除日志重启)。

其他缺陷

HBase使用JAVA开发,看上去很美的GC使用中代价可不小。Hbase为了保证数据强一致性,每个key只能由一个regionserver提供服务。在下列情况下,Hbase服务质量都将受损:

1) GC CMS -- CMS回收内存极其耗时,当hbase运行1-2天后,CMS可能耗时10分钟,这期间该regionserver无法服务。CMS经常被触发,这意味着hbase的服务经常会因为GC操作而部分暂停!

2) regionserver宕机 - 为了强一致性,每个key只由一个regionserver提供服务,故当regionserver宕机后,相应的region即无法服务!

3) major compaction、split不可控 - 大量磁盘操作将极大影响服务。(levelDB也需要major compaction,只是使用更加可控的方式做压缩,比如一次只有一个压缩任务。是否影响服务,待测试)

4) 数据恢复 - 数据恢复期间设置WAL log的相关操作,在数据恢复期间regionserver无法服务!

结论

或许通过研究hbase的源码可让hbase稳定运行,但从上述测试结果看:1)hbase还无法稳定长期运行;2)hbase系统很脆弱,故障恢复能力差。基于此,判断hbase还无法满足大规模线上系统的运维标准,只能放弃。考虑到hbase重启基本可恢复正常,故hbase还是可作为离线存储系统使用。

替代方案

面对大规模数据,基于磁盘的存储系统是必不可少的。google虽然公开了bigtable的设计,但未开源,但google开源了levelDB KV存储系统库(http://code.google.com/p/leveldb/)。levelDB采用C++实现,1.7版本的代码量大概2W,实现了LSM(自动压缩)、LevelFile(基本同HFile),WAL,提供了简单的Put、Get、Delete、Write(批量写、事务功能)等接口。levelDB库实现了单机单库的磁盘存储方案,开发者可根据自己需要开发定制的存储系统(比如:数据Replication、自动调度、自动恢复、负载均衡等)。

相关实践学习
云数据库HBase版使用教程
&nbsp; 相关的阿里云产品:云数据库 HBase 版 面向大数据领域的一站式NoSQL服务,100%兼容开源HBase并深度扩展,支持海量数据下的实时存储、高并发吞吐、轻SQL分析、全文检索、时序时空查询等能力,是风控、推荐、广告、物联网、车联网、Feeds流、数据大屏等场景首选数据库,是为淘宝、支付宝、菜鸟等众多阿里核心业务提供关键支撑的数据库。 了解产品详情:&nbsp;https://cn.aliyun.com/product/hbase &nbsp; ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库&nbsp;ECS 实例和一台目标数据库&nbsp;RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&amp;RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
分布式数据库 索引 Hbase
《HBase应用与发展之HBase RowKey与索引设计》电子版地址
HBase应用与发展之HBase RowKey与索引设计
100 0
《HBase应用与发展之HBase RowKey与索引设计》电子版地址
|
分布式数据库 Hbase
|
分布式数据库 Hbase
|
存储 分布式数据库 开发者
HBase表设计_8 | 学习笔记
快速学习 HBase表设计_8
114 0
|
存储 分布式数据库 开发者
HBase 表设计_7 | 学习笔记
快速学习 HBase 表设计_7
102 0
|
分布式数据库 开发者 Hbase
HBase 表设计_6 | 学习笔记
快速学习 HBase 表设计_6
100 0
|
存储 大数据 Java
HBase 表设计_5 | 学习笔记
快速学习 HBase 表设计_5
97 0
|
分布式数据库 开发者 Hbase
HBase 表设计_4 | 学习笔记
快速学习 HBase 表设计_4
101 0
|
分布式数据库 开发者 Hbase
HBase 表设计_3 | 学习笔记
快速学习 HBase 表设计_3
103 0
|
分布式数据库 开发者 Hbase
HBase表设计_2 | 学习笔记
快速学习 HBase表设计_2
103 0