HDFS block size Vs actual file size

限于喜欢 提交于 2019-11-28 04:46:11

The best way to know is to try it, see my results bellow.

But before trying, my guess is that even if you can only allocate 80 full blocks in your configuration, you can allocate more than 80 non-empty files. This is because I think HDFS does not use a full block each time you allocate a non-empty file. Said in another way, HDFS blocks are not a storage allocation unit, but a replication unit. I think the storage allocation unit of HDFS is the unit of the underlying filesystem (if you use ext4 with a block size of 4 KB and you create a 1 KB file in a cluster with replication factor of 3, you consume 3 times 4 KB = 12 KB of hard disk space).

Enough guessing and thinking, let's try it. My lab configuration is as follow:

  • hadoop version 1.0.4
  • 4 data nodes, each with a little less than 5.0G of available space, ext4 block size of 4K
  • block size of 64 MB, default replication of 1

After starting HDFS, I have the following NameNode summary:

  • 1 files and directories, 0 blocks = 1 total
  • DFS Used: 112 KB
  • DFS Remaining: 19.82 GB

Then I do the following commands:

  • hadoop fs -mkdir /test
  • for f in $(seq 1 10); do hadoop fs -copyFromLocal ./1K_file /test/$f; done

With these results:

  • 12 files and directories, 10 blocks = 22 total
  • DFS Used: 122.15 KB
  • DFS Remaining: 19.82 GB

So the 10 files did not consume 10 times 64 MB (no modification of "DFS Remaining").

HDFS use only what it needs on the local file system. So block, representing 12 MB file will take 12 MB when stored (on each datanode where it is stored). So you will be able to have as much blocks as you need assuming you have space for the data.

Bao Bui

The 'available blocks' will stay at 79 (see this question). Anyway I don't think HDFS decides whether it has enough free space in terms of the 'available blocks'.

HDFS block size and Ext block size are not the same thing. The easiest way to put it is HDFS block size is "replication" block size, not "storage" block size.

For storage it will use the same amount of space as your local file system does,because that's what it uses, but it will copy not less, than one block between nodes, even if only 1KB is used

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!