{"id":213,"date":"2020-03-13T17:41:14","date_gmt":"2020-03-13T09:41:14","guid":{"rendered":"https:\/\/blog.frost-s.tk\/?p=213"},"modified":"2020-03-13T18:23:14","modified_gmt":"2020-03-13T10:23:14","slug":"%e7%ac%ac%e4%b8%80%e7%ab%a0-%e5%88%86%e5%b8%83%e5%bc%8f%e8%ae%a1%e7%ae%97%e6%a1%86%e6%9e%b6%e4%b8%8e%e8%b5%84%e6%ba%90%e8%b0%83%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/blog.frost-s.com\/index.php\/2020\/03\/13\/%e7%ac%ac%e4%b8%80%e7%ab%a0-%e5%88%86%e5%b8%83%e5%bc%8f%e8%ae%a1%e7%ae%97%e6%a1%86%e6%9e%b6%e4%b8%8e%e8%b5%84%e6%ba%90%e8%b0%83%e5%ba%a6\/","title":{"rendered":"\u7b2c\u4e00\u7ae0  \u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6\u4e0e\u8d44\u6e90\u8c03\u5ea6"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><a>1.1&nbsp;&nbsp;\n\u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6<\/a><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><a>1.1.1&nbsp;&nbsp;\n\u7f16\u7a0b\u6a21\u578b<\/a><\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><a>1.&nbsp;&nbsp;&nbsp;&nbsp;\ninputformat<\/a><\/h5>\n\n\n\n<p>\u5728MapReduce\u7a0b\u5e8f\u7684\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5f80\u5f80\u9700\u8981\u7528\u5230FileInputFormat\u4e0eTextInputFormat\uff0c\u6211\u4eec\u4f1a\u53d1\u73b0TextInputFormat\u8fd9\u4e2a\u7c7b\u7ee7\u627f\u81eaFileInputFormat\uff0cFileInputFormat\u8fd9\u4e2a\u7c7b\u7ee7\u627f\u81eaInputFormat\uff0cInputFormat\u8fd9\u4e2a\u7c7b\u4f1a\u5c06\u6587\u4ef6file\u6309\u7167\u903b\u8f91\u8fdb\u884c\u5212\u5206\uff0c\u5212\u5206\u6210\u7684\u6bcf\u4e00\u4e2asplit\u5207\u7247\u5c06\u4f1a\u88ab\u5206\u914d\u7ed9\u4e00\u4e2aMapper\u4efb\u52a1,\u6587\u4ef6\u5148\u88ab\u5207\u5206\u6210split\u5757\uff0c\u800c\u540e\u6bcf\u4e00\u4e2asplit\u5207\u7247\u5bf9\u5e94\u4e00\u4e2aMapper\u4efb\u52a1<\/p>\n\n\n\n<p>FileInputFormat\u7684\u5212\u5206\u673a\u5236:<\/p>\n\n\n\n<p>A. \u7b80\u5355\u5730\u6309\u7167\u6587\u4ef6\u7684\u5185\u5bb9\u957f\u5ea6\u8fdb\u884c\u5207\u7247<\/p>\n\n\n\n<p>B. \u5207\u7247\u5927\u5c0f\uff0c\u9ed8\u8ba4\u7b49\u4e8e block \u5927\u5c0f<\/p>\n\n\n\n<p>C. \u5207\u7247\u65f6\u4e0d\u8003\u8651\u6570\u636e\u96c6\u6574\u4f53\uff0c\u800c\u662f\u9010\u4e2a\u9488\u5bf9\u6bcf\u4e00\u4e2a\u6587\u4ef6\u5355\u72ec\u5207\u7247<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c split\nsize =block size,\u5728 hadoop 2.x \u4e2d\u4e3a 128M\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f:bytesRemaining\/splitSize\n&gt; 1.1 \u4e0d\u6ee1\u8db3\u7684\u8bdd\uff0c\u90a3\u4e48\u6700\u540e\u6240\u6709\u5269\u4f59\u7684\u4f1a\u4f5c\u4e3a\u4e00\u4e2a\u5207\u7247\u3002\u4ece\u800c\u4e0d\u4f1a\u5f62\u6210\u4f8b\u5982 129M \u6587\u4ef6\u89c4\u5212\u6210\u4e24\u4e2a\u5207\u7247\u7684\u5c40\u9762\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><a>2.&nbsp;&nbsp;&nbsp;&nbsp;\nMaTask<\/a>\u7aef\u7684\u5de5\u4f5c\u673a\u5236<\/h5>\n\n\n\n<p>input File \u901a\u8fc7 split \u88ab\u903b\u8f91\u5207\u5206\u4e3a\u591a\u4e2a split \u6587\u4ef6\uff0c\u901a\u8fc7 Record \u6309\u884c\u8bfb\u53d6\u5185\u5bb9\u7ed9 map\uff08\u7528\u6237\u81ea\u5df1\u5b9e\u73b0\u7684\uff09\u8fdb\u884c\u5904\u7406\uff0c\u6570\u636e\u88ab map \u5904\u7406\u7ed3\u675f\u4e4b\u540e\u4ea4\u7ed9 OutputCollector \u6536\u96c6\u5668\uff0c\u5bf9\u5176\u7ed3\u679c key \u8fdb\u884c\u5206\u533a\uff08\u9ed8\u8ba4\u4f7f\u7528 hash \u5206\u533a\uff09\uff0c\u7136\u540e\u5199\u5165 buffer\uff0c\u6bcf\u4e2a map task \u90fd\u6709\u4e00\u4e2a\u5185\u5b58\u7f13\u51b2\u533a\uff0c\u5b58\u50a8\u7740 map \u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u5f53\u7f13\u51b2\u533a\u5feb\u6ee1\u7684\u65f6\u5019\u9700\u8981\u5c06\u7f13\u51b2\u533a\u7684\u6570\u636e\u4ee5\u4e00\u4e2a\u4e34\u65f6\u6587\u4ef6\u7684\u65b9\u5f0f\u5b58\u653e\u5230\u78c1\u76d8\uff0c\u5f53\u6574\u4e2a map task \u7ed3\u675f\u540e\u518d\u5bf9\u78c1\u76d8\u4e2d\u8fd9\u4e2a map task \u4ea7\u751f\u7684\u6240\u6709\u4e34\u65f6\u6587\u4ef6\u505a\u5408\u5e76\uff0c\u751f\u6210\u6700\u7ec8\u7684\u6b63\u5f0f\u8f93\u51fa\u6587\u4ef6\uff0c\u7136\u540e\u7b49\u5f85reduce task \u6765\u62c9\u6570\u636e\u3002 Map\u7aef\u7684\u8f93\u5165\u7684(k,v)\u5206\u522b\u662f\u8be5\u884c\u7684\u8d77\u59cb\u504f\u79fb\u91cf,\u4ee5\u53ca\u6bcf\u4e00\u884c\u7684\u6570\u636e\u5185\u5bb9,map\u7aef\u7684\u8f93\u51fa(k,v)\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u8fdb\u884c\u81ea\u5b9a\u4e49,\u4f46\u662f\u5982\u679c\u8f93\u51fa\u7684\u662fjavabean\u5bf9\u8c61,\u9700\u8981\u5bf9javabean\u7ee7\u627fwritable<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><a>3.&nbsp;&nbsp;&nbsp;&nbsp;\nshuffle<\/a>\u7684\u8fc7\u7a0b<\/h5>\n\n\n\n<p>shuffle\u7684\u8fc7\u7a0b\u662f:Map\u4ea7\u751f\u8f93\u51fa\u5f00\u59cb\u5230Reduc\u53d6\u5f97\u6570\u636e\u4f5c\u4e3a\u8f93\u5165\u4e4b\u524d\u7684\u8fc7\u7a0b\u79f0\u4f5cshuffle.<\/p>\n\n\n\n<p>1).Collect \u9636\u6bb5\uff1a\u5c06 MapTask \u7684\u7ed3\u679c\u8f93\u51fa\u5230\u9ed8\u8ba4\u5927\u5c0f\u4e3a 100M \u7684\u73af\u5f62\u7f13\u51b2\u533a\uff0c\u4fdd\u5b58\u7684\u662f key\/value\uff0cPartition \u5206\u533a\u4fe1\u606f\u7b49\u3002<\/p>\n\n\n\n<p>2).Spill \u9636\u6bb5\uff1a\u5f53\u5185\u5b58\u4e2d\u7684\u6570\u636e\u91cf\u8fbe\u5230\u4e00\u5b9a\u7684\u9600\u503c\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u5c06\u6570\u636e\u5199\u5165\u672c\u5730\u78c1\u76d8\uff0c\u5728\u5c06\u6570\u636e\u5199\u5165\u78c1\u76d8\u4e4b\u524d\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u4e00\u6b21\u6392\u5e8f\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u914d\u7f6e\u4e86 combiner\uff0c\u8fd8\u4f1a\u5c06\u6709\u76f8\u540c\u5206\u533a\u53f7\u548c key \u7684\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n\n\n\n<p>3).Merge \u9636\u6bb5\uff1a\u628a\u6240\u6709\u6ea2\u51fa\u7684\u4e34\u65f6\u6587\u4ef6\u8fdb\u884c\u4e00\u6b21\u5408\u5e76\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u4e00\u4e2a<\/p>\n\n\n\n<p>MapTask \u6700\u7ec8\u53ea\u4ea7\u751f\u4e00\u4e2a\u4e2d\u95f4\u6570\u636e\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>4).Copy \u9636\u6bb5\uff1a ReduceTask \u542f\u52a8 Fetcher \u7ebf\u7a0b\u5230\u5df2\u7ecf\u5b8c\u6210 MapTask \u7684\u8282\u70b9\u4e0a\u590d\u5236\u4e00\u4efd\u5c5e\u4e8e\u81ea\u5df1\u7684\u6570\u636e\uff0c\u8fd9\u4e9b\u6570\u636e\u9ed8\u8ba4\u4f1a\u4fdd\u5b58\u5728\u5185\u5b58\u7684\u7f13\u51b2\u533a\u4e2d\uff0c\u5f53\u5185\u5b58\u7684\u7f13\u51b2\u533a\u8fbe\u5230\u4e00\u5b9a\u7684\u9600\u503c\u7684\u65f6\u5019\uff0c\u5c31\u4f1a\u5c06\u6570\u636e\u5199\u5230\u78c1\u76d8\u4e4b\u4e0a\u3002<\/p>\n\n\n\n<p>5).Merge \u9636\u6bb5\uff1a\u5728 ReduceTask \u8fdc\u7a0b\u590d\u5236\u6570\u636e\u7684\u540c\u65f6\uff0c\u4f1a\u5728\u540e\u53f0\u5f00\u542f\u4e24\u4e2a\u7ebf<\/p>\n\n\n\n<p>\u7a0b\u5bf9\u5185\u5b58\u5230\u672c\u5730\u7684\u6570\u636e\u6587\u4ef6\u8fdb\u884c\u5408\u5e76\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>6).Sort \u9636\u6bb5\uff1a\u5728\u5bf9\u6570\u636e\u8fdb\u884c\u5408\u5e76\u7684\u540c\u65f6\uff0c\u4f1a\u8fdb\u884c\u6392\u5e8f\u64cd\u4f5c\uff0c\u7531\u4e8e MapTask\u9636\u6bb5\u5df2\u7ecf\u5bf9\u6570\u636e\u8fdb\u884c\u4e86\u5c40\u90e8\u7684\u6392\u5e8f\uff0cReduceTask \u53ea\u9700\u4fdd\u8bc1 Copy \u7684\u6570\u636e\u7684\u6700\u7ec8\u6574\u4f53\u6709\u6548\u6027\u5373\u53ef\u3002<\/p>\n\n\n\n<p>Shuffle \u4e2d\u7684\u7f13\u51b2\u533a\u5927\u5c0f\u4f1a\u5f71\u54cd\u5230 mapreduce \u7a0b\u5e8f\u7684\u6267\u884c\u6548\u7387\uff0c\u539f\u5219\u4e0a\u8bf4\uff0c\u7f13\u51b2\u533a\u8d8a\u5927\uff0c\u78c1\u76d8 io \u7684\u6b21\u6570\u8d8a\u5c11\uff0c\u6267\u884c\u901f\u5ea6\u5c31\u8d8a\u5feb\u7f13\u51b2\u533a\u7684\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u8c03\u6574, \u53c2\u6570\uff1aio.sort.mb \u9ed8\u8ba4 100M<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-519-253-0-image-9.png\" target=\"_blank\" rel=\"noreferrer noopener\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-519-253-0-image-9.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"519\" height=\"253\" data-original=\"https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-519-253-0-image-9.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-223\"  sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/div><\/a><\/figure>\n\n\n\n<h5 class=\"wp-block-heading\"><a>2.&nbsp;&nbsp;&nbsp;&nbsp;\nreduceTask<\/a><\/h5>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; reducer\u5c06\u5df2\u7ecf\u5206\u597d\u7ec4\u7684\u6570\u636e\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u4f9d\u6b21\u4e3a\u6bcf\u4e2a\u952e\u5bf9\u5e94\u5206\u7ec4\u6267\u884creduce\u51fd\u6570\u3002reduce\u51fd\u6570\u7684\u8f93\u5165\u662f\u952e\u4ee5\u53ca\u5305\u542b\u4e0e\u8be5\u952e\u5bf9\u5e94\u7684\u6240\u6709\u503c\u7684\u8fed\u4ee3\u5668\u3002<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reduce\u7aef\u7684\u8f93\u5165\u662fmap\u7aef\u7684\u8f93\u51fa,\u5b83\u7684\u8f93\u51fa\u7684(k,v)\u6839\u636e\u9700\u6c42\u8fdb\u884c\u81ea\u5b9a\u4e49<\/p>\n\n\n\n<p>reducetask \u5e76\u884c\u5ea6\u540c\u6837\u5f71\u54cd\u6574\u4e2a job \u7684\u6267\u884c\u5e76\u53d1\u5ea6\u548c\u6267\u884c\u6548\u7387\uff0c\u4e0e maptask<\/p>\n\n\n\n<p>\u7684\u5e76\u53d1\u6570\u7531\u5207\u7247\u6570\u51b3\u5b9a\u4e0d\u540c\uff0cReducetask \u6570\u91cf\u7684\u51b3\u5b9a\u662f\u53ef\u4ee5\u76f4\u63a5\u624b\u52a8\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<p>job.setNumReduceTasks(4);<\/p>\n\n\n\n<p>\u5982\u679c\u6570\u636e\u5206\u5e03\u4e0d\u5747\u5300\uff0c\u5c31\u6709\u53ef\u80fd\u5728 reduce \u9636\u6bb5\u4ea7\u751f\u6570\u636e\u503e\u659c\u3002<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u7684reduceTask\u7684\u662f1<\/p>\n\n\n\n<p>*Task\u5e76\u884c\u5ea6\u7ecf\u9a8c\u4e4b\u8c08\uff1a<\/p>\n\n\n\n<p>\u6700\u597d\u6bcf\u4e2a task \u7684\u6267\u884c\u65f6\u95f4\u81f3\u5c11\u4e00\u5206\u949f\u3002\u5982\u679c job \u7684\u6bcf\u4e2a map \u6216\u8005 reduce task \u7684\u8fd0\u884c\u65f6\u95f4\u90fd\u53ea\u6709 30-40 \u79d2\u949f\uff0c\u90a3\u4e48\u5c31\u51cf\u5c11\u8be5 job \u7684 map \u6216\u8005 reduce \u6570\uff0c\u6bcf\u4e00\u4e2a task(map|reduce)\u7684 setup \u548c\u52a0\u5165\u5230\u8c03\u5ea6\u5668\u4e2d\u8fdb\u884c\u8c03\u5ea6\uff0c\u8fd9\u4e2a\u4e2d\u95f4\u7684\u8fc7\u7a0b\u53ef\u80fd\u90fd\u8981\u82b1\u8d39\u51e0\u79d2\u949f\uff0c\u6240\u4ee5\u5982\u679c\u6bcf\u4e2atask \u90fd\u975e\u5e38\u5feb\u5c31\u8dd1\u5b8c\u4e86\uff0c\u5c31\u4f1a\u5728 task \u7684\u5f00\u59cb\u548c\u7ed3\u675f\u7684\u65f6\u5019\u6d6a\u8d39\u592a\u591a\u7684\u65f6\u95f4\u3002<\/p>\n\n\n\n<p>&nbsp; &nbsp; \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e00\u4e2a task \u90fd\u662f\u4e00\u4e2a\u65b0\u7684 JVM \u5b9e\u4f8b\uff0c\u90fd\u9700\u8981\u5f00\u542f\u548c\u9500<\/p>\n\n\n\n<p>\u6bc1\u7684\u5f00\u9500\u3002\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\uff0cJVM\n\u5f00\u542f\u548c\u9500\u6bc1\u7684\u65f6\u95f4\u53ef\u80fd\u4f1a\u6bd4\u5b9e\u9645\u5904\u7406\u6570\u636e\u7684\u65f6\u95f4<\/p>\n\n\n\n<p>\u8981\u6d88\u8017\u7684\u957f\uff0c\u914d\u7f6e\ntask \u7684 M JVM&nbsp; \u91cd\u7528\u53ef\u4ee5\u6539\u5584\u8be5\u95ee\u9898\uff1a<\/p>\n\n\n\n<p>\uff08mapred.job.reuse.jvm.num.tasks\uff0c\u9ed8\u8ba4\u662f 1\uff0c\u8868\u793a\u4e00\u4e2a JVM \u4e0a\u6700\u591a\u53ef\u4ee5<\/p>\n\n\n\n<p>\u987a\u5e8f\u6267\u884c\u7684 task \u6570\u76ee\uff08\u5c5e\u4e8e\u540c\u4e00\u4e2a Job\uff09\u662f 1\u3002\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a task\n\u542f\u4e00\u4e2a JVM\uff09<\/p>\n\n\n\n<p>\u5982\u679c input \u7684\u6587\u4ef6\u975e\u5e38\u7684\u5927\uff0c\u6bd4\u5982 1TB\uff0c\u53ef\u4ee5\u8003\u8651\u5c06 hdfs \u4e0a\u7684\u6bcf\u4e2a\nblock<\/p>\n\n\n\n<p>size \u8bbe\u5927\uff0c\u6bd4\u5982\u8bbe\u6210 256MB \u6216\u8005 512MB<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><a>3.&nbsp;&nbsp;&nbsp;&nbsp;\noutputformat<\/a><\/h5>\n\n\n\n<p>OutputFormat\u4e3b\u8981\u7528\u4e8e\u63cf\u8ff0\u8f93\u51fa\u6570\u636e\u7684\u683c\u5f0f\uff0c\u5b83\u80fd\u591f\u5c06\u7528\u6237\u63d0\u4f9b\u7684key\/value\u5bf9\u5199\u5165\u7279\u5b9a\u683c\u5f0f\u7684\u6587\u4ef6\u4e2d\u3002Hadoop \u81ea\u5e26\u4e86\u5f88\u591a OutputFormat \u7684\u5b9e\u73b0\uff0c\u5b83\u4eec\u4e0eInputFormat\u5b9e\u73b0\u76f8\u5bf9\u5e94\uff0c\u8db3\u591f\u6ee1\u8db3\u6211\u4eec\u4e1a\u52a1\u7684\u9700\u8981\u3002 OutputFormat \u7c7b\u7684\u5c42\u6b21\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-558-231-0-image-10.png\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-558-231-0-image-10.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"231\" data-original=\"https:\/\/blog.frost-s.com\/wp-content\/uploads\/2020\/03\/crop-0-0-558-231-0-image-10.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-225\"  sizes=\"(max-width: 558px) 100vw, 558px\" \/><\/div><\/a><\/figure>\n\n\n\n<p>OutputFormat\u662fMapReduce\u8f93\u51fa\u7684\u57fa\u7c7b\uff0c\u6240\u6709MapReduce\u8f93\u51fa\u90fd\u5b9e\u73b0\u4e86 OutputFormat \u63a5\u53e3,\u4e3b\u8981\u6709\uff1a<\/p>\n\n\n\n<p>TextInputFormat&nbsp;\u3001SequenceFileOutputFormat\u3001MultipleOutputs\u3001DBOutputFormat\u7b49<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><a>1.1.1&nbsp;&nbsp;\n\u7279\u6b8a\u7684\u7ec4\u4ef6partitioner\u4e0ecombiner<\/a><\/h3>\n\n\n\n<h5 class=\"wp-block-heading\"><a>1.&nbsp;&nbsp;&nbsp;&nbsp;\npartitioner<\/a>\u5b9a\u4e49<\/h5>\n\n\n\n<p>partitioner\u7684\u4f5c\u7528\u662f\u5c06mapper\uff08\u5982\u679c\u4f7f\u7528\u4e86combiner\u7684\u8bdd\u5c31\u662fcombiner\uff09\u8f93\u51fa\u7684key\/value\u62c6\u5206\u4e3a\u5206\u7247\uff08shard\uff09\uff0c\u6bcf\u4e2areducer\u5bf9\u5e94\u4e00\u4e2a\u5206\u7247\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cpartitioner\u5148\u8ba1\u7b97key\u7684\u6563\u5217\u503c\uff08\u901a\u5e38\u4e3amd5\u503c\uff09\u3002\u7136\u540e\u901a\u8fc7reducer\u4e2a\u6570\u6267\u884c\u53d6\u6a21\u8fd0\u7b97\uff1akey.hashCode%(reducer\u4e2a\u6570)\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u80fd\u591f\u968f\u673a\u5730\u5c06\u6574\u4e2akey\u7a7a\u95f4\u5e73\u5747\u5206\u53d1\u7ed9\u6bcf\u4e2areducer,\u540c\u65f6\u4e5f\u80fd\u786e\u4fdd\u4e0d\u540cmapper\u4ea7\u751f\u7684\u76f8\u540ckey\u80fd\u88ab\u5206\u53d1\u5230\u540c\u4e00\u4e2areducer\u3002\u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5206\u533a\u53bb\u7ee7\u627fpartition&lt;key,value&gt;\u628a\u4e0d\u540c\u7684\u7ed3\u679c\u5199\u5165\u4e0d\u540c\u7684\u6587\u4ef6\u4e2d<\/p>\n\n\n\n<p>\u5206\u533aPartitioner\u4e3b\u8981\u4f5c\u7528\u5728\u4e8e\u4ee5\u4e0b\u4e24\u70b9<\/p>\n\n\n\n<p>\uff081\uff09\u6839\u636e\u4e1a\u52a1\u9700\u8981\uff0c\u4ea7\u751f\u591a\u4e2a\u8f93\u51fa\u6587\u4ef6\uff1b<\/p>\n\n\n\n<p>\uff082\uff09\u591a\u4e2areduce\u4efb\u52a1\u5e76\u53d1\u8fd0\u884c\uff0c\u63d0\u9ad8\u6574\u4f53job\u7684\u8fd0\u884c\u6548\u7387<\/p>\n\n\n\n<p>\u9002\u7528\u8303\u56f4\uff1a<\/p>\n\n\n\n<p>\u9700\u8981\u975e\u5e38\u6ce8\u610f\u7684\u662f\uff1a\u5fc5\u987b\u63d0\u524d\u77e5\u9053\u6709\u591a\u5c11\u4e2a\u5206\u533a\u3002\u6bd4\u5982\u81ea\u5b9a\u4e49Partitioner\u4f1a\u8fd4\u56de5\u4e2a\u4e0d\u540cint\u503c\uff0c\u800creducer\nnumber\u8bbe\u7f6e\u4e86\u5c0f\u4e8e5\uff0c\u90a3\u5c31\u4f1a\u62a5\u9519\u3002\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u5206\u6790\u4efb\u52a1\u6765\u786e\u5b9a\u5206\u533a\u6570\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2.&nbsp;&nbsp;&nbsp;&nbsp;\nmap\u7aef\u7684combine\u7ec4\u4ef6<\/h5>\n\n\n\n<p>\u6bcf\u4e00\u4e2a map \u90fd\u53ef\u80fd\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u672c\u5730\u8f93\u51fa\uff0cCombiner \u7684\u4f5c\u7528\u5c31\u662f\u5bf9 map \u7aef\u7684\u8f93\u51fa\u5148\u505a\u4e00\u6b21\u5408\u5e76\uff0c\u4ee5\u51cf\u5c11\u5728 map \u548c reduce \u8282\u70b9\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u8f93\u91cf\uff0c\u4ee5\u63d0\u9ad8\u7f51\u7edc IO \u6027\u80fd\uff0c\u662f MapReduce \u7684\u4e00\u79cd\u4f18\u5316\u624b\u6bb5\u4e4b\u4e00<\/p>\n\n\n\n<p>combiner \u662f MR \u7a0b\u5e8f\u4e2d\nMapper \u548c Reducer \u4e4b\u5916\u7684\u4e00\u79cd\u7ec4\u4ef6<\/p>\n\n\n\n<p>combiner \u7ec4\u4ef6\u7684\u7236\u7c7b\u5c31\u662f Reducer<\/p>\n\n\n\n<p>combiner \u548c reducer \u7684\u533a\u522b\u5728\u4e8e\u8fd0\u884c\u7684\u4f4d\u7f6e\uff1a<\/p>\n\n\n\n<p>combiner \u662f\u5728\u6bcf\u4e00\u4e2a maptask \u6240\u5728\u7684\u8282\u70b9\u8fd0\u884c<\/p>\n\n\n\n<p>reducer \u662f\u63a5\u6536\u5168\u5c40\u6240\u6709 Mapper \u7684\u8f93\u51fa\u7ed3\u679c\uff1b<\/p>\n\n\n\n<p>combiner \u7684\u610f\u4e49\u5c31\u662f\u5bf9\u6bcf\u4e00\u4e2a maptask \u7684\u8f93\u51fa\u8fdb\u884c\u5c40\u90e8\u6c47\u603b\uff0c\u4ee5\u51cf\u5c0f\u7f51\u7edc\u4f20\u8f93\u91cf<\/p>\n\n\n\n<p class=\"has-normal-font-size\">\u5177\u4f53\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/p>\n\n\n\n<p>1)\u81ea\u5b9a\u4e49\u4e00\u4e2a combiner \u7ee7\u627f Reducer\uff0c\u91cd\u5199 reduce \u65b9\u6cd5<\/p>\n\n\n\n<p>2)\u4e2d\u8bbe\u7f6e\uff1a job.setCombinerClass(CustomCombiner.class)<\/p>\n\n\n\n<p> combiner \u80fd\u591f\u5e94\u7528\u7684\u524d\u63d0\u662f\u4e0d\u80fd\u5f71\u54cd\u6700\u7ec8\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u800c\u4e14\uff0ccombine<\/p>\n\n\n\n<p>\u8f93\u51fa kv \u5e94\u8be5\u8ddf reducer \u7684\u8f93\u5165 kv \u7c7b\u578b\u8981\u5bf9\u5e94\u8d77\u6765<\/p>\n\n\n\n<p>Combiner\u4f7f\u7528\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n\n\n\n<p>1.\u6709\u5f88\u591a\u4eba\u8ba4\u4e3a\u8fd9\u4e2acombiner\u548cmap\u8f93\u51fa\u7684\u6570\u636e\u5408\u5e76\u662f\u4e00\u4e2a\u8fc7\u7a0b\uff0c\u5176\u5b9e\u4e0d\u7136\uff0cmap\u8f93\u51fa\u7684\u6570\u636e\u5408\u5e76\u53ea\u4f1a\u4ea7\u751f\u5728\u6709\u6570\u636espill\u51fa\u7684\u65f6\u5019\uff0c\u5373\u8fdb\u884cmerge\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p>2.\u4e0emapper\u4e0ereducer\u4e0d\u540c\u7684\u662f\uff0ccombiner\u6ca1\u6709\u9ed8\u8ba4\u7684\u5b9e\u73b0\uff0c\u9700\u8981\u663e\u5f0f\u7684\u8bbe\u7f6e\u5728conf\u4e2d\u624d\u6709\u4f5c\u7528\u3002<\/p>\n\n\n\n<p>3.\u5e76\u4e0d\u662f\u6240\u6709\u7684job\u90fd\u9002\u7528combiner\uff0c\u53ea\u6709\u64cd\u4f5c\u6ee1\u8db3\u7ed3\u5408\u5f8b\u7684\u624d\u53ef\u8bbe\u7f6ecombiner\u3002combine\u64cd\u4f5c\u7c7b\u4f3c\u4e8e\uff1aopt(opt(1, 2, 3), opt(4, 5, 6))\u3002\u5982\u679copt\u4e3a\u6c42\u548c\u3001\u6c42\u6700\u5927\u503c\u7684\u8bdd\uff0c\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u662f\u5982\u679c\u662f\u6c42\u4e2d\u503c\u7684\u8bdd\uff0c\u4e0d\u9002\u7528\u3002<\/p>\n\n\n\n<p>4.\u4e00\u822c\u6765\u8bf4\uff0ccombiner\u548creducer\u5b83\u4eec\u4fe9\u8fdb\u884c\u540c\u6837\u7684\u64cd\u4f5c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.1&nbsp;&nbsp; \u5206\u5e03\u5f0f\u8ba1\u7b97\u6846\u67b6 1.1.1&nbsp;&nbsp; \u7f16\u7a0b\u6a21\u578b 1.&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":44,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/213"}],"collection":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/comments?post=213"}],"version-history":[{"count":4,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions"}],"predecessor-version":[{"id":229,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/posts\/213\/revisions\/229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media\/44"}],"wp:attachment":[{"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/media?parent=213"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/categories?post=213"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.frost-s.com\/index.php\/wp-json\/wp\/v2\/tags?post=213"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}