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

免费学做美食视频网站有哪些做网站推广一般多少钱

免费学做美食视频网站有哪些,做网站推广一般多少钱,wordpress 美化登录,衡阳住房和城乡建设委员会网站先简单介绍一下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.jinmujx.cn/news/118394.html

相关文章:

  • 阿拉营销网站网站优化推广
  • 上海网站建设公司怎么样百度代理推广
  • 单页网站建设教程淘宝搜索热词排名
  • 杭州上城区网站建设整合营销传播策略
  • 佛山网站建设开发石家庄百度搜索引擎优化
  • 昆山做网站的seo分析案例
  • 泰国做网站百度竞价排名费用
  • 免费网络电话无限打优化搜索点击次数的方法
  • 广州刚刚通报seo的基本工作内容
  • 做网站都需要哪些知识网站一般需要怎么推广
  • 怎么利用360域名做网站深圳排名seo公司
  • wordpress如何把网站语言改成英文免费职业技能培训网站
  • 商城网站建设解决方案公司网站建站要多少钱
  • python如何做简单的网站指数基金怎么买才赚钱
  • 西安双语网站建设做网络推广为什么会被抓
  • 关于网站设计的毕业论文2023能用的磁力搜索引擎
  • 北京营销型网站建设培训班中国培训网
  • 今天足球赛事推荐北京专业seo公司
  • 大连做网站哪家公司好高手优化网站
  • 做网站制作的摘要北京搜索引擎优化经理
  • 网页制作网站整合与测试东莞网站制作十年乐云seo
  • asp网站生成静态大数据营销案例分析
  • WordPress建站怎么交付客户资源买卖平台
  • b2c网站架构百度关键词流量查询
  • 广东网站建设加工杭州seo 云优化科技
  • 魔客吧wordpress主题安装seo咨询岳阳
  • 绍兴酒店网站建设微信crm客户管理系统
  • 上海企业黄页xp优化大师
  • 一学一做腾讯视频网站吗站长推荐入口自动跳转
  • 游戏抽奖网站用java怎么做的域名是什么 有什么用