HBase 中读 HDFS 调优

HDFS Read调优

在基于 HDFS 存储的 HBase 中,主要有两种调优方式:

  1. 绕过RPC的选项,称为short circuit reads
  2. 开启让HDFS推测性地从多个datanode读数据的选项,称为 hedged reads

Short-Circuit Reads

一般来说,HBase RegionServer 与 HDFS DataNode在一起,所以可以实现很好的数据本地化。但是在早期Hadoop 1.0.0版本中,RegionServer 在与 DataNode通过RPC通信时,与其他常规客户端一样,需要经过整个RPC通信过程。在 Hadoop 1.0.0 版本之后,加入了short-circuit read选项,它可以完全绕过RPC栈,通过本地clients直接从底层文件系统读数据。

Hadoop 2.x 之后进一步优化了这个实现。当前DataNode与HDFS客户端(HBase也是其中一个)可以使用一个称为file descriptor passing的功能,使得数据交换全部发生在OS kernel层。相较于之前的实现会更快,更高效。使得多个进程在同一个实例上进行高效地交互。

在Hadoop中,可以参考以下官方文档配置启用short-circuit reads:

https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/ShortCircuitLocalReads.html

下面是一个配置参考,需要在hbase-site.xml 与 hdfs-site.xml 两个配置文件中均配置,且配置完后需重启进程:

<property>
  <name>dfs.client.read.shortcircuit</name>
  <value>true</value>
  <description>
    This configuration parameter turns on short-circuit local reads.
  </description>

</property>
<property>
  <name>dfs.domain.socket.path</name>
  <value>/var/lib/hadoop-hdfs/dn_socket</value>
  <description>
    Optional. This is a path to a UNIX domain socket that will be used for
    communication between the DataNode and local HDFS clients.
    If the string "_PORT" is present in this path, it will be replaced by the
    TCP port of the DataNode.
  </description>
</property>

需要注意的是:dfs.domain.socket.path指定的文件(可以先不存在)的owner必须为OS的root用户,或者是运行datanode服务的用户。

最后,short-circuit read buffers的默认大小由dfs.client.read.shortcircuit.buffer.size指定,对于很繁忙的HBase 集群来说,默认值可能会比较高。在HBase中,如果没有没有显示指定此值,则会从默认的 1MB 直接降为 128KB(使用的是hbase.dfs.client.read.shortcircuit.buffer.size 属性,默认为128KB)。

在HBase 中的HDFS客户端,会为每个打开的data block分配一个direct byte buffer ,大小为参数hbase.dfs.client.read.shortcircuit.buffer.size 指定大小。此功能可以让HBase永久保持它的HDFS文件打开,所以会很快地增加。

Hedged Reads

Hedged reads是HDFS的一个功能,在Hadoop 2.4.0之后引入。一般来说,每个读请求都会由生成的一个线程处理。在Hedged reads 启用后,客户但可以等待一个预配置的时间,如果read没有返回,则客户端会生成第二个读请求,访问同一份数据的另一个block replica。之后,其中任意一个read 先返回的话,则另一个read请求则被丢弃。

Hedged reads使用的场景是:解决少概率的slow read(可能由瞬时错误导致,例如磁盘错误或是网络抖动等)。

HBase region server 是一个 HDFS client,所以我们可以在HBase中启用hedged reads,通过在 RegionServer 中的 hbase-site.xml 配置增加以下参数,并且根据实际环境对参数进行调整:

  • def.client.hedged.read.threadpool.size:默认值为0。指定有多少线程用于服务hedged reads。如果此值设置为0(默认),则hedged reads为disabled状态
  • dfs.client.hedged.read.threshold.millis:默认为500(0.5秒):在spawning 第二个线程前,等待的时间。

下面是一个示例配置,设置等待阈值为10ms,并且线程数为20:

<property>
  <name>dfs.client.hedged.read.threadpool.size</name>
  <value>20</value>
</property>

<property>
  <name>dfs.client.hedged.read.threshold.millis</name>
  <value>10</value>
</property>

需要注意的是:hedged reads 在HDFS中的功能,类似于MapReduce中的speculative execution:需要消耗额外的资源。例如,根据集群的负载与设定,它可能需要触发很多额外的读操作,且大部分是发送到远端的block replicas。产生的额外的I/O、以及网络可能会对集群性能造成较大影响。对此,需要在生产环境中的负载进行测试,以决定是否使用此功能。

猜你喜欢

转载自www.cnblogs.com/zackstang/p/11721377.html