Hadoop从2.3.0版本号開始支持HDFS缓存机制,HDFS同意用户将一部分文件夹或文件缓存在HDFS其中。NameNode会通知拥有相应块的DataNodes将其缓存在DataNode的内存其中

集中式缓存管理有着很多显著的优势:

  1. 防止那些被频繁使用的数据从内存中清除
  2. 由于DataNode的缓存由NameNode来管理,applications在做任务安排时能够查询这个缓存的列表,使用一个被缓存的块副本能够提高读性能
  3. 当块被DataNode缓存之后。client能够使用一个新的、高效的、zero-copy的读API。由于缓存中的数据已经被计算过checksum,当使用新API时,client基本上是零开销的
  4. 能够提高集群的内存利用率。当使用操作系统的缓存时,对一个块的反复读会导致全部的副本都会被放到缓冲区其中,当使用集中式缓存时。用户能够指定n个副本中的m个才会被缓存,能够节约n-m的内存

使用方法

集中式缓存对那些频繁訪问的的文件是很实用的。比如hive中常常被使用的fact表就很适合缓存;还有一方面,缓存一年的查询结果可能没那么实用了。由于这个结果可能仅仅会被查看一次

也有助于提高混合类型作业的SLA性能。把高优先级的数据缓存起来能够确保它不会与低优先级的数据竞争磁盘IO


使用:

[hadoop@master hadoop]$ hdfs cacheadmin -addPool admin				【加入一个pool】
Successfully added cache pool admin.
[hadoop@master hadoop]$ hdfs cacheadmin -listPools							【查看pool列表】
Found 1 result.
NAME   OWNER   GROUP   MODE            LIMIT  MAXTTL
admin  hadoop  hadoop  rwxr-xr-x   unlimited   never
[hadoop@master hadoop]$ hdfs cacheadmin -addDirective -path /input -pool admin 【将一个文件夹加入pool】
Added cache directive 1
[hadoop@master hadoop]$ hdfs cacheadmin -listDirectives						【查看已缓存的数据】
Found 2 entries
 ID POOL    REPL EXPIRY  PATH      
  1 admin      1 never   /input    
  2 test       1 never   /output/0
[hadoop@master hadoop]$ hdfs cacheadmin -removeDirective 1				【按id清除缓存】
Removed cached directive 1
[hadoop@master hadoop]$ hdfs cacheadmin -listDirectives						
Found 1 entry
 ID POOL   REPL EXPIRY  PATH      
  2 test      1 never   /output/0 
[hadoop@master hadoop]$ hdfs cacheadmin -removeDirectives -path /output/0	【按path清除缓存】
Removed cache directive 2
Removed every cache directive with path /output/0
[hadoop@master hadoop]$ hdfs cacheadmin -listDirectives
Found 0 entries



posted on 2017-05-24 09:21  lxjshuju  阅读(311)  评论(0编辑  收藏  举报