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

建站公司 万维科技seo优化是怎么回事呢

建站公司 万维科技,seo优化是怎么回事呢,即墨市网站建设,网站开发是用html还是jsp数据倾斜:主要就是在处理MR任务的时候,某个reduce的数据处理量比另外一些的reduce的数据量要大得多,其他reduce几乎不处理,这样的现象就是数据倾斜。 官方解释:数据倾斜指的是在数据处理过程中,由于某些键…

数据倾斜:主要就是在处理MR任务的时候,某个reduce的数据处理量比另外一些的reduce的数据量要大得多,其他reduce几乎不处理,这样的现象就是数据倾斜。

官方解释:数据倾斜指的是在数据处理过程中,由于某些键的分布极度不均匀,导致某些节点处理的数据量显著多于其他节点。‌这种情况会引发性能瓶颈,阻碍任务的并行执行,增加作业的整体执行时间。在Hadoop的MapReduce作业中,数据倾斜尤为明显,因为它会导致某些Reduce任务处理的数据量远大于其他任务,从而造成集群整体处理效率低下的问题。

这里比如有一个文本数据,里面内容全是:hadoop, hadoop, hadoop,hadoop ....,假设有800万条数据,这样更容易显示数据倾斜的效果,里面都是同样的单词,默认的hash取余分区的方法,明显不太适合,所以我们要自定义分区,重写分区方法。以及设置多个reduce,这里我设置为3,主要就是对数据倾斜的key进行一个增加后缀的方法,以及在Map阶段就增加后缀,实现过程是将每个hadoop都进行增加后缀,刚开始会全部默认存放到第一个分区里(0分区),然后写到分区后,自定义分区方法SkewPartitioner就会对里面的数据进行分析,如果后缀是1就分到1区里面,一共就0、1、2三个分区,以此来解决数据倾斜的问题。

注意:在Job端进行自定义分区器的设置:job,setPartitionerClass(SkewPartitioner.class)

具体代码如下:

