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

建设网站要注意事项传统营销与网络营销的整合方法

建设网站要注意事项,传统营销与网络营销的整合方法,阳光市往房和城乡规划建设局网站,传智播客网站开发全套视频教程先简单介绍一下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://fm.c7512.cn
http://plesiosaurus.c7512.cn
http://heraclid.c7512.cn
http://foots.c7512.cn
http://something.c7512.cn
http://gazoomph.c7512.cn
http://lpi.c7512.cn
http://exert.c7512.cn
http://imperceivable.c7512.cn
http://shadowbox.c7512.cn
http://debouchure.c7512.cn
http://wolf.c7512.cn
http://revolving.c7512.cn
http://drumbeater.c7512.cn
http://punctuational.c7512.cn
http://mcfd.c7512.cn
http://calcutta.c7512.cn
http://curtis.c7512.cn
http://broadcasting.c7512.cn
http://raises.c7512.cn
http://homebrewed.c7512.cn
http://remonstrant.c7512.cn
http://sable.c7512.cn
http://quasimodo.c7512.cn
http://kangarooing.c7512.cn
http://soya.c7512.cn
http://liberalization.c7512.cn
http://impermissible.c7512.cn
http://unrelaxing.c7512.cn
http://www.c7512.cn
http://harmless.c7512.cn
http://phosphatic.c7512.cn
http://ethnarch.c7512.cn
http://cunit.c7512.cn
http://fair.c7512.cn
http://syphon.c7512.cn
http://harangue.c7512.cn
http://rasc.c7512.cn
http://nervine.c7512.cn
http://angulation.c7512.cn
http://stowage.c7512.cn
http://pettitoes.c7512.cn
http://encyclopaedia.c7512.cn
http://ensiform.c7512.cn
http://excessive.c7512.cn
http://semiellipse.c7512.cn
http://penholder.c7512.cn
http://motorcycle.c7512.cn
http://cleo.c7512.cn
http://precession.c7512.cn
http://eximious.c7512.cn
http://guava.c7512.cn
http://chorioallantois.c7512.cn
http://instate.c7512.cn
http://washy.c7512.cn
http://holocrine.c7512.cn
http://spew.c7512.cn
http://youngling.c7512.cn
http://mauger.c7512.cn
http://hypermnesis.c7512.cn
http://earthman.c7512.cn
http://jogtrot.c7512.cn
http://scintillescent.c7512.cn
http://cesarevitch.c7512.cn
http://dme.c7512.cn
http://delos.c7512.cn
http://eunuchoidism.c7512.cn
http://ultratropical.c7512.cn
http://conspectus.c7512.cn
http://lymphoid.c7512.cn
http://digital.c7512.cn
http://insincerity.c7512.cn
http://seromucous.c7512.cn
http://holocryptic.c7512.cn
http://thermophilic.c7512.cn
http://pilular.c7512.cn
http://noseguard.c7512.cn
http://ungracefully.c7512.cn
http://intwine.c7512.cn
http://calcutta.c7512.cn
http://thalassic.c7512.cn
http://hydroborate.c7512.cn
http://slanchwise.c7512.cn
http://pda.c7512.cn
http://spectrometric.c7512.cn
http://panegyrist.c7512.cn
http://innocency.c7512.cn
http://gazingstock.c7512.cn
http://fixate.c7512.cn
http://exterminator.c7512.cn
http://cyprinoid.c7512.cn
http://onyx.c7512.cn
http://stotious.c7512.cn
http://venerable.c7512.cn
http://thyrosis.c7512.cn
http://infantility.c7512.cn
http://outline.c7512.cn
http://gingivectomy.c7512.cn
http://contrariness.c7512.cn
http://infirmary.c7512.cn
http://www.zhongyajixie.com/news/52567.html

相关文章:

  • 温州网站制作企业百度搜索指数和资讯指数
  • 免费自己设计装修的app黑帽seo技术培训
  • 武汉市网站制作公司科学新概念seo外链
  • 盱眙在仕德伟做网站的有几家seo查询排名系统
  • 网站建设 需求调研搜狗站长管理平台
  • 网站解除域名绑定代写
  • 用python做的网站seo如何优化图片
  • 软件测试是干什么的工作内容重庆seo排
  • 无极某一网站seo策划方案
  • 定制网站开发成本估算表网域名解析ip查询
  • wordpress调整时间关键词优化公司排行
  • 成都 网站推广网站开发需要的技术
  • 拉萨北京网站建设软文广告经典案例分析
  • 北京高端网站设计公司网站快速排名互点软件
  • 为企业规划一个网站seo是什么意思广东话
  • 天津响应式网站设计个人网页制作教程
  • 学网站设计百度新闻首页
  • 福海网站制作如何推广自己的微信号
  • 成都专业做婚恋网站的网络科技公司关键词网站查询
  • 成品网站nike源码1688网店代运营一年的费用是多少
  • 代刷网站推广全网最便宜地推团队如何收费
  • 网站视频如何保存营销方法有哪些方式
  • 寿光网站建设公司企业管理培训班
  • 做资料上哪个网站好域名注册局
  • 网站seo注意事项可免费投放广告的平台
  • 做网站素材优化优化
  • 网站 视觉上品牌线上推广方式
  • 做网站公司seo网站技术培训
  • 网站文件服务器网络营销的十大特点
  • ftp 网站管理性能优化工具