Java 是否可以在一个节点上运行多个映射程序

Java 是否可以在一个节点上运行多个映射程序,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,我有KMeans的代码,我的任务是计算加速比,我在uni集群中不同数量的节点上运行它。但是是否可以更改映射器和/或还原器的数量,以便在单个节点上运行时检查加速比的变化 在谷歌搜索时,我发现通过使用conf.setNumReduceTasks(2)我可以更改减速器的数量。但我的产出没有任何变化。(我的输出是以毫秒为单位的时间) 我使用的代码来自github: 虽然我根据自己的需求做了一些更改,但主要功能是相同的 以下是主函数的外观: public static void main(Stri

我有KMeans的代码,我的任务是计算加速比,我在uni集群中不同数量的节点上运行它。但是是否可以更改映射器和/或还原器的数量,以便在单个节点上运行时检查加速比的变化

在谷歌搜索时,我发现通过使用
conf.setNumReduceTasks(2)我可以更改减速器的数量。但我的产出没有任何变化。(我的输出是以毫秒为单位的时间)

我使用的代码来自github: 虽然我根据自己的需求做了一些更改,但主要功能是相同的

以下是主函数的外观:

    public static void main(String[] args) throws Exception {
    long startTime = System.currentTimeMillis();
    IN = args[0];
    OUT = args[1];
    String input = IN;
    String output = OUT + System.nanoTime();
    String again_input = output;
    int iteration = 0;
    boolean isdone = false;
    while (isdone == false) {
        JobConf conf = new JobConf(KMeans.class);
        if (iteration == 0) {
            Path hdfsPath = new Path(input + CENTROID_FILE_NAME);
            DistributedCache.addCacheFile(hdfsPath.toUri(), conf);
        } else {
            Path hdfsPath = new Path(again_input + OUTPUT_FILE_NAME);
            DistributedCache.addCacheFile(hdfsPath.toUri(), conf);
        }
        conf.setJobName(JOB_NAME);
        //conf.setNumReduceTasks(2);
        conf.setMapOutputKeyClass(DoubleWritable.class);
        conf.setMapOutputValueClass(DoubleWritable.class);
        conf.setOutputKeyClass(DoubleWritable.class);
        conf.setOutputValueClass(Text.class);
        conf.setMapperClass(Map.class);
        conf.setNumMapTasks(4);
        conf.setReducerClass(Reduce.class);
        conf.setInputFormat(TextInputFormat.class);
        conf.setOutputFormat(TextOutputFormat.class);
        FileInputFormat.setInputPaths(conf, new Path(input + DATA_FILE_NAME));
        FileOutputFormat.setOutputPath(conf, new Path(output));
        JobClient.runJob(conf);
        Path ofile = new Path(output + OUTPUT_FILE_NAME);   

        Configuration configuration = new Configuration();
        FileSystem fs = FileSystem.get(new URI("hdfs://127.0.0.1:9000"), configuration);
        Path filePath = new Path(output + OUTPUT_FILE_NAME);
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(filePath)));
        List<Double> centers_next = new ArrayList<Double>();
        String line = br.readLine();
        while (line != null) {
            String[] sp = line.split("\t| ");
            double c = Double.parseDouble(sp[0]);
            centers_next.add(c);
            line = br.readLine();
        }
        br.close();
        String prev;
        if (iteration == 0) {
            prev = input + CENTROID_FILE_NAME;
        } else {
            prev = again_input + OUTPUT_FILE_NAME;
        }
        Path prevfile = new Path(prev);
        FileSystem fs1 = FileSystem.get(new URI("hdfs://127.0.0.1:9000"), configuration);
        BufferedReader br1 = new BufferedReader(new InputStreamReader(fs1.open(prevfile)));
        List<Double> centers_prev = new ArrayList<Double>();
        String l = br1.readLine();
        while (l != null) {
            String[] sp1 = l.split(SPLITTER);
            double d = Double.parseDouble(sp1[0]);
            centers_prev.add(d);
            l = br1.readLine();
        }
        br1.close();
        Collections.sort(centers_next);
        Collections.sort(centers_prev);
        Iterator<Double> it = centers_prev.iterator();
        for (double d : centers_next) {
            double temp = it.next();
            if (Math.abs(temp - d) <= 0.1) {
                isdone = true;
            } else {
                isdone = false;
                break;
            }
        }
        ++iteration;
        again_input = output;
        output = OUT + System.nanoTime();
    }
    long endTime   = System.currentTimeMillis();
    long totalTime = endTime - startTime;
    System.out.println(totalTime);
}
publicstaticvoidmain(字符串[]args)引发异常{
long startTime=System.currentTimeMillis();
IN=args[0];
OUT=args[1];
字符串输入=IN;
字符串输出=OUT+System.nanoTime();
字符串再次\u输入=输出;
int迭代=0;
布尔isdone=false;
while(isdone==false){
JobConf conf=newjobconf(KMeans.class);
如果(迭代==0){
路径hdfsPath=新路径(输入+质心文件名);
DistributedCache.addCacheFile(hdfsPath.toUri(),conf);
}否则{
路径hdfsPath=新路径(同样是输入+输出文件名);
DistributedCache.addCacheFile(hdfsPath.toUri(),conf);
}
conf.setJobName(作业名称);
//conf.setNumReduceTasks(2);
conf.setMapOutputKeyClass(DoubleWritable.class);
conf.setMapOutputValueClass(DoubleWritable.class);
conf.setOutputKeyClass(DoubleWritable.class);
conf.setOutputValueClass(Text.class);
conf.setMapperClass(Map.class);
conf.setnummatasks(4);
conf.setReducerClass(Reduce.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
setInputPath(conf,新路径(输入+数据文件名));
setOutputPath(conf,新路径(output));
runJob(conf);
文件路径=新路径(输出+输出文件名);
配置=新配置();
FileSystem fs=FileSystem.get(新URI(“hdfs://127.0.0.1:9000配置);
路径文件路径=新路径(输出+输出文件名);
BufferedReader br=新的BufferedReader(新的InputStreamReader(fs.open(filePath));
List centers_next=new ArrayList();
String line=br.readLine();
while(行!=null){
字符串[]sp=line.split(“\t |”);
double c=double.parseDouble(sp[0]);
下一步,添加(c);
line=br.readLine();
}
br.close();
字符串prev;
如果(迭代==0){
prev=输入+质心文件名;
}否则{
prev=再次\u输入+输出\u文件\u名称;
}
路径prevfile=新路径(prev);
FileSystem fs1=FileSystem.get(新URI(“hdfs://127.0.0.1:9000配置);
BufferedReader br1=新的BufferedReader(新的InputStreamReader(fs1.open(prevfile));
List centers_prev=new ArrayList();
字符串l=br1.readLine();
while(l!=null){
字符串[]sp1=l.split(拆分器);
double d=double.parseDouble(sp1[0]);
上一次添加的中心(d);
l=br1.readLine();
}
br1.close();
Collections.sort(centers\u next);
集合。排序(中心和上一个);
迭代器it=centers_prev.Iterator();
用于(双d:中心\U下一个){
double temp=it.next();

if(Math.abs(temp-d)给定作业的映射数通常由输入文件中的输入拆分数驱动,而不是由setNumMapTasks()驱动或mapred.map.tasks参数。为每个输入拆分生成映射任务。mapred.map.tasks参数只是映射数量的InputFormat提示。可以使用setNumMapTasks()手动增加映射任务的数量,它可以用于增加映射任务的数量,但不会将该数量设置为低于Hadoop通过拆分输入数据确定的数量

Apache提供了更多信息

有多少张地图?

贴图的数量通常由输入的总大小决定,即输入文件的块总数

贴图的正确并行级别似乎是每个节点10-100个贴图左右,尽管对于每个cpu光照贴图任务,已将其设置为300个贴图。任务设置需要一段时间,因此最好至少花一分钟执行贴图


因此,如果您希望输入10TB的数据,并且块大小为128MB,那么最终将得到82000个映射,除非
Configuration.set(MRJobConfig.NUM_-maps,int)
(这仅为框架提供提示)用于将其设置得更高。

在从中读取文件之前,您可能应该等待作业完成HDFS@Ahsan:您是否正在寻找其中的性能调整部分,这就是为什么您希望尝试设置映射器的数量和reducers@ramprasad-是的,正如我说的,我在计算加速比。我通过增加no的数量得到了加速比des.现在我想通过增加映射器和还原器的数量在单节点上计算它。通常,单节点测试的可用资源较少。使用相同数据量和可用资源的多节点测试更适合计算速度。建议进行优化的多节点测试(在本例中,映射器和还原器的数量)逐个计算性能。此外,还有几个其他因素(如排序内存等)这将/可以提高map reduce程序的性能。还可以看看我的回答中添加的一般提示
地图的正确并行级别似乎是每个节点大约10-100个地图
,这高度依赖于您的