HDFS集中式缓存管理(Centralized Cache Management)


Hadoop从2.3.0版本开始支持HDFS缓存机制,HDFS允许用户将一部分目录或文件缓存在HDFS当中,NameNode会通知拥有对应块的DataNodes将其缓存在DataNode的内存当中

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

用法

集中式缓存对那些频繁访问的的文件是非常有用的,例如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



相关内容