HDFS Balancer工具可以用来分析块的分布情况,并且可以重新分配DataNode中的数据。本文通过为您介绍如何使用HDFS Balancer工具以及Balancer的主要调优参数。
使用HDFS Balancer
方式一:使用HDFS Balancer命令
hdfs balancer
[-threshold <threshold>]
[-policy <policy>]
[-exclude [-f <hosts-file> | <comma-separated list of hosts>]]
[-include [-f <hosts-file> | <comma-separated list of hosts>]]
[-source [-f <hosts-file> | <comma-separated list of hosts>]]
[-blockpools <comma-separated list of blockpool ids>]
[-idleiterations <idleiterations>]
参数 | 描述 |
---|---|
threshold | 磁盘容量的百分数。
默认值为10%,表示上下浮动10%。 当集群总使用率较高时,需要调小Threshold,避免阈值过高。 当集群新增节点较多时,您可以适当增加Threshold,使数据从高使用率节点移向低使用率节点。 |
policy | 平衡策略。支持以下策略:
|
exclude | Balancer排除特定的DataNode。 |
include | Balancer仅对特定的DataNode进行平衡操作。 |
source | 仅选择特定的DataNode作为源节点。 |
blockpools | Balancer仅在指定的blockpools中运行。 |
idleiterations | 最多允许的空闲循环次数。覆盖默认的5次。 |
方式二:使用start-balancer.sh工具
start-balancer.sh实际上是调用hdfs daemon start balancer命令。使用方式如下:
Balancer调优参数
- 客户端配置
参数 描述 dfs.balancer.dispatcherThreads Balancer在移动Block之前,每次迭代时查询出一个Block列表,分发给Mover线程使用。 说明 dispatcherThreads是该分发线程的个数,默认为200。dfs.balancer.rpc.per.sec 默认值为20,即每秒发送的RPC数量为20。 因为分发线程调用大量getBlocks的RPC查询,所以为了避免NameNode由于分发线程压力过大,需要控制分发线程RPC的发送速度。
例如,您可以在负载高的集群调整参数值,减小10或者5,对整体移动进度不会产生特别大的影响。
dfs.balancer.getBlocks.size Balancer会在移动Block前,每次迭代时查询出一个Block列表,给Mover线程使用,默认Block列表中Block的大小为2 GB。因为getBlocks过程会对RPC进行加锁,所以您可以根据NameNode压力进行调整。 dfs.balancer.moverThreads 默认值为1000。 Balancer处理移动Block的线程数,每个Block移动时会使用一个线程。
- DataNode配置
参数 描述 dfs.datanode.balance.bandwidthPerSec 指定DataNode用于Balancer的带宽,通常推荐设置为100 MB/s,您也可以通过dfsadmin -setBalancerBandwidth 参数进行适当调整,无需重启DataNode。
例如,在负载低时,增加Balancer的带宽。在负载高时,减少Balancer的带宽。
dfs.datanode.balance.max.concurrent.moves 默认值为5。
指定DataNode节点并发移动的最大个数。通常考虑和磁盘数匹配,推荐在DataNode端设置为
4 * 磁盘数
作为上限,可以使用Balancer的值进行调节。例如:一个DataNode有28块盘,在Balancer端设置为28,DataNode端设置为
28 * 4
。具体使用时根据集群负载适当调整。在负载较低时,增加concurrent数;在负载较高时,减少concurrent数。
常见问题
Q:为什么Balancer的threshold设置为10(%),但是平衡以后看到差值为20%左右?
A:threshold的含义是控制每个DataNode的使用率不高于或者不低于集群平均的使用率,所以使用率最多和最少的DataNode在平衡后可能差值为20%。要减少这种差距,可以尝试把差值调节到5(%)。