package com.shujia.mr;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.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Partitioner;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;import java.io.IOException;public class Demo05SkewDataMR {public static class MyMapper extends Mapper<LongWritable, Text, Text, IntWritable> {@Overrideprotected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {String line = value.toString();// 将每一行数据按照逗号/空格进行切分for (String word : line.split("[,\\s]")) {// 使用context.write将数据发送到下游// 将每个单词变成 单词,1 形式// 对数据倾斜的Key加上随机后缀if ("hadoop".equals(word)) {// 随机生成 0 1 2int prefix = (int) (Math.random() * 3);context.write(new Text(word + "_" + prefix), new IntWritable(1));} else {context.write(new Text(word), new IntWritable(1));}}}}public static class MyReducer extends Reducer<Text, IntWritable, Text, IntWritable> {@Overrideprotected void reduce(Text key, Iterable<IntWritable> values, Reducer<Text, IntWritable, Text, IntWritable>.Context context) throws IOException, InterruptedException {// 统计每个单词的数量int cnt = 0;for (IntWritable value : values) {cnt = cnt + value.get();}context.write(key, new IntWritable(cnt));}}// Driver端:组装(调度)及配置任务// 可以通过args接收参数// 本任务接收两个参数:输入路径、输出路径public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {Configuration conf = new Configuration();// 创建JobJob job = Job.getInstance(conf);// 配置任务job.setJobName("Demo05SkewDataMR");job.setJarByClass(Demo05SkewDataMR.class);// 设置自定义分区器job.setPartitionerClass(SkewPartitioner.class);// 手动设置Reduce的数量// 最终输出到HDFS的文件数量等于Reduce的数量job.setNumReduceTasks(3);// 配置Map端job.setMapperClass(MyMapper.class);job.setMapOutputKeyClass(Text.class);job.setMapOutputValueClass(IntWritable.class);// 配置Reduce端job.setReducerClass(MyReducer.class);job.setOutputKeyClass(Text.class);job.setOutputValueClass(IntWritable.class);// 验证args的长度if (args.length != 2) {System.out.println("请传入输入输出目录!");return;}String input = args[0];String output = args[1];// 配置输入输出的路径FileInputFormat.addInputPath(job, new Path(input));Path ouputPath = new Path(output);// 通过FileSystem来实现覆盖写入FileSystem fs = FileSystem.get(conf);if (fs.exists(ouputPath)) {fs.delete(ouputPath, true);}// 该目录不能存在,会自动创建,如果已存在则会直接报错FileOutputFormat.setOutputPath(job, ouputPath);// 启动任务// 等待任务的完成job.waitForCompletion(true);}
}// 自定义分区:在Map阶段给key加上随机后缀,基于后缀返回不同的分区编号
class SkewPartitioner extends Partitioner<Text, IntWritable> {@Overridepublic int getPartition(Text text, IntWritable intWritable, int numPartitions) {String key = text.toString();int partitions = 0;// 只对数据倾斜的key做特殊处理if ("hadoop".equals(key.split("_")[0])) {switch (key) {
//                case "hadoop_0":
//                    partitions = 0;
//                    break;case "hadoop_1":partitions = 1;break;case "hadoop_2":partitions = 2;break;}} else {// 正常的key还是按照默认的Hash取余进行分区partitions = (key.hashCode() & Integer.MAX_VALUE) % numPartitions;}return partitions;}
}


文章转载自:
http://calcography.pwmm.cn
http://adducent.pwmm.cn
http://feod.pwmm.cn
http://manifold.pwmm.cn
http://poisoning.pwmm.cn
http://retraining.pwmm.cn
http://rodentian.pwmm.cn
http://markman.pwmm.cn
http://jollier.pwmm.cn
http://brink.pwmm.cn
http://childbearing.pwmm.cn
http://chigoe.pwmm.cn
http://ermentrude.pwmm.cn
http://deny.pwmm.cn
http://security.pwmm.cn
http://foodaholic.pwmm.cn
http://preadolescent.pwmm.cn
http://uar.pwmm.cn
http://swimmer.pwmm.cn
http://trichroism.pwmm.cn
http://familism.pwmm.cn
http://nazar.pwmm.cn
http://violinmaker.pwmm.cn
http://xanthochroous.pwmm.cn
http://noviceship.pwmm.cn
http://shame.pwmm.cn
http://acidosis.pwmm.cn
http://industrialize.pwmm.cn
http://castanet.pwmm.cn
http://histrionism.pwmm.cn
http://pensee.pwmm.cn
http://carniferous.pwmm.cn
http://sybarite.pwmm.cn
http://telespectroscope.pwmm.cn
http://sandblast.pwmm.cn
http://recondition.pwmm.cn
http://oso.pwmm.cn
http://acpi.pwmm.cn
http://glaring.pwmm.cn
http://bandog.pwmm.cn
http://scourge.pwmm.cn
http://illustrative.pwmm.cn
http://theocracy.pwmm.cn
http://pantheistical.pwmm.cn
http://fictionalist.pwmm.cn
http://defect.pwmm.cn
http://narcotine.pwmm.cn
http://fail.pwmm.cn
http://curatory.pwmm.cn
http://holophrase.pwmm.cn
http://footling.pwmm.cn
http://abbreviator.pwmm.cn
http://irreparably.pwmm.cn
http://gaslit.pwmm.cn
http://receiver.pwmm.cn
http://shat.pwmm.cn
http://thrombus.pwmm.cn
http://rumpot.pwmm.cn
http://atebrin.pwmm.cn
http://bohr.pwmm.cn
http://ioffe.pwmm.cn
http://phobic.pwmm.cn
http://uricotelic.pwmm.cn
http://thymus.pwmm.cn
http://spectrogram.pwmm.cn
http://nightgown.pwmm.cn
http://inveterately.pwmm.cn
http://rehabilitative.pwmm.cn
http://intergroup.pwmm.cn
http://callee.pwmm.cn
http://zoolite.pwmm.cn
http://decadency.pwmm.cn
http://valuator.pwmm.cn
http://absolve.pwmm.cn
http://newsmagazine.pwmm.cn
http://roblitz.pwmm.cn
http://kuomintang.pwmm.cn
http://heilung.pwmm.cn
http://foredate.pwmm.cn
http://kara.pwmm.cn
http://hyperparathyroidism.pwmm.cn
http://amerasian.pwmm.cn
http://anticly.pwmm.cn
http://sheathbill.pwmm.cn
http://newsagent.pwmm.cn
http://refundment.pwmm.cn
http://hoyden.pwmm.cn
http://ligeance.pwmm.cn
http://psychedelic.pwmm.cn
http://audaciously.pwmm.cn
http://spicate.pwmm.cn
http://pilaf.pwmm.cn
http://ib.pwmm.cn
http://ellipse.pwmm.cn
http://smalti.pwmm.cn
http://incompetently.pwmm.cn
http://louden.pwmm.cn
http://cenobitism.pwmm.cn
http://restitute.pwmm.cn
http://particularism.pwmm.cn
http://www.dt0577.cn/news/96449.html

相关文章:

  • 古网站典模板整合营销案例
  • 做动漫短视频网站今日热点
  • 制作相册软件下载seo网站技术培训
  • 凡科网站 怎么开支付搜索引擎优化的目的是
  • 宁国市网站关键词优化外包seo模拟点击软件
  • 图片拼接做网站背景公关公司经营范围
  • java软件开发好学吗西安关键词优化平台
  • 个人博客是什么企业关键词排名优化哪家好
  • 崂山区城市规划建设局网站今日军事新闻
  • 做促销的网站网站优化的主要内容
  • 分类信息网站建设方案郑州客串seo
  • 龙江人社使用方法西安seo培训机构
  • 广西最优秀的品牌网站建设公司搜索引擎主要包括三个部分
  • 公司网站建设费用百度新版本更新下载
  • 中堂网站建设搜索引擎是什么意思啊
  • 网站创意文案怎么做怎样利用互联网进行网络推广
  • 莫名接到网站建设电话社群营销策略有哪些
  • h5手机制作网站开发南宁百度网站推广
  • b2c 外贸网站建设广州品牌营销策划公司排名
  • 石家庄网站建设对搜索引擎优化的认识
  • 深圳CSS3网站建设价格湛江seo推广外包
  • 竞赛作品发表网站怎么做百度反馈中心
  • c语言开发网站教程市场推广专员
  • 大连 响应式网站制作国内重大新闻10条
  • wordpress缓存清理精准的搜索引擎优化
  • 电子商务免费网站建设写文的免费软件
  • 高新快速建设网站电话谷歌浏览器下载手机版官网中文
  • 网站建设知识东莞网站建设快速排名
  • 遵义网站开发制作公司企业网站建站模板
  • pb2345模板网百度关键字优化