数据有多种尺寸,保存 HBase 中的所有数据(包括图像和文档等二进制数据)是理想的选择。虽然 HBase 在技术上可以处理大小超过 100 KB 的单元格的二进制对象,但 HBase 的正常读取和写入路径针对小于 100KB 的值进行了优化。当 HBase 处理超过此阈值的大量对象(此处称为中等对象或 MOB)时,由于分割和压缩引起的写入放大,性能会降低。使用 MOB 时,理想情况下,您的对象将介于 100KB 和 10MB 之间(参见 FAQ )。 HBase **FIX_VERSION_NUMBER **增加了对更好地管理大量 MOB 的支持,同时保持了性能,一致性和低运营开销。 MOB 支持由 HBASE-11339 完成的工作提供。要利用 MOB,您需要使用 HFile 版本 3 。 (可选)为每个 RegionServer 配置 MOB 文件读取器的缓存设置(请参阅配置 MOB 缓存),然后配置特定列以保存 MOB 数据。客户端代码无需更改即可利用 HBase MOB 支持。该功能对客户端是透明的。

MOB 压缩

在 MemStore 刷新后,MOB 数据被刷新到 MOB 文件中。一段时间后会有很多 MOB 文件。为了减少 MOB 文件数量,有一个周期性任务可以将小型 MOB 文件压缩成大型 MOB 文件(MOB 压缩)。

76.1。为 MOB 配置列

您可以在表创建或更改期间配置列以支持 MOB,无论是在 HBase Shell 中还是通过 Java API。两个相关的属性是布尔IS_MOBMOB_THRESHOLD,它是一个对象被认为是 MOB 的字节数。只需要IS_MOB。如果未指定MOB_THRESHOLD,则使用默认阈值 100 KB。

使用 HBase Shell 为 MOB 配置列

hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400}
hbase> alter 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400} 

示例 23.使用 Java API 为 MOB 配置列

...
HColumnDescriptor hcd = new HColumnDescriptor(“f”);
hcd.setMobEnabled(true);
...
hcd.setMobThreshold(102400L);
... 

76.2。配置 MOB 压缩策略

默认情况下,将特定日期的 MOB 文件压缩为一个大型 MOB 文件。为了更多地减少 MOB 文件数,还支持其他 MOB 压缩策略。

每日策略 - 压缩 MOB 文件一天进入一个大型 MOB 文件(默认策略)每周策略 - 紧凑 MOB 文件一周到一个大型 MOB 文件 montly 策略 - 紧凑 MOB 文件一个月到一个大 MOB 文件

使用 HBase Shell 配置 MOB 压缩策略

hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'daily'}
hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'weekly'}
hbase> create 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'monthly'}

hbase> alter 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'daily'}
hbase> alter 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'weekly'}
hbase> alter 't1', {NAME => 'f1', IS_MOB => true, MOB_THRESHOLD => 102400, MOB_COMPACT_PARTITION_POLICY => 'monthly'} 

76.3。配置 MOB 压缩可合并阈值

如果一个 mob 文件的大小小于这个值,它被认为是一个小文件,需要在 mob compaction 中合并。默认值为 1280MB。

<property>
    <name>hbase.mob.compaction.mergeable.threshold</name>
    <value>10000000000</value>
</property> 

76.4。测试 MOB

提供实用程序org.apache.hadoop.hbase.IntegrationTestIngestWithMOB以帮助测试 MOB 功能。该实用程序运行如下:

$ sudo -u hbase hbase org.apache.hadoop.hbase.IntegrationTestIngestWithMOB \
            -threshold 1024 \
            -minMobDataSize 512 \
            -maxMobDataSize 5120 
  • **threshold**是细胞被认为是 MOB 的阈值。默认值为 1 kB,以字节为单位表示。

  • **minMobDataSize**是 MOB 数据大小的最小值。默认值为 512 B,以字节为单位表示。

  • **maxMobDataSize**是 MOB 数据大小的最大值。默认值为 5 kB,以字节为单位表示。

76.5。配置 MOB 缓存

因为可以随时存在大量 MOB 文件,与 HFiles 的数量相比,MOB 文件并不总是保持打开状态。 MOB 文件读取器缓存是一个 LRU 缓存,它保持最近使用的 MOB 文件打开。要在每个 RegionServer 上配置 MOB 文件读取器的缓存,请将以下属性添加到 R​​egionServer 的hbase-site.xml,自定义配置以适合您的环境,然后重新启动或滚动重新启动 RegionServer。

示例 24.示例 MOB 缓存配置

<property>
    <name>hbase.mob.file.cache.size</name>
    <value>1000</value>
    <description>
      Number of opened file handlers to cache.
      A larger value will benefit reads by providing more file handlers per mob
      file cache and would reduce frequent file opening and closing.
      However, if this is set too high, this could lead to a "too many opened file handers"
      The default value is 1000.
    </description>
</property>
<property>
    <name>hbase.mob.cache.evict.period</name>
    <value>3600</value>
    <description>
      The amount of time in seconds after which an unused file is evicted from the
      MOB cache. The default value is 3600 seconds.
    </description>
</property>
<property>
    <name>hbase.mob.cache.evict.remain.ratio</name>
    <value>0.5f</value>
    <description>
      A multiplier (between 0.0 and 1.0), which determines how many files remain cached
      after the threshold of files that remains cached after a cache eviction occurs
      which is triggered by reaching the `hbase.mob.file.cache.size` threshold.
      The default value is 0.5f, which means that half the files (the least-recently-used
      ones) are evicted.
    </description>
</property> 

76.6。 MOB 优化任务

76.6.1。手动压缩 MOB 文件

要手动压缩 MOB 文件,而不是等待配置触发压缩,请使用compactmajor_compact HBase shell 命令。这些命令要求第一个参数为表名,并将列族作为第二个参数。并将压缩类型作为第三个参数。

hbase> compact 't1', 'c1’, ‘MOB’
hbase> major_compact 't1', 'c1’, ‘MOB’ 

这些命令也可通过Admin.compactAdmin.majorCompact方法获得。