当前位置: 首页 > news >正文

网页升级访问中每天正常更新中seo哪家公司好

网页升级访问中每天正常更新中,seo哪家公司好,如何自己设计logo图标,旅游网站建设的建议先简单介绍一下partitioner 和 combiner Partitioner类 用于在Map端对key进行分区 默认使用的是HashPartitioner 获取key的哈希值使用key的哈希值对Reduce任务数求模决定每条记录应该送到哪个Reducer处理自定义Partitioner 继承抽象类Partitioner,重写getPartiti…

先简单介绍一下partitioner 和 combiner 

Partitioner类

  • 用于在Map端对key进行分区
    • 默认使用的是HashPartitioner
      • 获取key的哈希值
      • 使用key的哈希值对Reduce任务数求模
    • 决定每条记录应该送到哪个Reducer处理
  • 自定义Partitioner
    • 继承抽象类Partitioner,重写getPartition方法
    • job.setPartitionerClass(MyPartitioner.class)

Combiner类

  • Combiner相当于本地化的Reduce操作
    • 在shuffle之前进行本地聚合
    • 用于性能优化,可选项
    • 输入和输出类型一致
  • Reducer可以被用作Combiner的条件
    • 符合交换律和结合律
  • 实现Combiner
    • job.setCombinerClass(WCReducer.class)

我们进入案例来看这两个知识点

一 案例需求

一个存放电话号码的文本,我们需要136 137,138 139和其它开头的号码分开存放统计其每个数字开头的号码个数

效果

 二 PhoneMapper 类

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;import java.io.IOException;public class PhoneMapper extends Mapper<LongWritable, Text,Text, IntWritable> {@Overrideprotected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {String phone = value.toString();Text text = new Text(phone);IntWritable intWritable = new IntWritable(1);context.write(text,intWritable);}
}

三 PhoneReducer 类

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class PhoneReducer extends Reducer<Text, IntWritable,Text,IntWritable> {@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int count = 0;for (IntWritable intWritable : values){count += intWritable.get();}context.write(key, new IntWritable(count));}
}

四 PhonePartitioner 类

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;public class PhonePartitioner extends Partitioner<Text, IntWritable> {@Overridepublic int getPartition(Text text, IntWritable intWritable, int i) {//136,137   138,139     其它号码放一起if("136".equals(text.toString().substring(0,3)) || "137".equals(text.toString().substring(0,3))){return 0;}else if ("138".equals(text.toString().substring(0,3)) || "139".equals(text.toString().substring(0,3))){return 1;}else {return 2;}}
}

五 PhoneCombiner 类

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;import java.io.IOException;public class PhoneCombiner extends Reducer<Text, IntWritable,Text,IntWritable> {@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {int count = 0;for(IntWritable intWritable : values){count += intWritable.get();}context.write(new Text(key.toString().substring(0,3)), new IntWritable(count));}
}

六 PhoneDriver 类

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class PhoneDriver {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {Configuration conf = new Configuration();Job job = Job.getInstance(conf);job.setJarByClass(PhoneDriver.class);job.setMapperClass(PhoneMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);job.setCombinerClass(PhoneCombiner.class);job.setPartitionerClass(PhonePartitioner.class);job.setNumReduceTasks(3);job.setReducerClass(PhoneReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);Path inPath = new Path("in/demo4/phone.csv");FileInputFormat.setInputPaths(job, inPath);Path outPath = new Path("out/out6");FileSystem fs = FileSystem.get(outPath.toUri(),conf);if (fs.exists(outPath)){fs.delete(outPath, true);}FileOutputFormat.setOutputPath(job, outPath);job.waitForCompletion(true);}
}

七 小结

该案例新知识点在于分区(partition)和结合(combine)

这次代码的流程是 

driver——》mapper——》partitioner——》combiner——》reducer

map 每处理一条数据都经过一次 partitioner 分区然后存到环形缓存区中去,然后map再去处理下一条数据以此反复直至所有数据处理完成

combine 则是将环形缓存区溢出的缓存文件合并,并提前进行一次排序和计算(对每个溢出文件计算后再合并)最后将一个大的文件给到 reducer,这样大大减少了 reducer 的计算负担

http://www.ds6.com.cn/news/83477.html

相关文章:

  • 电影网站模板源代码常州谷歌推广
  • asp.net 旅游网站开发营销
  • 如何做网站优化如何创建个人网站免费
  • 哪里有做阿里网站的哈尔滨网站优化
  • 资源网站建设常州seo关键词排名
  • 做h5场景的网站推广普通话手抄报一等奖
  • 做网站哪个服务器好网页设计与制作书籍
  • 免费网站制作视频教程网站一键生成
  • 建设一个能看视频的网站高端企业建站公司
  • 泰安做网站公司网络营销策划名词解释
  • 泊头公司做网站百度推广开户费用多少
  • 专业的设计网站有哪些竞价推广价格
  • asp.net网站开发视频教程营销策划公司
  • 网站建设去哪谷歌google官方网站
  • 怎么创建手机网站网站生成器
  • 自建网站 做自定义导航平台推广方式
  • 网站建设招聘内容百度关键词优化推广
  • 建设网站考证seo自动点击排名
  • 网站建设的过程有哪些哪里可以免费推广广告
  • dedecms婚纱摄影网站模板代运营一般收费
  • wordpress分类设置seo引擎搜索网站
  • 网站开发完要过审是啥意思解释seo网站推广
  • 微餐饮网站建设用途广州seo实战培训
  • 有经验的企业网站建设做外贸用什么软件找客户
  • wordpress 摘要 格式百度seo规则
  • soho设计网站百度seo排名软
  • 郑州短视频拍摄制作seo网站优化推广怎么样
  • 丰城市建设局网站怎么做线上推广
  • 重庆企业网站制作百度怎么打广告在首页
  • 电子商务网站建设的核心是什么汕头seo建站