zoukankan      html  css  js  c++  java
  • Hadoop 之 分布式缓存的原理和方法——DistributedCache

    1.什么时Hadoop的分布式缓存

    答:在执行MapReduce时,可能Mapper之间需要共享一些信息,如果信息量不大,可以将其从HDFS中加载到内存中,这就是Hadoop分布式缓存机制。

    2.如何使用缓存机制

    答:在main方法中加载共享文件的HDFS路径,路径可以是目录也可以是文件。可以在路径末尾阶段追加 '#' +别名,在map阶段可以使用该别名。

          这时执行第一步的代码:

    String cache = "hdfs://10.105.xx.xxxx:8020/cache/file";  //目录或者文件
    cache += "#myfile";  //file是文件的别名
    job.addCacheFile(new Path(cache).toUri(), conf);  //添加到job设置

    第二步,在Mapper类或者Reducec的setup方法中,用输入流获取分布式缓存文件。

    protected void setup(Context context) throws IOException,InterruptedEXception {
              FileReader reader = new FileReader("myfile");
              BuffereReader br = new BufferedReader(reader);
    }
  • 相关阅读:
    POJ1700 Crossing River
    Glad to see you! CodeForces
    Summer sell-off CodeForces
    atcoderI
    Selling Souvenirs CodeForces
    Array Division CodeForces
    Tea Party CodeForces
    Atcoder F
    Atcoder E
    Average Sleep Time CodeForces
  • 原文地址:https://www.cnblogs.com/twodoge/p/9762104.html
Copyright © 2011-2022 走看看