HDFS存入大量元数据的影响
HDFS存入大量小文件,有什么影响?
元数据层面:每个小文件都有一份元数据,其中包括文件路径,文件名,所有者,所属组,权限,创建时间等,这些信息都保存在 Namenode 内存中(大的文件块和小的文件块都占用NameNode150字节的内存)。
所以小文件过多,会占用 Namenode 服务器大量内存,影响 Namenode 性能和使用寿命。
计算层面:默认情况下MR会对每个小文件启用一个MapTask计算,非常影响计算性能。同时也影响磁盘寻址时间。
产生的原因
官方默认的这三个参数配置写入HDFS后会产生小文件:
Name | Default | Description |
---|---|---|
hdfs.rollInterval | 30 | Number of seconds to wait before rolling current file (0 = never roll based on time interval) |
hdfs.rollSize | 1024 | File size to trigger roll, in bytes (0: never roll based on file size) |
hdfs.rollCount | 10 | Number of events written to file before it rolled (0 = never roll based on number of events) |
中文解释:
字段 | 默认值 | 说明 |
---|---|---|
hdfs.rollInterval | 30 | 每隔30秒截断一个文件。设置为0表示不会因为时间间隔截断文件 |
hdfs.rollSize | 1024 | 文件字节数超过1024截断一个文件。设置为0就不因为文件大小截断文件 |
hdfs.rollCount | 10 | 每10个event截断一个文件。设置为0就不因为event数量截断文件 |
解决办法
# 将这几个字段的值设置为0
a1.sinks.k1.hdfs.rollInterval = 0
a1.sinks.k1.hdfs.rollCount = 0
a1.sinks.k1.hdfs.rollSize = 0
扩展 : round 字段
Name | Default | Description |
---|---|---|
hdfs.round | false | Should the timestamp be rounded down (if true, affects all time based escape sequences except %t) |
hdfs.roundValue | 1 | Rounded down to the highest multiple of this (in the unit configured using hdfs.roundUnit ), less than current time. |
hdfs.roundUnit | second | The unit of the round down value - second , minute or hour . |
中文解释:
字段 | 默认值 | 说明 |
---|---|---|
round | false | 时间戳是否应四舍五入(如果为true,则将影响所有基于时间的转义序列,但%t除外) |
roundValue | 1 | 四舍五入到此值的最高倍数(使用hdfs.roundUnit 配置的单位),要小于当前时间 |
roundUnit | second | 时间戳四舍五入的单位 - 秒,分钟,小时 |
举例1
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 1
a1.sinks.k1.hdfs.roundUnit = minute
我们打算对时间戳根据分钟以每1分钟为单位进行四舍五入。
效果1
每分钟生成1个文件块
举例2
# 我们打算对时间戳根据分钟以每10分钟为单位进行四舍五入。
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
效果2
经过15分钟,生成了2个文件块
部分图片引用自:https://blog.csdn.net/weixin_43326165/article/details/101103564