官方详解HDFS Balancer工具主要调优参数
作者:阿里云 时间:2023-07-24 04:43:47
引言
HDFS Balancer工具可以用来分析块的分布情况,并且可以重新分配DataNode中的数据。本文通过为您介绍如何使用HDFS Balancer工具以及Balancer的主要调优参数。
使用HDFS 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>]
Balancer主要参数如下表。
参数 | 描述 |
---|---|
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的最大带宽。
hdfs dfsadmin -setBalancerBandwidth <bandwidth in bytes per second>
说明 <bandwidth in bytes per second>
为设置的最大带宽。例如,如果需要设置最大带宽为20 MB/s,对应值为20971520,则完整代码示例为hdfs dfsadmin -setBalancerBandwidth 20971520
。如果集群负载较高,建议设置为209715200(200 MB/s);如果集群空闲,建议设置为1073741824(1 GB/s)。
执行以下命令,切换到hdfs用户并执行Balancer参数。
DataLake集群
su hdfs
/opt/apps/HDFS/hdfs-current/sbin/start-balancer.sh -threshold 5
Hadoop集群
su hdfs
/usr/lib/hadoop-current/sbin/start-balancer.sh -threshold 5
执行以下命令,进入HDFS安装目录。
DataLake集群
cd /var/log/emr/hadoop/
Hadoop集群
cd /var/log/hadoop-hdfs
执行以下命令,查看Balancer运行情况。
当提示信息包含Successfully
字样时,表示执行成功。
DataLake集群
tailf hadoop-hdfs-balancer-master-1-1.c-xxx.log
Hadoop集群
tailf hadoop-hdfs-balancer-emr-header-1.cluster-xxx.log
说明 命令中的hadoop-hdfs-balancer-master-1-1.c-xxx.log
和hadoop-hdfs-balancer-emr-header-xx.cluster-xxx.log
为上一步骤中获取到的日志名称。
Balancer调优参数
执行Balancer会占用一定的系统资源,建议在业务空闲期执行。默认情况下,不需要对HDFS Balancer参数进行额外调整。当需要对Balancer参数进行额外调整时,您可以在E-MapReduce控制台的HDFS服务页面,选择配置 > hdfs-site.xml,调整以下两类配置。
客户端配置
参数 | 描述 |
---|---|
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(%)。
来源:https://help.aliyun.com/document_detail/449686.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android 动态加载二维码视图生成快照的示例
![](https://img.aspxhome.com/file/2023/9/84719_0s.png)
Spring P标签的使用详解
详解SpringBoot JPA常用注解的使用方法
![](https://img.aspxhome.com/file/2023/5/72535_0s.png)
Android中使用TagFlowLayout制作动态添加删除标签
![](https://img.aspxhome.com/file/2023/1/93331_0s.gif)
C#中的yield关键字详解
![](https://img.aspxhome.com/file/2023/7/129707_0s.png)
Java基础学习之字符串知识总结
![](https://img.aspxhome.com/file/2023/9/84209_0s.png)
Android 重写ViewGroup 分析onMeasure()和onLayout()方法
SpringBoot服务开启后通过端口访问无反应的解决
![](https://img.aspxhome.com/file/2023/4/91534_0s.jpg)
c# 解决IIS写Excel的权限问题
Android加载Assets目录中Xml布局文件
探讨Java验证码制作(下篇)
![](https://img.aspxhome.com/file/2023/6/69946_0s.png)
C#实现文件上传与下载功能实例
利用C#版OpenCV实现圆心求取实例代码
![](https://img.aspxhome.com/file/2023/3/94663_0s.jpg)
Java8通过Function获取字段名的方法(获取实体类的字段名称)
![](https://img.aspxhome.com/file/2023/7/63277_0s.png)
浅谈Java解释器模式
![](https://img.aspxhome.com/file/2023/8/68708_0s.png)
C#中#define后面只加一个参数的解释
跳一跳自动跳跃C#代码实现
![](https://img.aspxhome.com/file/2023/3/69203_0s.png)
使用SpringBoot开发Restful服务实现增删改查功能
![](https://img.aspxhome.com/file/2023/8/61658_0s.png)
SpringCloud超详细讲解负载均衡组件Ribbon源码
![](https://img.aspxhome.com/file/2023/6/86866_0s.png)