{"id":2890,"date":"2019-02-27T16:52:53","date_gmt":"2019-02-27T08:52:53","guid":{"rendered":"https:\/\/damogame.cn:15443\/wordpress\/?p=2890"},"modified":"2019-02-27T16:52:53","modified_gmt":"2019-02-27T08:52:53","slug":"kafka-%e8%ae%be%e8%ae%a1%e4%b8%8e%e5%8e%9f%e7%90%86%e8%af%a6%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/2890","title":{"rendered":"Kafka \u8bbe\u8ba1\u4e0e\u539f\u7406\u8be6\u89e3"},"content":{"rendered":"<div class=\"article-header-box\">\n<div class=\"article-header\">\n<div class=\"article-title-box\"><\/div>\n<div class=\"article-info-box\">\n<div class=\"operating\">\u00a0\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u672a\u7ecf\u535a\u4e3b\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002 https:\/\/blog.csdn.net\/suifeng3051\/article\/details\/48053965<\/div>\n<\/div>\n<\/div>\n<\/div>\n<article class=\"baidu_pl\">\n<div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" data-pid=\"blog\" data-mod=\"popu_307\" data-dsm=\"post\">\n<div id=\"content_views\" class=\"markdown_views prism-atom-one-light\">\n<h2 id=\"\u4e00kafka\u7b80\u4ecb\"><a name=\"t0\"><\/a>\u4e00\u3001Kafka\u7b80\u4ecb<\/h2>\n<pre class=\"prettyprint\"><code class=\"has-numbering\">\u672c\u6587\u7efc\u5408\u4e86\u6211\u4e4b\u524d\u5199\u7684kafka\u76f8\u5173\u6587\u7ae0\uff0c\u53ef\u4f5c\u4e3a\u4e00\u4e2a\u5168\u9762\u4e86\u89e3\u5b66\u4e60kafka\u7684\u57f9\u8bad\u5b66\u4e60\u8d44\u6599\u3002\r\n<\/code><\/pre>\n<ul class=\"pre-numbering\">\n<li>1<\/li>\n<\/ul>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\u51fa\u5904 :\u00a0<a href=\"http:\/\/blog.csdn.net\/suifeng3051\/article\/details\/48053965\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">\u672c\u6587\u94fe\u63a5<\/a><\/p>\n<h3 id=\"11-\u80cc\u666f\u5386\u53f2\"><a name=\"t1\"><\/a>1.1 \u80cc\u666f\u5386\u53f2<\/h3>\n<p>\u5f53\u4eca\u793e\u4f1a\u5404\u79cd\u5e94\u7528\u7cfb\u7edf\u8bf8\u5982\u5546\u4e1a\u3001\u793e\u4ea4\u3001\u641c\u7d22\u3001\u6d4f\u89c8\u7b49\u50cf\u4fe1\u606f\u5de5\u5382\u4e00\u6837\u4e0d\u65ad\u7684\u751f\u4ea7\u51fa\u5404\u79cd\u4fe1\u606f\uff0c\u5728\u5927\u6570\u636e\u65f6\u4ee3\uff0c\u6211\u4eec\u9762\u4e34\u5982\u4e0b\u51e0\u4e2a\u6311\u6218\uff1a<\/p>\n<ol>\n<li>\u5982\u4f55\u6536\u96c6\u8fd9\u4e9b\u5de8\u5927\u7684\u4fe1\u606f<\/li>\n<li>\u5982\u4f55\u5206\u6790\u5b83<\/li>\n<li>\u5982\u4f55\u53ca\u65f6\u505a\u5230\u5982\u4e0a\u4e24\u70b9<\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u51e0\u4e2a\u6311\u6218\u5f62\u6210\u4e86\u4e00\u4e2a\u4e1a\u52a1\u9700\u6c42\u6a21\u578b\uff0c\u5373\u751f\u4ea7\u8005\u751f\u4ea7\uff08produce\uff09\u5404\u79cd\u4fe1\u606f\uff0c\u6d88\u8d39\u8005\u6d88\u8d39\uff08consume\uff09\uff08\u5904\u7406\u5206\u6790\uff09\u8fd9\u4e9b\u4fe1\u606f\uff0c\u800c\u5728\u751f\u4ea7\u8005\u4e0e\u6d88\u8d39\u8005\u4e4b\u95f4\uff0c\u9700\u8981\u4e00\u4e2a\u6c9f\u901a\u4e24\u8005\u7684\u6865\u6881-\u6d88\u606f\u7cfb\u7edf\u3002\u4ece\u4e00\u4e2a\u5fae\u89c2\u5c42\u9762\u6765\u8bf4\uff0c\u8fd9\u79cd\u9700\u6c42\u4e5f\u53ef\u7406\u89e3\u4e3a\u4e0d\u540c\u7684\u7cfb\u7edf\u4e4b\u95f4\u5982\u4f55\u4f20\u9012\u6d88\u606f\u3002<\/p>\n<h3 id=\"12-kafka\u8bde\u751f\"><a name=\"t2\"><\/a>1.2 Kafka\u8bde\u751f<\/h3>\n<p>Kafka\u7531\u00a0<strong>linked-in<\/strong>\u00a0\u5f00\u6e90<br \/>\nkafka-\u5373\u662f\u89e3\u51b3\u4e0a\u8ff0\u8fd9\u7c7b\u95ee\u9898\u7684\u4e00\u4e2a\u6846\u67b6\uff0c\u5b83\u5b9e\u73b0\u4e86\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u4e4b\u95f4\u7684\u65e0\u7f1d\u8fde\u63a5\u3002<br \/>\nkafka-\u9ad8\u4ea7\u51fa\u7684\u5206\u5e03\u5f0f\u6d88\u606f\u7cfb\u7edf(A high-throughput distributed messaging system)<\/p>\n<h3 id=\"13-kafka\u73b0\u5728\"><a name=\"t3\"><\/a>1.3 Kafka\u73b0\u5728<\/h3>\n<p>Apache kafka \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u7684\u57fa\u4e8epush-subscribe\u7684\u6d88\u606f\u7cfb\u7edf\uff0c\u5b83\u5177\u5907\u5feb\u901f\u3001\u53ef\u6269\u5c55\u3001\u53ef\u6301\u4e45\u5316\u7684\u7279\u70b9\u3002\u5b83\u73b0\u5728\u662fApache\u65d7\u4e0b\u7684\u4e00\u4e2a\u5f00\u6e90\u7cfb\u7edf\uff0c\u4f5c\u4e3ahadoop\u751f\u6001\u7cfb\u7edf\u7684\u4e00\u90e8\u5206\uff0c\u88ab\u5404\u79cd\u5546\u4e1a\u516c\u53f8\u5e7f\u6cdb\u5e94\u7528\u3002\u5b83\u7684\u6700\u5927\u7684\u7279\u6027\u5c31\u662f\u53ef\u4ee5\u5b9e\u65f6\u7684\u5904\u7406\u5927\u91cf\u6570\u636e\u4ee5\u6ee1\u8db3\u5404\u79cd\u9700\u6c42\u573a\u666f\uff1a\u6bd4\u5982\u57fa\u4e8ehadoop\u7684\u6279\u5904\u7406\u7cfb\u7edf\u3001\u4f4e\u5ef6\u8fdf\u7684\u5b9e\u65f6\u7cfb\u7edf\u3001storm\/spark\u6d41\u5f0f\u5904\u7406\u5f15\u64ce\u3002<\/p>\n<h2 id=\"\u4e8ckafka\u6280\u672f\u6982\u89c8\"><a name=\"t4\"><\/a>\u4e8c\u3001Kafka\u6280\u672f\u6982\u89c8<\/h2>\n<h3 id=\"21-kafka\u7684\u7279\u6027\"><a name=\"t5\"><\/a>2.1 Kafka\u7684\u7279\u6027<\/h3>\n<ul>\n<li><strong>\u9ad8\u541e\u5410\u91cf\u3001\u4f4e\u5ef6\u8fdf<\/strong>\uff1akafka\u6bcf\u79d2\u53ef\u4ee5\u5904\u7406\u51e0\u5341\u4e07\u6761\u6d88\u606f\uff0c\u5b83\u7684\u5ef6\u8fdf\u6700\u4f4e\u53ea\u6709\u51e0\u6beb\u79d2<\/li>\n<li><strong>\u53ef\u6269\u5c55\u6027<\/strong>\uff1akafka\u96c6\u7fa4\u652f\u6301\u70ed\u6269\u5c55<\/li>\n<li><strong>\u6301\u4e45\u6027\u3001\u53ef\u9760\u6027<\/strong>\uff1a\u6d88\u606f\u88ab\u6301\u4e45\u5316\u5230\u672c\u5730\u78c1\u76d8\uff0c\u5e76\u4e14\u652f\u6301\u6570\u636e\u5907\u4efd\u9632\u6b62\u6570\u636e\u4e22\u5931<\/li>\n<li><strong>\u5bb9\u9519\u6027<\/strong>\uff1a\u5141\u8bb8\u96c6\u7fa4\u4e2d\u8282\u70b9\u5931\u8d25\uff08\u82e5\u526f\u672c\u6570\u91cf\u4e3an,\u5219\u5141\u8bb8n-1\u4e2a\u8282\u70b9\u5931\u8d25\uff09<\/li>\n<li><strong>\u9ad8\u5e76\u53d1<\/strong>\uff1a\u652f\u6301\u6570\u5343\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u8bfb\u5199<\/li>\n<\/ul>\n<h3 id=\"22-kafka\u4e00\u4e9b\u91cd\u8981\u8bbe\u8ba1\u601d\u60f3\"><a name=\"t6\"><\/a>2.2 Kafka\u4e00\u4e9b\u91cd\u8981\u8bbe\u8ba1\u601d\u60f3<\/h3>\n<p>\u4e0b\u9762\u4ecb\u7ecd\u5148\u5927\u4f53\u4ecb\u7ecd\u4e00\u4e0bKafka\u7684\u4e3b\u8981\u8bbe\u8ba1\u601d\u60f3\uff0c\u53ef\u4ee5\u8ba9\u76f8\u5173\u4eba\u5458\u5728\u77ed\u65f6\u95f4\u5185\u4e86\u89e3\u5230kafka\u76f8\u5173\u7279\u6027\uff0c\u5982\u679c\u60f3\u6df1\u5165\u7814\u7a76\uff0c\u540e\u9762\u4f1a\u5bf9\u5176\u4e2d\u6bcf\u4e00\u4e2a\u7279\u6027\u90fd\u505a\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/p>\n<ul>\n<li><strong>Consumergroup<\/strong>\uff1a\u5404\u4e2aconsumer\u53ef\u4ee5\u7ec4\u6210\u4e00\u4e2a\u7ec4\uff0c\u6bcf\u4e2a\u6d88\u606f\u53ea\u80fd\u88ab\u7ec4\u4e2d\u7684\u4e00\u4e2aconsumer\u6d88\u8d39\uff0c\u5982\u679c\u4e00\u4e2a\u6d88\u606f\u53ef\u4ee5\u88ab\u591a\u4e2aconsumer\u6d88\u8d39\u7684\u8bdd\uff0c\u90a3\u4e48\u8fd9\u4e9bconsumer\u5fc5\u987b\u5728\u4e0d\u540c\u7684\u7ec4\u3002<\/li>\n<li><strong>\u6d88\u606f\u72b6\u6001<\/strong>\uff1a\u5728Kafka\u4e2d\uff0c\u6d88\u606f\u7684\u72b6\u6001\u88ab\u4fdd\u5b58\u5728consumer\u4e2d\uff0cbroker\u4e0d\u4f1a\u5173\u5fc3\u54ea\u4e2a\u6d88\u606f\u88ab\u6d88\u8d39\u4e86\u88ab\u8c01\u6d88\u8d39\u4e86\uff0c\u53ea\u8bb0\u5f55\u4e00\u4e2aoffset\u503c\uff08\u6307\u5411partition\u4e2d\u4e0b\u4e00\u4e2a\u8981\u88ab\u6d88\u8d39\u7684\u6d88\u606f\u4f4d\u7f6e\uff09\uff0c\u8fd9\u5c31\u610f\u5473\u7740\u5982\u679cconsumer\u5904\u7406\u4e0d\u597d\u7684\u8bdd\uff0cbroker\u4e0a\u7684\u4e00\u4e2a\u6d88\u606f\u53ef\u80fd\u4f1a\u88ab\u6d88\u8d39\u591a\u6b21\u3002<\/li>\n<li><strong>\u6d88\u606f\u6301\u4e45\u5316<\/strong>\uff1aKafka\u4e2d\u4f1a\u628a\u6d88\u606f\u6301\u4e45\u5316\u5230\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u5e76\u4e14\u4fdd\u6301\u6781\u9ad8\u7684\u6548\u7387\u3002<\/li>\n<li><strong>\u6d88\u606f\u6709\u6548\u671f<\/strong>\uff1aKafka\u4f1a\u957f\u4e45\u4fdd\u7559\u5176\u4e2d\u7684\u6d88\u606f\uff0c\u4ee5\u4fbfconsumer\u53ef\u4ee5\u591a\u6b21\u6d88\u8d39\uff0c\u5f53\u7136\u5176\u4e2d\u5f88\u591a\u7ec6\u8282\u662f\u53ef\u914d\u7f6e\u7684\u3002<\/li>\n<li><strong>\u6279\u91cf\u53d1\u9001<\/strong>\uff1aKafka\u652f\u6301\u4ee5\u6d88\u606f\u96c6\u5408\u4e3a\u5355\u4f4d\u8fdb\u884c\u6279\u91cf\u53d1\u9001\uff0c\u4ee5\u63d0\u9ad8push\u6548\u7387\u3002<\/li>\n<li><strong>push-and-pull<\/strong>\u00a0: Kafka\u4e2d\u7684Producer\u548cconsumer\u91c7\u7528\u7684\u662fpush-and-pull\u6a21\u5f0f\uff0c\u5373Producer\u53ea\u7ba1\u5411broker push\u6d88\u606f\uff0cconsumer\u53ea\u7ba1\u4ecebroker pull\u6d88\u606f\uff0c\u4e24\u8005\u5bf9\u6d88\u606f\u7684\u751f\u4ea7\u548c\u6d88\u8d39\u662f\u5f02\u6b65\u7684\u3002<\/li>\n<li><strong>Kafka\u96c6\u7fa4\u4e2dbroker\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong>\uff1a\u4e0d\u662f\u4e3b\u4ece\u5173\u7cfb\uff0c\u5404\u4e2abroker\u5728\u96c6\u7fa4\u4e2d\u5730\u4f4d\u4e00\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u968f\u610f\u7684\u589e\u52a0\u6216\u5220\u9664\u4efb\u4f55\u4e00\u4e2abroker\u8282\u70b9\u3002<\/li>\n<li><strong>\u8d1f\u8f7d\u5747\u8861\u65b9\u9762<\/strong>\uff1a Kafka\u63d0\u4f9b\u4e86\u4e00\u4e2a metadata API\u6765\u7ba1\u7406broker\u4e4b\u95f4\u7684\u8d1f\u8f7d\uff08\u5bf9Kafka0.8.x\u800c\u8a00\uff0c\u5bf9\u4e8e0.7.x\u4e3b\u8981\u9760zookeeper\u6765\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\uff09\u3002<\/li>\n<li><strong>\u540c\u6b65\u5f02\u6b65<\/strong>\uff1aProducer\u91c7\u7528\u5f02\u6b65push\u65b9\u5f0f\uff0c\u6781\u5927\u63d0\u9ad8Kafka\u7cfb\u7edf\u7684\u541e\u5410\u7387\uff08\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u63a7\u5236\u662f\u91c7\u7528\u540c\u6b65\u8fd8\u662f\u5f02\u6b65\u65b9\u5f0f\uff09\u3002<\/li>\n<li><strong>\u5206\u533a\u673a\u5236partition<\/strong>\uff1aKafka\u7684broker\u7aef\u652f\u6301\u6d88\u606f\u5206\u533a\uff0cProducer\u53ef\u4ee5\u51b3\u5b9a\u628a\u6d88\u606f\u53d1\u5230\u54ea\u4e2a\u5206\u533a\uff0c\u5728\u4e00\u4e2a\u5206\u533a\u4e2d\u6d88\u606f\u7684\u987a\u5e8f\u5c31\u662fProducer\u53d1\u9001\u6d88\u606f\u7684\u987a\u5e8f\uff0c\u4e00\u4e2a\u4e3b\u9898\u4e2d\u53ef\u4ee5\u6709\u591a\u4e2a\u5206\u533a\uff0c\u5177\u4f53\u5206\u533a\u7684\u6570\u91cf\u662f\u53ef\u914d\u7f6e\u7684\u3002\u5206\u533a\u7684\u610f\u4e49\u5f88\u91cd\u5927\uff0c\u540e\u9762\u7684\u5185\u5bb9\u4f1a\u9010\u6e10\u4f53\u73b0\u3002<\/li>\n<li><strong>\u79bb\u7ebf\u6570\u636e\u88c5\u8f7d<\/strong>\uff1aKafka\u7531\u4e8e\u5bf9\u53ef\u62d3\u5c55\u7684\u6570\u636e\u6301\u4e45\u5316\u7684\u652f\u6301\uff0c\u5b83\u4e5f\u975e\u5e38\u9002\u5408\u5411Hadoop\u6216\u8005\u6570\u636e\u4ed3\u5e93\u4e2d\u8fdb\u884c\u6570\u636e\u88c5\u8f7d\u3002<\/li>\n<li><strong>\u63d2\u4ef6\u652f\u6301<\/strong>\uff1a\u73b0\u5728\u4e0d\u5c11\u6d3b\u8dc3\u7684\u793e\u533a\u5df2\u7ecf\u5f00\u53d1\u51fa\u4e0d\u5c11\u63d2\u4ef6\u6765\u62d3\u5c55Kafka\u7684\u529f\u80fd\uff0c\u5982\u7528\u6765\u914d\u5408Storm\u3001Hadoop\u3001flume\u76f8\u5173\u7684\u63d2\u4ef6\u3002<\/li>\n<\/ul>\n<h3 id=\"23-kafka-\u5e94\u7528\u573a\u666f\"><a name=\"t7\"><\/a>2.3 kafka \u5e94\u7528\u573a\u666f<\/h3>\n<ul>\n<li><strong>\u65e5\u5fd7\u6536\u96c6<\/strong>\uff1a\u4e00\u4e2a\u516c\u53f8\u53ef\u4ee5\u7528Kafka\u53ef\u4ee5\u6536\u96c6\u5404\u79cd\u670d\u52a1\u7684log\uff0c\u901a\u8fc7kafka\u4ee5\u7edf\u4e00\u63a5\u53e3\u670d\u52a1\u7684\u65b9\u5f0f\u5f00\u653e\u7ed9\u5404\u79cdconsumer\uff0c\u4f8b\u5982hadoop\u3001Hbase\u3001Solr\u7b49\u3002<\/li>\n<li><strong>\u6d88\u606f\u7cfb\u7edf<\/strong>\uff1a\u89e3\u8026\u548c\u751f\u4ea7\u8005\u548c\u6d88\u8d39\u8005\u3001\u7f13\u5b58\u6d88\u606f\u7b49\u3002<\/li>\n<li><strong>\u7528\u6237\u6d3b\u52a8\u8ddf\u8e2a<\/strong>\uff1aKafka\u7ecf\u5e38\u88ab\u7528\u6765\u8bb0\u5f55web\u7528\u6237\u6216\u8005app\u7528\u6237\u7684\u5404\u79cd\u6d3b\u52a8\uff0c\u5982\u6d4f\u89c8\u7f51\u9875\u3001\u641c\u7d22\u3001\u70b9\u51fb\u7b49\u6d3b\u52a8\uff0c\u8fd9\u4e9b\u6d3b\u52a8\u4fe1\u606f\u88ab\u5404\u4e2a\u670d\u52a1\u5668\u53d1\u5e03\u5230kafka\u7684topic\u4e2d\uff0c\u7136\u540e\u8ba2\u9605\u8005\u901a\u8fc7\u8ba2\u9605\u8fd9\u4e9btopic\u6765\u505a\u5b9e\u65f6\u7684\u76d1\u63a7\u5206\u6790\uff0c\u6216\u8005\u88c5\u8f7d\u5230hadoop\u3001\u6570\u636e\u4ed3\u5e93\u4e2d\u505a\u79bb\u7ebf\u5206\u6790\u548c\u6316\u6398\u3002<\/li>\n<li><strong>\u8fd0\u8425\u6307\u6807<\/strong>\uff1aKafka\u4e5f\u7ecf\u5e38\u7528\u6765\u8bb0\u5f55\u8fd0\u8425\u76d1\u63a7\u6570\u636e\u3002\u5305\u62ec\u6536\u96c6\u5404\u79cd\u5206\u5e03\u5f0f\u5e94\u7528\u7684\u6570\u636e\uff0c\u751f\u4ea7\u5404\u79cd\u64cd\u4f5c\u7684\u96c6\u4e2d\u53cd\u9988\uff0c\u6bd4\u5982\u62a5\u8b66\u548c\u62a5\u544a\u3002<\/li>\n<li><strong>\u6d41\u5f0f\u5904\u7406<\/strong>\uff1a\u6bd4\u5982spark streaming\u548cstorm<\/li>\n<li><strong>\u4e8b\u4ef6\u6e90<\/strong><\/li>\n<\/ul>\n<h3 id=\"24-kafka\u67b6\u6784\u7ec4\u4ef6\"><a name=\"t8\"><\/a>2.4 Kafka\u67b6\u6784\u7ec4\u4ef6<\/h3>\n<p>Kafka\u4e2d\u53d1\u5e03\u8ba2\u9605\u7684\u5bf9\u8c61\u662ftopic\u3002\u6211\u4eec\u53ef\u4ee5\u4e3a\u6bcf\u7c7b\u6570\u636e\u521b\u5efa\u4e00\u4e2atopic\uff0c\u628a\u5411topic\u53d1\u5e03\u6d88\u606f\u7684\u5ba2\u6237\u7aef\u79f0\u4f5cproducer\uff0c\u4ecetopic\u8ba2\u9605\u6d88\u606f\u7684\u5ba2\u6237\u7aef\u79f0\u4f5cconsumer\u3002Producers\u548cconsumers\u53ef\u4ee5\u540c\u65f6\u4ece\u591a\u4e2atopic\u8bfb\u5199\u6570\u636e\u3002\u4e00\u4e2akafka\u96c6\u7fa4\u7531\u4e00\u4e2a\u6216\u591a\u4e2abroker\u670d\u52a1\u5668\u7ec4\u6210\uff0c\u5b83\u8d1f\u8d23\u6301\u4e45\u5316\u548c\u5907\u4efd\u5177\u4f53\u7684kafka\u6d88\u606f\u3002<\/p>\n<ul>\n<li>topic\uff1a\u6d88\u606f\u5b58\u653e\u7684\u76ee\u5f55\u5373\u4e3b\u9898<\/li>\n<li>Producer\uff1a\u751f\u4ea7\u6d88\u606f\u5230topic\u7684\u4e00\u65b9<\/li>\n<li>Consumer\uff1a\u8ba2\u9605topic\u6d88\u8d39\u6d88\u606f\u7684\u4e00\u65b9<\/li>\n<li>Broker\uff1aKafka\u7684\u670d\u52a1\u5b9e\u4f8b\u5c31\u662f\u4e00\u4e2abroker<\/li>\n<\/ul>\n<p><img decoding=\"async\" title=\"\" src=\"http:\/\/kafka.apache.org\/images\/producer_consumer.png\" alt=\"\" \/><\/p>\n<h3 id=\"25-kafka-topicpartition\"><a name=\"t9\"><\/a>2.5 Kafka Topic&amp;Partition<\/h3>\n<p>\u6d88\u606f\u53d1\u9001\u65f6\u90fd\u88ab\u53d1\u9001\u5230\u4e00\u4e2atopic\uff0c\u5176\u672c\u8d28\u5c31\u662f\u4e00\u4e2a\u76ee\u5f55\uff0c\u800ctopic\u7531\u662f\u7531\u4e00\u4e9bPartition Logs(\u5206\u533a\u65e5\u5fd7)\u7ec4\u6210,\u5176\u7ec4\u7ec7\u7ed3\u6784\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"http:\/\/kafka.apache.org\/images\/log_anatomy.png\" alt=\"\" \/><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u6bcf\u4e2aPartition\u4e2d\u7684\u6d88\u606f\u90fd\u662f\u6709\u5e8f\u7684\uff0c\u751f\u4ea7\u7684\u6d88\u606f\u88ab\u4e0d\u65ad\u8ffd\u52a0\u5230Partition log\u4e0a\uff0c\u5176\u4e2d\u7684\u6bcf\u4e00\u4e2a\u6d88\u606f\u90fd\u88ab\u8d4b\u4e88\u4e86\u4e00\u4e2a\u552f\u4e00\u7684offset\u503c\u3002<br \/>\nKafka\u96c6\u7fa4\u4f1a\u4fdd\u5b58\u6240\u6709\u7684\u6d88\u606f\uff0c\u4e0d\u7ba1\u6d88\u606f\u6709\u6ca1\u6709\u88ab\u6d88\u8d39\uff1b\u6211\u4eec\u53ef\u4ee5\u8bbe\u5b9a\u6d88\u606f\u7684\u8fc7\u671f\u65f6\u95f4\uff0c\u53ea\u6709\u8fc7\u671f\u7684\u6570\u636e\u624d\u4f1a\u88ab\u81ea\u52a8\u6e05\u9664\u4ee5\u91ca\u653e\u78c1\u76d8\u7a7a\u95f4\u3002\u6bd4\u5982\u6211\u4eec\u8bbe\u7f6e\u6d88\u606f\u8fc7\u671f\u65f6\u95f4\u4e3a2\u5929\uff0c\u90a3\u4e48\u8fd92\u5929\u5185\u7684\u6240\u6709\u6d88\u606f\u90fd\u4f1a\u88ab\u4fdd\u5b58\u5230\u96c6\u7fa4\u4e2d\uff0c\u6570\u636e\u53ea\u6709\u8d85\u8fc7\u4e86\u4e24\u5929\u624d\u4f1a\u88ab\u6e05\u9664\u3002<br \/>\nKafka\u9700\u8981\u7ef4\u6301\u7684\u5143\u6570\u636e\u53ea\u6709\u4e00\u4e2a\u2013\u6d88\u8d39\u6d88\u606f\u5728Partition\u4e2d\u7684offset\u503c\uff0cConsumer\u6bcf\u6d88\u8d39\u4e00\u4e2a\u6d88\u606f\uff0coffset\u5c31\u4f1a\u52a01\u3002\u5176\u5b9e\u6d88\u606f\u7684\u72b6\u6001\u5b8c\u5168\u662f\u7531Consumer\u63a7\u5236\u7684\uff0cConsumer\u53ef\u4ee5\u8ddf\u8e2a\u548c\u91cd\u8bbe\u8fd9\u4e2aoffset\u503c\uff0c\u8fd9\u6837\u7684\u8bddConsumer\u5c31\u53ef\u4ee5\u8bfb\u53d6\u4efb\u610f\u4f4d\u7f6e\u7684\u6d88\u606f\u3002<br \/>\n\u628a\u6d88\u606f\u65e5\u5fd7\u4ee5Partition\u7684\u5f62\u5f0f\u5b58\u653e\u6709\u591a\u91cd\u8003\u8651\uff0c\u7b2c\u4e00\uff0c\u65b9\u4fbf\u5728\u96c6\u7fa4\u4e2d\u6269\u5c55\uff0c\u6bcf\u4e2aPartition\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574\u4ee5\u9002\u5e94\u5b83\u6240\u5728\u7684\u673a\u5668\uff0c\u800c\u4e00\u4e2atopic\u53c8\u53ef\u4ee5\u6709\u591a\u4e2aPartition\u7ec4\u6210\uff0c\u56e0\u6b64\u6574\u4e2a\u96c6\u7fa4\u5c31\u53ef\u4ee5\u9002\u5e94\u4efb\u610f\u5927\u5c0f\u7684\u6570\u636e\u4e86\uff1b\u7b2c\u4e8c\u5c31\u662f\u53ef\u4ee5\u63d0\u9ad8\u5e76\u53d1\uff0c\u56e0\u4e3a\u53ef\u4ee5\u4ee5Partition\u4e3a\u5355\u4f4d\u8bfb\u5199\u4e86\u3002<\/p>\n<h2 id=\"\u4e09kafka-\u6838\u5fc3\u7ec4\u4ef6\"><a name=\"t10\"><\/a>\u4e09\u3001Kafka \u6838\u5fc3\u7ec4\u4ef6<\/h2>\n<h3 id=\"31-replicationspartitions-\u548cleaders\"><a name=\"t11\"><\/a>3.1 Replications\u3001Partitions \u548cLeaders<\/h3>\n<p>\u901a\u8fc7\u4e0a\u9762\u4ecb\u7ecd\u7684\u6211\u4eec\u53ef\u4ee5\u77e5\u9053\uff0ckafka\u4e2d\u7684\u6570\u636e\u662f\u6301\u4e45\u5316\u7684\u5e76\u4e14\u80fd\u591f\u5bb9\u9519\u7684\u3002Kafka\u5141\u8bb8\u7528\u6237\u4e3a\u6bcf\u4e2atopic\u8bbe\u7f6e\u526f\u672c\u6570\u91cf\uff0c\u526f\u672c\u6570\u91cf\u51b3\u5b9a\u4e86\u6709\u51e0\u4e2abroker\u6765\u5b58\u653e\u5199\u5165\u7684\u6570\u636e\u3002\u5982\u679c\u4f60\u7684\u526f\u672c\u6570\u91cf\u8bbe\u7f6e\u4e3a3\uff0c\u90a3\u4e48\u4e00\u4efd\u6570\u636e\u5c31\u4f1a\u88ab\u5b58\u653e\u57283\u53f0\u4e0d\u540c\u7684\u673a\u5668\u4e0a\uff0c\u90a3\u4e48\u5c31\u5141\u8bb8\u67092\u4e2a\u673a\u5668\u5931\u8d25\u3002\u4e00\u822c\u63a8\u8350\u526f\u672c\u6570\u91cf\u81f3\u5c11\u4e3a2\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u4fdd\u8bc1\u589e\u51cf\u3001\u91cd\u542f\u673a\u5668\u65f6\u4e0d\u4f1a\u5f71\u54cd\u5230\u6570\u636e\u6d88\u8d39\u3002\u5982\u679c\u5bf9\u6570\u636e\u6301\u4e45\u5316\u6709\u66f4\u9ad8\u7684\u8981\u6c42\uff0c\u53ef\u4ee5\u628a\u526f\u672c\u6570\u91cf\u8bbe\u7f6e\u4e3a3\u6216\u8005\u66f4\u591a\u3002<br \/>\nKafka\u4e2d\u7684topic\u662f\u4ee5partition\u7684\u5f62\u5f0f\u5b58\u653e\u7684\uff0c\u6bcf\u4e00\u4e2atopic\u90fd\u53ef\u4ee5\u8bbe\u7f6e\u5b83\u7684partition\u6570\u91cf\uff0cPartition\u7684\u6570\u91cf\u51b3\u5b9a\u4e86\u7ec4\u6210topic\u7684log\u7684\u6570\u91cf\u3002Producer\u5728\u751f\u4ea7\u6570\u636e\u65f6\uff0c\u4f1a\u6309\u7167\u4e00\u5b9a\u89c4\u5219\uff08\u8fd9\u4e2a\u89c4\u5219\u662f\u53ef\u4ee5\u81ea\u5b9a\u4e49\u7684\uff09\u628a\u6d88\u606f\u53d1\u5e03\u5230topic\u7684\u5404\u4e2apartition\u4e2d\u3002\u4e0a\u9762\u5c06\u7684\u526f\u672c\u90fd\u662f\u4ee5partition\u4e3a\u5355\u4f4d\u7684\uff0c\u4e0d\u8fc7\u53ea\u6709\u4e00\u4e2apartition\u7684\u526f\u672c\u4f1a\u88ab\u9009\u4e3e\u6210leader\u4f5c\u4e3a\u8bfb\u5199\u7528\u3002<br \/>\n\u5173\u4e8e\u5982\u4f55\u8bbe\u7f6epartition\u503c\u9700\u8981\u8003\u8651\u7684\u56e0\u7d20\u3002\u4e00\u4e2apartition\u53ea\u80fd\u88ab\u4e00\u4e2a\u6d88\u8d39\u8005\u6d88\u8d39\uff08\u4e00\u4e2a\u6d88\u8d39\u8005\u53ef\u4ee5\u540c\u65f6\u6d88\u8d39\u591a\u4e2apartition\uff09\uff0c\u56e0\u6b64\uff0c\u5982\u679c\u8bbe\u7f6e\u7684partition\u7684\u6570\u91cf\u5c0f\u4e8econsumer\u7684\u6570\u91cf\uff0c\u5c31\u4f1a\u6709\u6d88\u8d39\u8005\u6d88\u8d39\u4e0d\u5230\u6570\u636e\u3002\u6240\u4ee5\uff0c\u63a8\u8350partition\u7684\u6570\u91cf\u4e00\u5b9a\u8981\u5927\u4e8e\u540c\u65f6\u8fd0\u884c\u7684consumer\u7684\u6570\u91cf\u3002\u53e6\u5916\u4e00\u65b9\u9762\uff0c\u5efa\u8baepartition\u7684\u6570\u91cf\u5927\u4e8e\u96c6\u7fa4broker\u7684\u6570\u91cf\uff0c\u8fd9\u6837leader partition\u5c31\u53ef\u4ee5\u5747\u5300\u7684\u5206\u5e03\u5728\u5404\u4e2abroker\u4e2d\uff0c\u6700\u7ec8\u4f7f\u5f97\u96c6\u7fa4\u8d1f\u8f7d\u5747\u8861\u3002\u5728Cloudera,\u6bcf\u4e2atopic\u90fd\u6709\u4e0a\u767e\u4e2apartition\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0ckafka\u9700\u8981\u4e3a\u6bcf\u4e2apartition\u5206\u914d\u4e00\u4e9b\u5185\u5b58\u6765\u7f13\u5b58\u6d88\u606f\u6570\u636e\uff0c\u5982\u679cpartition\u6570\u91cf\u8d8a\u5927\uff0c\u5c31\u8981\u4e3akafka\u5206\u914d\u66f4\u5927\u7684heap space\u3002<\/p>\n<h3 id=\"32-producers\"><a name=\"t12\"><\/a>3.2 Producers<\/h3>\n<p>Producers\u76f4\u63a5\u53d1\u9001\u6d88\u606f\u5230broker\u4e0a\u7684leader partition\uff0c\u4e0d\u9700\u8981\u7ecf\u8fc7\u4efb\u4f55\u4e2d\u4ecb\u4e00\u7cfb\u5217\u7684\u8def\u7531\u8f6c\u53d1\u3002\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e2a\u7279\u6027\uff0ckafka\u96c6\u7fa4\u4e2d\u7684\u6bcf\u4e2abroker\u90fd\u53ef\u4ee5\u54cd\u5e94producer\u7684\u8bf7\u6c42\uff0c\u5e76\u8fd4\u56detopic\u7684\u4e00\u4e9b\u5143\u4fe1\u606f\uff0c\u8fd9\u4e9b\u5143\u4fe1\u606f\u5305\u62ec\u54ea\u4e9b\u673a\u5668\u662f\u5b58\u6d3b\u7684\uff0ctopic\u7684leader partition\u90fd\u5728\u54ea\uff0c\u73b0\u9636\u6bb5\u54ea\u4e9bleader partition\u662f\u53ef\u4ee5\u76f4\u63a5\u88ab\u8bbf\u95ee\u7684\u3002<br \/>\nProducer\u5ba2\u6237\u7aef\u81ea\u5df1\u63a7\u5236\u7740\u6d88\u606f\u88ab\u63a8\u9001\u5230\u54ea\u4e9bpartition\u3002\u5b9e\u73b0\u7684\u65b9\u5f0f\u53ef\u4ee5\u662f\u968f\u673a\u5206\u914d\u3001\u5b9e\u73b0\u4e00\u7c7b\u968f\u673a\u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\uff0c\u6216\u8005\u6307\u5b9a\u4e00\u4e9b\u5206\u533a\u7b97\u6cd5\u3002Kafka\u63d0\u4f9b\u4e86\u63a5\u53e3\u4f9b\u7528\u6237\u5b9e\u73b0\u81ea\u5b9a\u4e49\u7684\u5206\u533a\uff0c\u7528\u6237\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u6d88\u606f\u6307\u5b9a\u4e00\u4e2apartitionKey\uff0c\u901a\u8fc7\u8fd9\u4e2akey\u6765\u5b9e\u73b0\u4e00\u4e9bhash\u5206\u533a\u7b97\u6cd5\u3002\u6bd4\u5982\uff0c\u628auserid\u4f5c\u4e3apartitionkey\u7684\u8bdd\uff0c\u76f8\u540cuserid\u7684\u6d88\u606f\u5c06\u4f1a\u88ab\u63a8\u9001\u5230\u540c\u4e00\u4e2a\u5206\u533a\u3002<br \/>\n\u4ee5Batch\u7684\u65b9\u5f0f\u63a8\u9001\u6570\u636e\u53ef\u4ee5\u6781\u5927\u7684\u63d0\u9ad8\u5904\u7406\u6548\u7387\uff0ckafka Producer \u53ef\u4ee5\u5c06\u6d88\u606f\u5728\u5185\u5b58\u4e2d\u7d2f\u8ba1\u5230\u4e00\u5b9a\u6570\u91cf\u540e\u4f5c\u4e3a\u4e00\u4e2abatch\u53d1\u9001\u8bf7\u6c42\u3002Batch\u7684\u6570\u91cf\u5927\u5c0f\u53ef\u4ee5\u901a\u8fc7Producer\u7684\u53c2\u6570\u63a7\u5236\uff0c\u53c2\u6570\u503c\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u7d2f\u8ba1\u7684\u6d88\u606f\u7684\u6570\u91cf\uff08\u5982500\u6761\uff09\u3001\u7d2f\u8ba1\u7684\u65f6\u95f4\u95f4\u9694\uff08\u5982100ms\uff09\u6216\u8005\u7d2f\u8ba1\u7684\u6570\u636e\u5927\u5c0f(64KB)\u3002\u901a\u8fc7\u589e\u52a0batch\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u51cf\u5c11\u7f51\u7edc\u8bf7\u6c42\u548c\u78c1\u76d8IO\u7684\u6b21\u6570\uff0c\u5f53\u7136\u5177\u4f53\u53c2\u6570\u8bbe\u7f6e\u9700\u8981\u5728\u6548\u7387\u548c\u65f6\u6548\u6027\u65b9\u9762\u505a\u4e00\u4e2a\u6743\u8861\u3002<br \/>\nProducers\u53ef\u4ee5\u5f02\u6b65\u7684\u5e76\u884c\u7684\u5411kafka\u53d1\u9001\u6d88\u606f\uff0c\u4f46\u662f\u901a\u5e38producer\u5728\u53d1\u9001\u5b8c\u6d88\u606f\u4e4b\u540e\u4f1a\u5f97\u5230\u4e00\u4e2afuture\u54cd\u5e94\uff0c\u8fd4\u56de\u7684\u662foffset\u503c\u6216\u8005\u53d1\u9001\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u9519\u8bef\u3002\u8fd9\u5176\u4e2d\u6709\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u53c2\u6570\u201cacks\u201d,\u8fd9\u4e2a\u53c2\u6570\u51b3\u5b9a\u4e86producer\u8981\u6c42leader partition \u6536\u5230\u786e\u8ba4\u7684\u526f\u672c\u4e2a\u6570\uff0c\u5982\u679cacks\u8bbe\u7f6e\u6570\u91cf\u4e3a0\uff0c\u8868\u793aproducer\u4e0d\u4f1a\u7b49\u5f85broker\u7684\u54cd\u5e94\uff0c\u6240\u4ee5\uff0cproducer\u65e0\u6cd5\u77e5\u9053\u6d88\u606f\u662f\u5426\u53d1\u9001\u6210\u529f\uff0c\u8fd9\u6837\u6709\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u4e22\u5931\uff0c\u4f46\u540c\u65f6\uff0cacks\u503c\u4e3a0\u4f1a\u5f97\u5230\u6700\u5927\u7684\u7cfb\u7edf\u541e\u5410\u91cf\u3002<br \/>\n\u82e5acks\u8bbe\u7f6e\u4e3a1\uff0c\u8868\u793aproducer\u4f1a\u5728leader partition\u6536\u5230\u6d88\u606f\u65f6\u5f97\u5230broker\u7684\u4e00\u4e2a\u786e\u8ba4\uff0c\u8fd9\u6837\u4f1a\u6709\u66f4\u597d\u7684\u53ef\u9760\u6027\uff0c\u56e0\u4e3a\u5ba2\u6237\u7aef\u4f1a\u7b49\u5f85\u76f4\u5230broker\u786e\u8ba4\u6536\u5230\u6d88\u606f\u3002\u82e5\u8bbe\u7f6e\u4e3a-1\uff0cproducer\u4f1a\u5728\u6240\u6709\u5907\u4efd\u7684partition\u6536\u5230\u6d88\u606f\u65f6\u5f97\u5230broker\u7684\u786e\u8ba4\uff0c\u8fd9\u4e2a\u8bbe\u7f6e\u53ef\u4ee5\u5f97\u5230\u6700\u9ad8\u7684\u53ef\u9760\u6027\u4fdd\u8bc1\u3002<br \/>\nKafka \u6d88\u606f\u6709\u4e00\u4e2a\u5b9a\u957f\u7684header\u548c\u53d8\u957f\u7684\u5b57\u8282\u6570\u7ec4\u7ec4\u6210\u3002\u56e0\u4e3akafka\u6d88\u606f\u652f\u6301\u5b57\u8282\u6570\u7ec4\uff0c\u4e5f\u5c31\u4f7f\u5f97kafka\u53ef\u4ee5\u652f\u6301\u4efb\u4f55\u7528\u6237\u81ea\u5b9a\u4e49\u7684\u5e8f\u5217\u53f7\u683c\u5f0f\u6216\u8005\u5176\u5b83\u5df2\u6709\u7684\u683c\u5f0f\u5982Apache Avro\u3001protobuf\u7b49\u3002Kafka\u6ca1\u6709\u9650\u5b9a\u5355\u4e2a\u6d88\u606f\u7684\u5927\u5c0f\uff0c\u4f46\u6211\u4eec\u63a8\u8350\u6d88\u606f\u5927\u5c0f\u4e0d\u8981\u8d85\u8fc71MB,\u901a\u5e38\u4e00\u822c\u6d88\u606f\u5927\u5c0f\u90fd\u57281~10kB\u4e4b\u524d\u3002<\/p>\n<h3 id=\"33-consumers\"><a name=\"t13\"><\/a>3.3 Consumers<\/h3>\n<p>Kafka\u63d0\u4f9b\u4e86\u4e24\u5957consumer api\uff0c\u5206\u4e3ahigh-level api\u548csample-api\u3002Sample-api \u662f\u4e00\u4e2a\u5e95\u5c42\u7684API\uff0c\u5b83\u7ef4\u6301\u4e86\u4e00\u4e2a\u548c\u5355\u4e00broker\u7684\u8fde\u63a5\uff0c\u5e76\u4e14\u8fd9\u4e2aAPI\u662f\u5b8c\u5168\u65e0\u72b6\u6001\u7684\uff0c\u6bcf\u6b21\u8bf7\u6c42\u90fd\u9700\u8981\u6307\u5b9aoffset\u503c\uff0c\u56e0\u6b64\uff0c\u8fd9\u5957API\u4e5f\u662f\u6700\u7075\u6d3b\u7684\u3002<br \/>\n\u5728kafka\u4e2d\uff0c\u5f53\u524d\u8bfb\u5230\u6d88\u606f\u7684offset\u503c\u662f\u7531consumer\u6765\u7ef4\u62a4\u7684\uff0c\u56e0\u6b64\uff0cconsumer\u53ef\u4ee5\u81ea\u5df1\u51b3\u5b9a\u5982\u4f55\u8bfb\u53d6kafka\u4e2d\u7684\u6570\u636e\u3002\u6bd4\u5982\uff0cconsumer\u53ef\u4ee5\u901a\u8fc7\u91cd\u8bbeoffset\u503c\u6765\u91cd\u65b0\u6d88\u8d39\u5df2\u6d88\u8d39\u8fc7\u7684\u6570\u636e\u3002\u4e0d\u7ba1\u6709\u6ca1\u6709\u88ab\u6d88\u8d39\uff0ckafka\u4f1a\u4fdd\u5b58\u6570\u636e\u4e00\u6bb5\u65f6\u95f4\uff0c\u8fd9\u4e2a\u65f6\u95f4\u5468\u671f\u662f\u53ef\u914d\u7f6e\u7684\uff0c\u53ea\u6709\u5230\u4e86\u8fc7\u671f\u65f6\u95f4\uff0ckafka\u624d\u4f1a\u5220\u9664\u8fd9\u4e9b\u6570\u636e\u3002<br \/>\nHigh-level API\u5c01\u88c5\u4e86\u5bf9\u96c6\u7fa4\u4e2d\u4e00\u7cfb\u5217broker\u7684\u8bbf\u95ee\uff0c\u53ef\u4ee5\u900f\u660e\u7684\u6d88\u8d39\u4e00\u4e2atopic\u3002\u5b83\u81ea\u5df1\u7ef4\u6301\u4e86\u5df2\u6d88\u8d39\u6d88\u606f\u7684\u72b6\u6001\uff0c\u5373\u6bcf\u6b21\u6d88\u8d39\u7684\u90fd\u662f\u4e0b\u4e00\u4e2a\u6d88\u606f\u3002<br \/>\nHigh-level API\u8fd8\u652f\u6301\u4ee5\u7ec4\u7684\u5f62\u5f0f\u6d88\u8d39topic\uff0c\u5982\u679cconsumers\u6709\u540c\u4e00\u4e2a\u7ec4\u540d\uff0c\u90a3\u4e48kafka\u5c31\u76f8\u5f53\u4e8e\u4e00\u4e2a\u961f\u5217\u6d88\u606f\u670d\u52a1\uff0c\u800c\u5404\u4e2aconsumer\u5747\u8861\u7684\u6d88\u8d39\u76f8\u5e94partition\u4e2d\u7684\u6570\u636e\u3002\u82e5consumers\u6709\u4e0d\u540c\u7684\u7ec4\u540d\uff0c\u90a3\u4e48\u6b64\u65f6kafka\u5c31\u76f8\u5f53\u4e0e\u4e00\u4e2a\u5e7f\u64ad\u670d\u52a1\uff0c\u4f1a\u628atopic\u4e2d\u7684\u6240\u6709\u6d88\u606f\u5e7f\u64ad\u5230\u6bcf\u4e2aconsumer\u3002<br \/>\n<img decoding=\"async\" title=\"\" src=\"http:\/\/kafka.apache.org\/images\/consumer-groups.png\" alt=\"\" \/><\/p>\n<h2 id=\"\u56dbkafka\u6838\u5fc3\u7279\u6027\"><a name=\"t14\"><\/a>\u56db\u3001Kafka\u6838\u5fc3\u7279\u6027<\/h2>\n<h3 id=\"41-\u538b\u7f29\"><a name=\"t15\"><\/a>4.1 \u538b\u7f29<\/h3>\n<p>\u6211\u4eec\u4e0a\u9762\u5df2\u7ecf\u77e5\u9053\u4e86Kafka\u652f\u6301\u4ee5\u96c6\u5408\uff08batch\uff09\u4e3a\u5355\u4f4d\u53d1\u9001\u6d88\u606f\uff0c\u5728\u6b64\u57fa\u7840\u4e0a\uff0cKafka\u8fd8\u652f\u6301\u5bf9\u6d88\u606f\u96c6\u5408\u8fdb\u884c\u538b\u7f29\uff0cProducer\u7aef\u53ef\u4ee5\u901a\u8fc7GZIP\u6216Snappy\u683c\u5f0f\u5bf9\u6d88\u606f\u96c6\u5408\u8fdb\u884c\u538b\u7f29\u3002Producer\u7aef\u8fdb\u884c\u538b\u7f29\u4e4b\u540e\uff0c\u5728Consumer\u7aef\u9700\u8fdb\u884c\u89e3\u538b\u3002\u538b\u7f29\u7684\u597d\u5904\u5c31\u662f\u51cf\u5c11\u4f20\u8f93\u7684\u6570\u636e\u91cf\uff0c\u51cf\u8f7b\u5bf9\u7f51\u7edc\u4f20\u8f93\u7684\u538b\u529b\uff0c\u5728\u5bf9\u5927\u6570\u636e\u5904\u7406\u4e0a\uff0c\u74f6\u9888\u5f80\u5f80\u4f53\u73b0\u5728\u7f51\u7edc\u4e0a\u800c\u4e0d\u662fCPU\uff08\u538b\u7f29\u548c\u89e3\u538b\u4f1a\u8017\u6389\u90e8\u5206CPU\u8d44\u6e90\uff09\u3002<br \/>\n\u90a3\u4e48\u5982\u4f55\u533a\u5206\u6d88\u606f\u662f\u538b\u7f29\u7684\u8fd8\u662f\u672a\u538b\u7f29\u7684\u5462\uff0cKafka\u5728\u6d88\u606f\u5934\u90e8\u6dfb\u52a0\u4e86\u4e00\u4e2a\u63cf\u8ff0\u538b\u7f29\u5c5e\u6027\u5b57\u8282\uff0c\u8fd9\u4e2a\u5b57\u8282\u7684\u540e\u4e24\u4f4d\u8868\u793a\u6d88\u606f\u7684\u538b\u7f29\u91c7\u7528\u7684\u7f16\u7801\uff0c\u5982\u679c\u540e\u4e24\u4f4d\u4e3a0\uff0c\u5219\u8868\u793a\u6d88\u606f\u672a\u88ab\u538b\u7f29\u3002<\/p>\n<h3 id=\"42\u6d88\u606f\u53ef\u9760\u6027\"><a name=\"t16\"><\/a>4.2\u6d88\u606f\u53ef\u9760\u6027<\/h3>\n<p>\u5728\u6d88\u606f\u7cfb\u7edf\u4e2d\uff0c\u4fdd\u8bc1\u6d88\u606f\u5728\u751f\u4ea7\u548c\u6d88\u8d39\u8fc7\u7a0b\u4e2d\u7684\u53ef\u9760\u6027\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u5728\u5b9e\u9645\u6d88\u606f\u4f20\u9012\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u5982\u4e0b\u4e09\u4e2d\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>\u4e00\u4e2a\u6d88\u606f\u53d1\u9001\u5931\u8d25<\/li>\n<li>\u4e00\u4e2a\u6d88\u606f\u88ab\u53d1\u9001\u591a\u6b21<\/li>\n<li>\u6700\u7406\u60f3\u7684\u60c5\u51b5\uff1aexactly-once ,\u4e00\u4e2a\u6d88\u606f\u53d1\u9001\u6210\u529f\u4e14\u4ec5\u53d1\u9001\u4e86\u4e00\u6b21<\/li>\n<\/ul>\n<p>\u6709\u8bb8\u591a\u7cfb\u7edf\u58f0\u79f0\u5b83\u4eec\u5b9e\u73b0\u4e86exactly-once\uff0c\u4f46\u662f\u5b83\u4eec\u5176\u5b9e\u5ffd\u7565\u4e86\u751f\u4ea7\u8005\u6216\u6d88\u8d39\u8005\u5728\u751f\u4ea7\u548c\u6d88\u8d39\u8fc7\u7a0b\u4e2d\u6709\u53ef\u80fd\u5931\u8d25\u7684\u60c5\u51b5\u3002\u6bd4\u5982\u867d\u7136\u4e00\u4e2aProducer\u6210\u529f\u53d1\u9001\u4e00\u4e2a\u6d88\u606f\uff0c\u4f46\u662f\u6d88\u606f\u5728\u53d1\u9001\u9014\u4e2d\u4e22\u5931\uff0c\u6216\u8005\u6210\u529f\u53d1\u9001\u5230broker\uff0c\u4e5f\u88abconsumer\u6210\u529f\u53d6\u8d70\uff0c\u4f46\u662f\u8fd9\u4e2aconsumer\u5728\u5904\u7406\u53d6\u8fc7\u6765\u7684\u6d88\u606f\u65f6\u5931\u8d25\u4e86\u3002<br \/>\n\u4eceProducer\u7aef\u770b\uff1aKafka\u662f\u8fd9\u4e48\u5904\u7406\u7684\uff0c\u5f53\u4e00\u4e2a\u6d88\u606f\u88ab\u53d1\u9001\u540e\uff0cProducer\u4f1a\u7b49\u5f85broker\u6210\u529f\u63a5\u6536\u5230\u6d88\u606f\u7684\u53cd\u9988\uff08\u53ef\u901a\u8fc7\u53c2\u6570\u63a7\u5236\u7b49\u5f85\u65f6\u95f4\uff09\uff0c\u5982\u679c\u6d88\u606f\u5728\u9014\u4e2d\u4e22\u5931\u6216\u662f\u5176\u4e2d\u4e00\u4e2abroker\u6302\u6389\uff0cProducer\u4f1a\u91cd\u65b0\u53d1\u9001\uff08\u6211\u4eec\u77e5\u9053Kafka\u6709\u5907\u4efd\u673a\u5236\uff0c\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u63a7\u5236\u662f\u5426\u7b49\u5f85\u6240\u6709\u5907\u4efd\u8282\u70b9\u90fd\u6536\u5230\u6d88\u606f\uff09\u3002<br \/>\n\u4eceConsumer\u7aef\u770b\uff1a\u524d\u9762\u8bb2\u5230\u8fc7partition\uff0cbroker\u7aef\u8bb0\u5f55\u4e86partition\u4e2d\u7684\u4e00\u4e2aoffset\u503c\uff0c\u8fd9\u4e2a\u503c\u6307\u5411Consumer\u4e0b\u4e00\u4e2a\u5373\u5c06\u6d88\u8d39message\u3002\u5f53Consumer\u6536\u5230\u4e86\u6d88\u606f\uff0c\u4f46\u5374\u5728\u5904\u7406\u8fc7\u7a0b\u4e2d\u6302\u6389\uff0c\u6b64\u65f6Consumer\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e2aoffset\u503c\u91cd\u65b0\u627e\u5230\u4e0a\u4e00\u4e2a\u6d88\u606f\u518d\u8fdb\u884c\u5904\u7406\u3002Consumer\u8fd8\u6709\u6743\u9650\u63a7\u5236\u8fd9\u4e2aoffset\u503c\uff0c\u5bf9\u6301\u4e45\u5316\u5230broker\u7aef\u7684\u6d88\u606f\u505a\u4efb\u610f\u5904\u7406\u3002<\/p>\n<h3 id=\"43-\u5907\u4efd\u673a\u5236\"><a name=\"t17\"><\/a>4.3 \u5907\u4efd\u673a\u5236<\/h3>\n<p>\u5907\u4efd\u673a\u5236\u662fKafka0.8\u7248\u672c\u7684\u65b0\u7279\u6027\uff0c\u5907\u4efd\u673a\u5236\u7684\u51fa\u73b0\u5927\u5927\u63d0\u9ad8\u4e86Kafka\u96c6\u7fa4\u7684\u53ef\u9760\u6027\u3001\u7a33\u5b9a\u6027\u3002\u6709\u4e86\u5907\u4efd\u673a\u5236\u540e\uff0cKafka\u5141\u8bb8\u96c6\u7fa4\u4e2d\u7684\u8282\u70b9\u6302\u6389\u540e\u800c\u4e0d\u5f71\u54cd\u6574\u4e2a\u96c6\u7fa4\u5de5\u4f5c\u3002\u4e00\u4e2a\u5907\u4efd\u6570\u91cf\u4e3an\u7684\u96c6\u7fa4\u5141\u8bb8n-1\u4e2a\u8282\u70b9\u5931\u8d25\u3002\u5728\u6240\u6709\u5907\u4efd\u8282\u70b9\u4e2d\uff0c\u6709\u4e00\u4e2a\u8282\u70b9\u4f5c\u4e3alead\u8282\u70b9\uff0c\u8fd9\u4e2a\u8282\u70b9\u4fdd\u5b58\u4e86\u5176\u5b83\u5907\u4efd\u8282\u70b9\u5217\u8868\uff0c\u5e76\u7ef4\u6301\u5404\u4e2a\u5907\u4efd\u95f4\u7684\u72b6\u4f53\u540c\u6b65\u3002\u4e0b\u9762\u8fd9\u5e45\u56fe\u89e3\u91ca\u4e86Kafka\u7684\u5907\u4efd\u673a\u5236:<\/p>\n<p><img decoding=\"async\" title=\"\" src=\"https:\/\/img-blog.csdn.net\/20150828162159461\" alt=\"\u8fd9\u91cc\u5199\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3 id=\"44-kafka\u9ad8\u6548\u6027\u76f8\u5173\u8bbe\u8ba1\"><a name=\"t18\"><\/a>4.4 Kafka\u9ad8\u6548\u6027\u76f8\u5173\u8bbe\u8ba1<\/h3>\n<h4 id=\"441-\u6d88\u606f\u7684\u6301\u4e45\u5316\">4.4.1 \u6d88\u606f\u7684\u6301\u4e45\u5316<\/h4>\n<p>Kafka\u9ad8\u5ea6\u4f9d\u8d56\u6587\u4ef6\u7cfb\u7edf\u6765\u5b58\u50a8\u548c\u7f13\u5b58\u6d88\u606f\uff0c\u4e00\u822c\u7684\u4eba\u8ba4\u4e3a\u78c1\u76d8\u662f\u7f13\u6162\u7684\uff0c\u8fd9\u5bfc\u81f4\u4eba\u4eec\u5bf9\u6301\u4e45\u5316\u7ed3\u6784\u5177\u6709\u7ade\u4e89\u6027\u6301\u6000\u7591\u6001\u5ea6\u3002\u5176\u5b9e\uff0c\u78c1\u76d8\u8fdc\u6bd4\u4f60\u60f3\u8c61\u7684\u8981\u5feb\u6216\u8005\u6162\uff0c\u8fd9\u51b3\u5b9a\u4e8e\u6211\u4eec\u5982\u4f55\u4f7f\u7528\u78c1\u76d8\u3002<br \/>\n\u4e00\u4e2a\u548c\u78c1\u76d8\u6027\u80fd\u6709\u5173\u7684\u5173\u952e\u4e8b\u5b9e\u662f\uff1a\u78c1\u76d8\u9a71\u52a8\u5668\u7684\u541e\u5410\u91cf\u8ddf\u5bfb\u5230\u5ef6\u8fdf\u662f\u76f8\u80cc\u79bb\u7684\uff0c\u4e5f\u5c31\u662f\u6240\uff0c\u7ebf\u6027\u5199\u7684\u901f\u5ea6\u8fdc\u8fdc\u5927\u4e8e\u968f\u673a\u5199\u3002\u6bd4\u5982\uff1a\u5728\u4e00\u4e2a6 7200rpm SATA RAID-5 \u7684\u78c1\u76d8\u9635\u5217\u4e0a\u7ebf\u6027\u5199\u7684\u901f\u5ea6\u5927\u6982\u662f600M\/\u79d2\uff0c\u4f46\u662f\u968f\u673a\u5199\u7684\u901f\u5ea6\u53ea\u6709100K\/\u79d2\uff0c\u4e24\u8005\u76f8\u5dee\u5c06\u8fd16000\u500d\u3002\u7ebf\u6027\u8bfb\u5199\u5728\u5927\u591a\u6570\u5e94\u7528\u573a\u666f\u4e0b\u662f\u53ef\u4ee5\u9884\u6d4b\u7684\uff0c\u56e0\u6b64\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5229\u7528read-ahead\u548cwrite-behind\u6280\u672f\u6765\u4ece\u5927\u7684\u6570\u636e\u5757\u4e2d\u9884\u53d6\u6570\u636e\uff0c\u6216\u8005\u5c06\u591a\u4e2a\u903b\u8f91\u4e0a\u7684\u5199\u64cd\u4f5c\u7ec4\u5408\u6210\u4e00\u4e2a\u5927\u5199\u7269\u7406\u5199\u64cd\u4f5c\u4e2d\u3002\u66f4\u591a\u7684\u8ba8\u8bba\u53ef\u4ee5\u5728<a href=\"http:\/\/queue.acm.org\/detail.cfm?id=1563874\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">ACMQueueArtical<\/a>\u4e2d\u627e\u5230\uff0c\u4ed6\u4eec\u53d1\u73b0\uff0c\u5bf9\u78c1\u76d8\u7684\u7ebf\u6027\u8bfb\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u6bd4\u5185\u5b58\u7684\u968f\u673a\u8bbf\u95ee\u8981\u5feb\u4e00\u4e9b\u3002<br \/>\n\u4e3a\u4e86\u8865\u507f\u8fd9\u4e2a\u6027\u80fd\u4e0a\u7684\u5206\u6b67\uff0c\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u90fd\u4f1a\u628a\u7a7a\u95f2\u7684\u5185\u5b58\u7528\u4f5c\u78c1\u76d8\u7f13\u5b58\uff0c\u5c3d\u7ba1\u5728\u5185\u5b58\u56de\u6536\u7684\u65f6\u5019\u4f1a\u6709\u4e00\u70b9\u6027\u80fd\u4e0a\u7684\u4ee3\u4ef7\u3002\u6240\u6709\u7684\u78c1\u76d8\u8bfb\u5199\u64cd\u4f5c\u4f1a\u5728\u8fd9\u4e2a\u7edf\u4e00\u7684\u7f13\u5b58\u4e0a\u8fdb\u884c\u3002<br \/>\n\u6b64\u5916\uff0c\u5982\u679c\u6211\u4eec\u662f\u5728JVM\u7684\u57fa\u7840\u4e0a\u6784\u5efa\u7684\uff0c\u719f\u6089java\u5185\u5b58\u5e94\u7528\u7ba1\u7406\u7684\u4eba\u5e94\u8be5\u6e05\u695a\u4ee5\u4e0b\u4e24\u4ef6\u4e8b\u60c5\uff1a<\/p>\n<ol>\n<li>\u4e00\u4e2a\u5bf9\u8c61\u7684\u5185\u5b58\u6d88\u8017\u662f\u975e\u5e38\u9ad8\u7684\uff0c\u7ecf\u5e38\u662f\u6240\u5b58\u6570\u636e\u7684\u4e24\u500d\u6216\u8005\u66f4\u591a\u3002<\/li>\n<li>\u968f\u7740\u5806\u5185\u6570\u636e\u7684\u589e\u591a\uff0cJava\u7684\u5783\u573e\u56de\u6536\u4f1a\u53d8\u5f97\u975e\u5e38\u6602\u8d35\u3002<\/li>\n<\/ol>\n<p>\u57fa\u4e8e\u8fd9\u4e9b\u4e8b\u5b9e\uff0c\u5229\u7528\u6587\u4ef6\u7cfb\u7edf\u5e76\u4e14\u4f9d\u9760\u9875\u7f13\u5b58\u6bd4\u7ef4\u62a4\u4e00\u4e2a\u5185\u5b58\u7f13\u5b58\u6216\u8005\u5176\u4ed6\u7ed3\u6784\u8981\u597d\u2014\u2014\u6211\u4eec\u81f3\u5c11\u8981\u4f7f\u5f97\u53ef\u7528\u7684\u7f13\u5b58\u52a0\u500d\uff0c\u901a\u8fc7\u81ea\u52a8\u8bbf\u95ee\u53ef\u7528\u5185\u5b58\uff0c\u5e76\u4e14\u901a\u8fc7\u5b58\u50a8\u66f4\u7d27\u51d1\u7684\u5b57\u8282\u7ed3\u6784\u800c\u4e0d\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u5c06\u6709\u53ef\u80fd\u518d\u6b21\u52a0\u500d\u3002\u8fd9\u4e48\u505a\u7684\u7ed3\u679c\u5c31\u662f\u5728\u4e00\u53f032GB\u7684\u673a\u5668\u4e0a\uff0c\u5982\u679c\u4e0d\u8003\u8651GC\u60e9\u7f5a\uff0c\u5c06\u6700\u591a\u670928-30GB\u7684\u7f13\u5b58\u3002\u6b64\u5916\uff0c\u8fd9\u4e9b\u7f13\u5b58\u5c06\u4f1a\u4e00\u76f4\u5b58\u5728\u5373\u4f7f\u670d\u52a1\u91cd\u542f\uff0c\u7136\u800c\u8fdb\u7a0b\u5185\u7f13\u5b58\u9700\u8981\u5728\u5185\u5b58\u4e2d\u91cd\u6784\uff0810GB\u7f13\u5b58\u9700\u8981\u82b1\u8d3910\u5206\u949f\uff09\u6216\u8005\u5b83\u9700\u8981\u4e00\u4e2a\u5b8c\u5168\u51b7\u7f13\u5b58\u542f\u52a8\uff08\u975e\u5e38\u5dee\u7684\u521d\u59cb\u5316\u6027\u80fd\uff09\u3002\u5b83\u540c\u65f6\u4e5f\u7b80\u5316\u4e86\u4ee3\u7801\uff0c\u56e0\u4e3a\u73b0\u5728\u6240\u6709\u7684\u7ef4\u62a4\u7f13\u5b58\u548c\u6587\u4ef6\u7cfb\u7edf\u4e4b\u95f4\u5185\u805a\u7684\u903b\u8f91\u90fd\u5728\u64cd\u4f5c\u7cfb\u7edf\u5185\u90e8\u4e86\uff0c\u8fd9\u4f7f\u5f97\u8fd9\u6837\u505a\u6bd4one-off in-process attempts\u66f4\u52a0\u9ad8\u6548\u4e0e\u51c6\u786e\u3002\u5982\u679c\u4f60\u7684\u78c1\u76d8\u5e94\u7528\u66f4\u52a0\u503e\u5411\u4e8e\u987a\u5e8f\u8bfb\u53d6\uff0c\u90a3\u4e48read-ahead\u5728\u6bcf\u6b21\u78c1\u76d8\u8bfb\u53d6\u4e2d\u5b9e\u9645\u4e0a\u83b7\u53d6\u5230\u8fd9\u4eba\u7f13\u5b58\u4e2d\u7684\u6709\u7528\u6570\u636e\u3002<br \/>\n\u4ee5\u4e0a\u8fd9\u4e9b\u5efa\u8bae\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u8bbe\u8ba1\uff1a\u4e0d\u540c\u4e8e\u7ef4\u62a4\u5c3d\u53ef\u80fd\u591a\u7684\u5185\u5b58\u7f13\u5b58\u5e76\u4e14\u5728\u9700\u8981\u7684\u65f6\u5019\u5237\u65b0\u5230\u6587\u4ef6\u7cfb\u7edf\u4e2d\uff0c\u6211\u4eec\u6362\u4e00\u79cd\u601d\u8def\u3002\u6240\u6709\u7684\u6570\u636e\u4e0d\u9700\u8981\u8c03\u7528\u5237\u65b0\u7a0b\u5e8f\uff0c\u800c\u662f\u7acb\u523b\u5c06\u5b83\u5199\u5230\u4e00\u4e2a\u6301\u4e45\u5316\u7684\u65e5\u5fd7\u4e2d\u3002\u4e8b\u5b9e\u4e0a\uff0c\u8fd9\u4ec5\u4ec5\u610f\u5473\u7740\uff0c\u6570\u636e\u5c06\u88ab\u4f20\u8f93\u5230\u5185\u6838\u9875\u7f13\u5b58\u4e2d\u5e76\u7a0d\u540e\u88ab\u5237\u65b0\u3002\u6211\u4eec\u53ef\u4ee5\u589e\u52a0\u4e00\u4e2a\u914d\u7f6e\u9879\u4ee5\u8ba9\u7cfb\u7edf\u7684\u7528\u6237\u6765\u63a7\u5236\u6570\u636e\u5728\u4ec0\u4e48\u65f6\u5019\u88ab\u5237\u65b0\u5230\u7269\u7406\u786c\u76d8\u4e0a\u3002<\/p>\n<h4 id=\"442-\u5e38\u6570\u65f6\u95f4\u6027\u80fd\u4fdd\u8bc1\">4.4.2 \u5e38\u6570\u65f6\u95f4\u6027\u80fd\u4fdd\u8bc1<\/h4>\n<p>\u6d88\u606f\u7cfb\u7edf\u4e2d\u6301\u4e45\u5316\u6570\u636e\u7ed3\u6784\u7684\u8bbe\u8ba1\u901a\u5e38\u662f\u7ef4\u62a4\u8005\u4e00\u4e2a\u548c\u6d88\u8d39\u961f\u5217\u6709\u5173\u7684B\u6811\u6216\u8005\u5176\u5b83\u80fd\u591f\u968f\u673a\u5b58\u53d6\u7ed3\u6784\u7684\u5143\u6570\u636e\u4fe1\u606f\u3002B\u6811\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u5728\u4e8b\u52a1\u578b\u4e0e\u975e\u4e8b\u52a1\u578b\u7684\u8bed\u4e49\u4e2d\u3002\u4f46\u662f\u5b83\u9700\u8981\u4e00\u4e2a\u5f88\u9ad8\u7684\u82b1\u8d39\uff0c\u5c3d\u7ba1B\u6811\u7684\u64cd\u4f5c\u9700\u8981O(logN)\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u8fd9\u88ab\u8ba4\u4e3a\u4e0e\u5e38\u6570\u65f6\u95f4\u7b49\u4ef7\uff0c\u4f46\u8fd9\u5bf9\u78c1\u76d8\u64cd\u4f5c\u6765\u8bf4\u662f\u4e0d\u5bf9\u7684\u3002\u78c1\u76d8\u5bfb\u9053\u4e00\u6b21\u9700\u898110ms\uff0c\u5e76\u4e14\u4e00\u6b21\u53ea\u80fd\u5bfb\u4e00\u4e2a\uff0c\u56e0\u6b64\u5e76\u884c\u5316\u662f\u53d7\u9650\u7684\u3002<br \/>\n\u76f4\u89c9\u4e0a\u6765\u8bb2\uff0c\u4e00\u4e2a\u6301\u4e45\u5316\u7684\u961f\u5217\u53ef\u4ee5\u6784\u5efa\u5728\u5bf9\u4e00\u4e2a\u6587\u4ef6\u7684\u8bfb\u548c\u8ffd\u52a0\u4e0a\uff0c\u5c31\u50cf\u4e00\u822c\u60c5\u51b5\u4e0b\u7684\u65e5\u5fd7\u89e3\u51b3\u65b9\u6848\u3002\u5c3d\u7ba1\u548cB\u6811\u76f8\u6bd4\uff0c\u8fd9\u79cd\u7ed3\u6784\u4e0d\u80fd\u652f\u6301\u4e30\u5bcc\u7684\u8bed\u4e49\uff0c\u4f46\u662f\u5b83\u6709\u4e00\u4e2a\u4f18\u70b9\uff0c\u6240\u6709\u7684\u64cd\u4f5c\u90fd\u662f\u5e38\u6570\u65f6\u95f4\uff0c\u5e76\u4e14\u8bfb\u5199\u4e4b\u95f4\u4e0d\u4f1a\u76f8\u4e92\u963b\u585e\u3002\u8fd9\u79cd\u8bbe\u8ba1\u5177\u6709\u6781\u5927\u7684\u6027\u80fd\u4f18\u52bf\uff1a\u6700\u7ec8\u7cfb\u7edf\u6027\u80fd\u548c\u6570\u636e\u5927\u5c0f\u5b8c\u5168\u65e0\u5173\uff0c\u670d\u52a1\u5668\u53ef\u4ee5\u5145\u5206\u5229\u7528\u5ec9\u4ef7\u7684\u786c\u76d8\u6765\u63d0\u4f9b\u9ad8\u6548\u7684\u6d88\u606f\u670d\u52a1\u3002<br \/>\n\u4e8b\u5b9e\u4e0a\u8fd8\u6709\u4e00\u70b9\uff0c\u78c1\u76d8\u7a7a\u95f4\u7684\u65e0\u9650\u589e\u5927\u800c\u4e0d\u5f71\u54cd\u6027\u80fd\u8fd9\u70b9\uff0c\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u63d0\u4f9b\u4e00\u822c\u6d88\u606f\u7cfb\u7edf\u65e0\u6cd5\u63d0\u4f9b\u7684\u7279\u6027\u3002\u6bd4\u5982\u8bf4\uff0c\u6d88\u606f\u88ab\u6d88\u8d39\u540e\u4e0d\u662f\u7acb\u9a6c\u88ab\u5220\u9664\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6d88\u606f\u4fdd\u7559\u4e00\u6bb5\u76f8\u5bf9\u6bd4\u8f83\u957f\u7684\u65f6\u95f4\uff08\u6bd4\u5982\u4e00\u4e2a\u661f\u671f\uff09\u3002<\/p>\n<h4 id=\"443-\u8fdb\u4e00\u6b65\u63d0\u9ad8\u6548\u7387\">4.4.3 \u8fdb\u4e00\u6b65\u63d0\u9ad8\u6548\u7387<\/h4>\n<p>\u6211\u4eec\u5df2\u7ecf\u4e3a\u6548\u7387\u505a\u4e86\u975e\u5e38\u591a\u7684\u52aa\u529b\u3002\u4f46\u662f\u6709\u4e00\u79cd\u975e\u5e38\u4e3b\u8981\u7684\u5e94\u7528\u573a\u666f\u662f\uff1a\u5904\u7406Web\u6d3b\u52a8\u6570\u636e\uff0c\u5b83\u7684\u7279\u70b9\u662f\u6570\u636e\u91cf\u975e\u5e38\u5927\uff0c\u6bcf\u4e00\u6b21\u7684\u7f51\u9875\u6d4f\u89c8\u90fd\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u5199\u64cd\u4f5c\u3002<a href=\"https:\/\/www.baidu.com\/s?wd=%E6%9B%B4%E8%BF%9B%E4%B8%80%E6%AD%A5&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">\u66f4\u8fdb\u4e00\u6b65<\/a>\uff0c\u6211\u4eec\u5047\u8bbe\u6bcf\u4e00\u4e2a\u88ab\u53d1\u5e03\u7684\u6d88\u606f\u90fd\u4f1a\u88ab\u81f3\u5c11\u4e00\u4e2aconsumer\u6d88\u8d39\uff0c\u56e0\u6b64\u6211\u4eec\u66f4\u8981\u6012\u8def\u8ba9\u6d88\u8d39\u53d8\u5f97\u66f4\u5ec9\u4ef7\u3002<br \/>\n\u901a\u8fc7\u4e0a\u9762\u7684\u4ecb\u7ecd\uff0c\u6211\u4eec\u5df2\u7ecf\u89e3\u51b3\u4e86\u78c1\u76d8\u65b9\u9762\u7684\u6548\u7387\u95ee\u9898\uff0c\u9664\u6b64\u4e4b\u5916\uff0c\u5728\u6b64\u7c7b\u7cfb\u7edf\u4e2d\u8fd8\u6709\u4e24\u7c7b\u6bd4\u8f83\u4f4e\u6548\u7684\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\u592a\u591a\u5c0f\u7684I\/O\u64cd\u4f5c<\/li>\n<li>\u8fc7\u591a\u7684\u5b57\u8282\u62f7\u8d1d<\/li>\n<\/ul>\n<p>\u4e3a\u4e86\u51cf\u5c11\u5927\u91cf\u5c0fI\/O\u64cd\u4f5c\u7684\u95ee\u9898\uff0ckafka\u7684\u534f\u8bae\u662f\u56f4\u7ed5\u6d88\u606f\u96c6\u5408\u6784\u5efa\u7684\u3002Producer\u4e00\u6b21\u7f51\u7edc\u8bf7\u6c42\u53ef\u4ee5\u53d1\u9001\u4e00\u4e2a\u6d88\u606f\u96c6\u5408\uff0c\u800c\u4e0d\u662f\u6bcf\u4e00\u6b21\u53ea\u53d1\u4e00\u6761\u6d88\u606f\u3002\u5728server\u7aef\u662f\u4ee5\u6d88\u606f\u5757\u7684\u5f62\u5f0f\u8ffd\u52a0\u6d88\u606f\u5230log\u4e2d\u7684\uff0cconsumer\u5728\u67e5\u8be2\u7684\u65f6\u5019\u4e5f\u662f\u4e00\u6b21\u67e5\u8be2\u5927\u91cf\u7684\u7ebf\u6027\u6570\u636e\u5757\u3002\u6d88\u606f\u96c6\u5408\u5373MessageSet\uff0c\u5b9e\u73b0\u672c\u8eab\u662f\u4e00\u4e2a\u975e\u5e38\u7b80\u5355\u7684API\uff0c\u5b83\u5c06\u4e00\u4e2a\u5b57\u8282\u6570\u7ec4\u6216\u8005\u6587\u4ef6\u8fdb\u884c\u6253\u5305\u3002\u6240\u4ee5\u5bf9\u6d88\u606f\u7684\u5904\u7406\uff0c\u8fd9\u91cc\u6ca1\u6709\u5206\u5f00\u7684\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u7684\u4e0a\u6b65\u9aa4\uff0c\u6d88\u606f\u7684\u5b57\u6bb5\u53ef\u4ee5\u6309\u9700\u53cd\u5e8f\u5217\u5316\uff08\u5982\u679c\u6ca1\u6709\u9700\u8981\uff0c\u53ef\u4ee5\u4e0d\u7528\u53cd\u5e8f\u5217\u5316\uff09\u3002<br \/>\n\u53e6\u4e00\u4e2a\u5f71\u54cd\u6548\u7387\u7684\u95ee\u9898\u5c31\u662f\u5b57\u8282\u62f7\u8d1d\u3002\u4e3a\u4e86\u89e3\u51b3\u5b57\u8282\u62f7\u8d1d\u7684\u95ee\u9898\uff0ckafka\u8bbe\u8ba1\u4e86\u4e00\u79cd\u201c\u6807\u51c6\u5b57\u8282\u6d88\u606f\u201d\uff0cProducer\u3001Broker\u3001Consumer\u5171\u4eab\u8fd9\u4e00\u79cd\u6d88\u606f\u683c\u5f0f\u3002Kakfa\u7684message log\u5728broker\u7aef\u5c31\u662f\u4e00\u4e9b\u76ee\u5f55\u6587\u4ef6\uff0c\u8fd9\u4e9b\u65e5\u5fd7\u6587\u4ef6\u90fd\u662fMessageSet\u6309\u7167\u8fd9\u79cd\u201c\u6807\u51c6\u5b57\u8282\u6d88\u606f\u201d\u683c\u5f0f\u5199\u5165\u5230\u78c1\u76d8\u7684\u3002<br \/>\n\u7ef4\u6301\u8fd9\u79cd\u901a\u7528\u7684\u683c\u5f0f\u5bf9\u8fd9\u4e9b\u64cd\u4f5c\u7684\u4f18\u5316\u5c24\u4e3a\u91cd\u8981\uff1a\u6301\u4e45\u5316log \u5757\u7684\u7f51\u7edc\u4f20\u8f93\u3002\u6d41\u884c\u7684<a href=\"https:\/\/www.baidu.com\/s?wd=unix%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">unix\u64cd\u4f5c\u7cfb\u7edf<\/a>\u63d0\u4f9b\u4e86\u4e00\u79cd\u975e\u5e38\u9ad8\u6548\u7684\u9014\u5f84\u6765\u5b9e\u73b0\u9875\u9762\u7f13\u5b58\u548csocket\u4e4b\u95f4\u7684\u6570\u636e\u4f20\u9012\u3002\u5728<a href=\"https:\/\/www.baidu.com\/s?wd=Linux%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F&amp;tn=24004469_oem_dg&amp;rsv_dl=gh_pl_sl_csd\" target=\"_blank\" rel=\"noopener noreferrer\">Linux\u64cd\u4f5c\u7cfb\u7edf<\/a>\u4e2d\uff0c\u8fd9\u79cd\u65b9\u5f0f\u88ab\u79f0\u4f5c\uff1asendfile system call\uff08Java\u63d0\u4f9b\u4e86\u8bbf\u95ee\u8fd9\u4e2a\u7cfb\u7edf\u8c03\u7528\u7684\u65b9\u6cd5\uff1aFileChannel.transferTo api\uff09\u3002<\/p>\n<p>\u4e3a\u4e86\u7406\u89e3sendfile\u7684\u5f71\u54cd\uff0c\u9700\u8981\u7406\u89e3\u4e00\u822c\u7684\u5c06\u6570\u636e\u4ece\u6587\u4ef6\u4f20\u5230socket\u7684\u8def\u5f84\uff1a<\/p>\n<ol>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u5c06\u6570\u636e\u4ece\u78c1\u76d8\u8bfb\u5230\u5185\u6838\u7a7a\u95f4\u7684\u9875\u7f13\u5b58\u4e2d<\/li>\n<li>\u5e94\u7528\u5c06\u6570\u636e\u4ece\u5185\u6838\u7a7a\u95f4\u8bfb\u5230\u7528\u6237\u7a7a\u95f4\u7684\u7f13\u5b58\u4e2d<\/li>\n<li>\u5e94\u7528\u5c06\u6570\u636e\u5199\u56de\u5185\u6838\u7a7a\u95f4\u7684socket\u7f13\u5b58\u4e2d<\/li>\n<li>\u64cd\u4f5c\u7cfb\u7edf\u5c06\u6570\u636e\u4ecesocket\u7f13\u5b58\u5199\u5230\u7f51\u5361\u7f13\u5b58\u4e2d\uff0c\u4ee5\u4fbf\u5c06\u6570\u636e\u7ecf\u7f51\u7edc\u53d1\u51fa<\/li>\n<\/ol>\n<p>\u8fd9\u79cd\u64cd\u4f5c\u65b9\u5f0f\u660e\u663e\u662f\u975e\u5e38\u4f4e\u6548\u7684\uff0c\u8fd9\u91cc\u6709\u56db\u6b21\u62f7\u8d1d\uff0c\u4e24\u6b21\u7cfb\u7edf\u8c03\u7528\u3002\u5982\u679c\u4f7f\u7528sendfile\uff0c\u5c31\u53ef\u4ee5\u907f\u514d\u4e24\u6b21\u62f7\u8d1d\uff1a\u64cd\u4f5c\u7cfb\u7edf\u5c06\u6570\u636e\u76f4\u63a5\u4ece\u9875\u7f13\u5b58\u53d1\u9001\u5230\u7f51\u7edc\u4e0a\u3002\u6240\u4ee5\u5728\u8fd9\u4e2a\u4f18\u5316\u7684\u8def\u5f84\u4e2d\uff0c\u53ea\u6709\u6700\u540e\u4e00\u6b65\u5c06\u6570\u636e\u62f7\u8d1d\u5230\u7f51\u5361\u7f13\u5b58\u4e2d\u662f\u9700\u8981\u7684\u3002<br \/>\n\u6211\u4eec\u671f\u671b\u4e00\u4e2a\u4e3b\u9898\u4e0a\u6709\u591a\u4e2a\u6d88\u8d39\u8005\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u5e94\u7528\u573a\u666f\u3002\u5229\u7528\u4e0a\u8ff0\u7684zero-copy\uff0c\u6570\u636e\u53ea\u88ab\u62f7\u8d1d\u5230\u9875\u7f13\u5b58\u4e00\u6b21\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u5728\u6bcf\u6b21\u6d88\u8d39\u65f6\u88ab\u91cd\u5f97\u5229\u7528\uff0c\u800c\u4e0d\u9700\u8981\u5c06\u6570\u636e\u5b58\u5728\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u5728\u6bcf\u6b21\u8bfb\u7684\u65f6\u5019\u62f7\u8d1d\u5230\u5185\u6838\u7a7a\u95f4\u4e2d\u3002\u8fd9\u4f7f\u5f97\u6d88\u606f\u6d88\u8d39\u901f\u5ea6\u53ef\u4ee5\u8fbe\u5230\u7f51\u7edc\u8fde\u63a5\u7684\u901f\u5ea6\u3002\u8fd9\u6837\u4ee5\u6765\uff0c\u901a\u8fc7\u9875\u9762\u7f13\u5b58\u548csendfile\u7684\u7ed3\u5408\u4f7f\u7528\uff0c\u6574\u4e2akafka\u96c6\u7fa4\u51e0\u4e4e\u90fd\u5df2\u4ee5\u7f13\u5b58\u7684\u65b9\u5f0f\u63d0\u4f9b\u670d\u52a1\uff0c\u800c\u4e14\u5373\u4f7f\u4e0b\u6e38\u7684consumer\u5f88\u591a\uff0c\u4e5f\u4e0d\u4f1a\u5bf9\u6574\u4e2a\u96c6\u7fa4\u670d\u52a1\u9020\u6210\u538b\u529b\u3002<br \/>\n\u5173\u4e8esendfile\u548czero-copy\uff0c\u8bf7\u53c2\u8003\uff1a<a href=\"https:\/\/www.ibm.com\/developerworks\/linux\/library\/j-zerocopy\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">zero-copy<\/a><\/p>\n<h2 id=\"\u4e94kafka\u96c6\u7fa4\u90e8\u7f72\"><a name=\"t19\"><\/a>\u4e94\u3001Kafka\u96c6\u7fa4\u90e8\u7f72<\/h2>\n<h3 id=\"51-\u96c6\u7fa4\u90e8\u7f72\"><a name=\"t20\"><\/a>5.1 \u96c6\u7fa4\u90e8\u7f72<\/h3>\n<p>\u4e3a\u4e86\u63d0\u9ad8\u6027\u80fd\uff0c\u63a8\u8350\u91c7\u7528\u4e13\u7528\u7684\u670d\u52a1\u5668\u6765\u90e8\u7f72kafka\u96c6\u7fa4\uff0c\u5c3d\u91cf\u4e0ehadoop\u96c6\u7fa4\u5206\u5f00\uff0c\u56e0\u4e3akafka\u4f9d\u8d56\u78c1\u76d8\u8bfb\u5199\u548c\u5927\u7684\u9875\u9762\u7f13\u5b58\uff0c\u5982\u679c\u548chadoop\u5171\u4eab\u8282\u70b9\u7684\u8bdd\u4f1a\u5f71\u54cd\u5176\u4f7f\u7528\u9875\u9762\u7f13\u5b58\u7684\u6027\u80fd\u3002<br \/>\nKafka\u96c6\u7fa4\u7684\u5927\u5c0f\u9700\u8981\u6839\u636e\u786c\u4ef6\u7684\u914d\u7f6e\u3001\u751f\u4ea7\u8005\u6d88\u8d39\u8005\u7684\u5e76\u53d1\u6570\u91cf\u3001\u6570\u636e\u7684\u526f\u672c\u4e2a\u6570\u3001\u6570\u636e\u7684\u4fdd\u5b58\u65f6\u957f\u7efc\u5408\u786e\u5b9a\u3002<br \/>\n\u78c1\u76d8\u7684\u541e\u5410\u91cf\u5c24\u4e3a\u91cd\u8981\uff0c\u56e0\u4e3a\u901a\u5e38kafka\u7684\u74f6\u9888\u5c31\u5728\u78c1\u76d8\u4e0a\u3002<br \/>\nKafka\u4f9d\u8d56\u4e8ezookeeper\uff0c\u5efa\u8bae\u91c7\u7528\u4e13\u7528\u670d\u52a1\u5668\u6765\u90e8\u7f72zookeeper\u96c6\u7fa4\uff0czookeeper\u96c6\u7fa4\u7684\u8282\u70b9\u91c7\u7528\u5076\u6570\u4e2a\uff0c\u4e00\u822c\u5efa\u8bae\u75283\u30015\u30017\u4e2a\u3002\u6ce8\u610fzookeeper\u96c6\u7fa4\u8d8a\u5927\u5176\u8bfb\u5199\u6027\u80fd\u8d8a\u6162\uff0c\u56e0\u4e3azookeeper\u9700\u8981\u5728\u8282\u70b9\u4e4b\u95f4\u540c\u6b65\u6570\u636e\u3002\u4e00\u4e2a3\u8282\u70b9\u7684zookeeper\u96c6\u7fa4\u5141\u8bb8\u4e00\u4e2a\u8282\u70b9\u5931\u8d25\uff0c\u4e00\u4e2a5\u8282\u70b9\u96c6\u7fa4\u5141\u8bb82\u4e2a\u51e0\u70b9\u5931\u8d25\u3002<\/p>\n<h3 id=\"52-\u96c6\u7fa4\u5927\u5c0f\"><a name=\"t21\"><\/a>5.2 \u96c6\u7fa4\u5927\u5c0f<\/h3>\n<p>\u6709\u5f88\u591a\u56e0\u7d20\u51b3\u5b9a\u7740kafka\u96c6\u7fa4\u9700\u8981\u5177\u5907\u5b58\u50a8\u80fd\u529b\u7684\u5927\u5c0f\uff0c\u6700\u51c6\u786e\u7684\u8861\u91cf\u529e\u6cd5\u5c31\u662f\u6a21\u62df\u8d1f\u8f7d\u6765\u6d4b\u7b97\u4e00\u4e0b\uff0cKafka\u672c\u8eab\u4e5f\u63d0\u4f9b\u4e86\u8d1f\u8f7d\u6d4b\u8bd5\u7684\u5de5\u5177\u3002<br \/>\n\u5982\u679c\u4e0d\u60f3\u901a\u8fc7\u6a21\u62df\u5b9e\u9a8c\u6765\u8bc4\u4f30\u96c6\u7fa4\u5927\u5c0f\uff0c\u6700\u597d\u7684\u529e\u6cd5\u5c31\u662f\u6839\u636e\u786c\u76d8\u7684\u7a7a\u95f4\u9700\u6c42\u6765\u63a8\u7b97\u3002\u4e0b\u9762\u6211\u5c31\u6839\u636e\u7f51\u7edc\u548c\u78c1\u76d8\u541e\u5410\u91cf\u9700\u6c42\u6765\u505a\u4e00\u4e0b\u4f30\u7b97\u3002<br \/>\n\u6211\u4eec\u505a\u5982\u4e0b\u5047\u8bbe\uff1a<\/p>\n<ul>\n<li>W\uff1a\u6bcf\u79d2\u5199\u591a\u5c11MB<\/li>\n<li>R \uff1a\u526f\u672c\u6570<\/li>\n<li>C \uff1aConsumer\u7684\u6570\u91cf<\/li>\n<\/ul>\n<p>\u4e00\u822c\u7684\u6765\u8bf4\uff0ckafka\u96c6\u7fa4\u74f6\u9888\u5728\u4e8e\u7f51\u7edc\u548c\u78c1\u76d8\u541e\u5410\u91cf\uff0c\u6240\u4ee5\u6211\u4eec\u5148\u8bc4\u4f30\u4e00\u4e0b\u96c6\u7fa4\u7684\u7f51\u7edc\u548c\u78c1\u76d8\u9700\u6c42\u3002<br \/>\n\u5bf9\u4e8e\u6bcf\u6761\u6d88\u606f\uff0c\u6bcf\u4e2a\u526f\u672c\u90fd\u8981\u5199\u4e00\u904d\uff0c\u6240\u4ee5\u6574\u4f53\u5199\u7684\u901f\u5ea6\u662fW*R\u3002\u8bfb\u6570\u636e\u7684\u90e8\u5206\u4e3b\u8981\u662f\u96c6\u7fa4\u5185\u90e8\u5404\u4e2a\u526f\u672c\u4eceleader\u540c\u6b65\u6d88\u606f\u8bfb\u548c\u96c6\u7fa4\u5916\u90e8\u7684consumer\u8bfb\uff0c\u6240\u4ee5\u96c6\u7fa4\u5185\u90e8\u8bfb\u7684\u901f\u7387\u662f(R-1)*W,\u540c\u65f6\uff0c\u5916\u90e8consumer\u8bfb\u7684\u901f\u5ea6\u662fC*W\uff0c\u56e0\u6b64\uff1a<\/p>\n<ul>\n<li>Write\uff1aW*R<\/li>\n<li>Read\uff1a\uff08R-1\uff09*W+C*W<\/li>\n<\/ul>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6211\u4eec\u53ef\u4ee5\u5728\u8bfb\u7684\u65f6\u5019\u7f13\u5b58\u90e8\u5206\u6570\u636e\u6765\u51cf\u5c11IO\u64cd\u4f5c\uff0c\u5982\u679c\u4e00\u4e2a\u96c6\u7fa4\u6709M MB\u5185\u5b58\uff0c\u5199\u7684\u901f\u5ea6\u662fW MB\/sec\uff0c\u5219\u5141\u8bb8M\/(W*R) \u79d2\u7684\u5199\u53ef\u4ee5\u88ab\u7f13\u5b58\u3002\u5982\u679c\u96c6\u7fa4\u670932GB\u5185\u5b58\uff0c\u5199\u7684\u901f\u5ea6\u662f50MB\/s\u7684\u8bdd\uff0c\u5219\u53ef\u4ee5\u81f3\u5c11\u7f13\u5b5810\u5206\u949f\u7684\u6570\u636e\u3002<\/p>\n<h3 id=\"53-kafka\u6027\u80fd\u6d4b\u8bd5\"><a name=\"t22\"><\/a>5.3 Kafka\u6027\u80fd\u6d4b\u8bd5<\/h3>\n<p><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/Performance+testing\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Performance testing<\/a><\/p>\n<h3 id=\"54-kafka\u5728zookeeper\u4e2d\u7684\u6570\u636e\u7ed3\u6784\"><a name=\"t23\"><\/a>5.4 Kafka\u5728zookeeper\u4e2d\u7684\u6570\u636e\u7ed3\u6784<\/h3>\n<p><a href=\"https:\/\/cwiki.apache.org\/confluence\/display\/KAFKA\/Kafka+data+structures+in+Zookeeper\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Kafka data structures in Zookeeper<\/a><\/p>\n<h2 id=\"\u516dkafka\u4e3b\u8981\u914d\u7f6e\"><a name=\"t24\"><\/a>\u516d\u3001Kafka\u4e3b\u8981\u914d\u7f6e<\/h2>\n<h3 id=\"61-broker-config\"><a name=\"t25\"><\/a>6.1 Broker Config<\/h3>\n<div class=\"table-box\">\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>broker.id<\/td>\n<td><\/td>\n<td>\u5fc5\u586b\u53c2\u6570\uff0cbroker\u7684\u552f\u4e00\u6807\u8bc6<\/td>\n<\/tr>\n<tr>\n<td>log.dirs<\/td>\n<td>\/tmp\/kafka-logs<\/td>\n<td>Kafka\u6570\u636e\u5b58\u653e\u7684\u76ee\u5f55\u3002\u53ef\u4ee5\u6307\u5b9a\u591a\u4e2a\u76ee\u5f55\uff0c\u4e2d\u95f4\u7528\u9017\u53f7\u5206\u9694\uff0c\u5f53\u65b0partition\u88ab\u521b\u5efa\u7684\u65f6\u4f1a\u88ab\u5b58\u653e\u5230\u5f53\u524d\u5b58\u653epartition\u6700\u5c11\u7684\u76ee\u5f55\u3002<\/td>\n<\/tr>\n<tr>\n<td>port<\/td>\n<td>9092<\/td>\n<td>BrokerServer\u63a5\u53d7\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u7aef\u53e3\u53f7<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.connect<\/td>\n<td>null<\/td>\n<td>Zookeeper\u7684\u8fde\u63a5\u4e32\uff0c\u683c\u5f0f\u4e3a\uff1ahostname1:port1,hostname2:port2,hostname3:port3\u3002\u53ef\u4ee5\u586b\u4e00\u4e2a\u6216\u591a\u4e2a\uff0c\u4e3a\u4e86\u63d0\u9ad8\u53ef\u9760\u6027\uff0c\u5efa\u8bae\u90fd\u586b\u4e0a\u3002\u6ce8\u610f\uff0c\u6b64\u914d\u7f6e\u5141\u8bb8\u6211\u4eec\u6307\u5b9a\u4e00\u4e2azookeeper\u8def\u5f84\u6765\u5b58\u653e\u6b64kafka\u96c6\u7fa4\u7684\u6240\u6709\u6570\u636e\uff0c\u4e3a\u4e86\u4e0e\u5176\u4ed6\u5e94\u7528\u96c6\u7fa4\u533a\u5206\u5f00\uff0c\u5efa\u8bae\u5728\u6b64\u914d\u7f6e\u4e2d\u6307\u5b9a\u672c\u96c6\u7fa4\u5b58\u653e\u76ee\u5f55\uff0c\u683c\u5f0f\u4e3a\uff1ahostname1:port1,hostname2:port2,hostname3:port3\/chroot\/path \u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6d88\u8d39\u8005\u7684\u53c2\u6570\u8981\u548c\u6b64\u53c2\u6570\u4e00\u81f4\u3002<\/td>\n<\/tr>\n<tr>\n<td>message.max.bytes<\/td>\n<td>1000000<\/td>\n<td>\u670d\u52a1\u5668\u53ef\u4ee5\u63a5\u6536\u5230\u7684\u6700\u5927\u7684\u6d88\u606f\u5927\u5c0f\u3002\u6ce8\u610f\u6b64\u53c2\u6570\u8981\u548cconsumer\u7684maximum.message.size\u5927\u5c0f\u4e00\u81f4\uff0c\u5426\u5219\u4f1a\u56e0\u4e3a\u751f\u4ea7\u8005\u751f\u4ea7\u7684\u6d88\u606f\u592a\u5927\u5bfc\u81f4\u6d88\u8d39\u8005\u65e0\u6cd5\u6d88\u8d39\u3002<\/td>\n<\/tr>\n<tr>\n<td>num.io.threads<\/td>\n<td>8<\/td>\n<td>\u670d\u52a1\u5668\u7528\u6765\u6267\u884c\u8bfb\u5199\u8bf7\u6c42\u7684IO\u7ebf\u7a0b\u6570\uff0c\u6b64\u53c2\u6570\u7684\u6570\u91cf\u81f3\u5c11\u8981\u7b49\u4e8e\u670d\u52a1\u5668\u4e0a\u78c1\u76d8\u7684\u6570\u91cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>queued.max.requests<\/td>\n<td>500<\/td>\n<td>I\/O\u7ebf\u7a0b\u53ef\u4ee5\u5904\u7406\u8bf7\u6c42\u7684\u961f\u5217\u5927\u5c0f\uff0c\u82e5\u5b9e\u9645\u8bf7\u6c42\u6570\u8d85\u8fc7\u6b64\u5927\u5c0f\uff0c\u7f51\u7edc\u7ebf\u7a0b\u5c06\u505c\u6b62\u63a5\u6536\u65b0\u7684\u8bf7\u6c42\u3002<\/td>\n<\/tr>\n<tr>\n<td>socket.send.buffer.bytes<\/td>\n<td>100 * 1024<\/td>\n<td>The SO_SNDBUFF buffer the server prefers for socket connections.<\/td>\n<\/tr>\n<tr>\n<td>socket.receive.buffer.bytes<\/td>\n<td>100 * 1024<\/td>\n<td>The SO_RCVBUFF buffer the server prefers for socket connections.<\/td>\n<\/tr>\n<tr>\n<td>socket.request.max.bytes<\/td>\n<td>100 * 1024 * 1024<\/td>\n<td>\u670d\u52a1\u5668\u5141\u8bb8\u8bf7\u6c42\u7684\u6700\u5927\u503c\uff0c \u7528\u6765\u9632\u6b62\u5185\u5b58\u6ea2\u51fa\uff0c\u5176\u503c\u5e94\u8be5\u5c0f\u4e8e Java heap size.<\/td>\n<\/tr>\n<tr>\n<td>num.partitions<\/td>\n<td>1<\/td>\n<td>\u9ed8\u8ba4partition\u6570\u91cf\uff0c\u5982\u679ctopic\u5728\u521b\u5efa\u65f6\u6ca1\u6709\u6307\u5b9apartition\u6570\u91cf\uff0c\u9ed8\u8ba4\u4f7f\u7528\u6b64\u503c\uff0c\u5efa\u8bae\u6539\u4e3a5<\/td>\n<\/tr>\n<tr>\n<td>log.segment.bytes<\/td>\n<td>1024 * 1024 * 1024<\/td>\n<td>Segment\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u8d85\u8fc7\u6b64\u503c\u5c06\u4f1a\u81ea\u52a8\u65b0\u5efa\u4e00\u4e2asegment\uff0c\u6b64\u503c\u53ef\u4ee5\u88abtopic\u7ea7\u522b\u7684\u53c2\u6570\u8986\u76d6\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.roll.{ms,hours}<\/td>\n<td>24 * 7 hours<\/td>\n<td>\u65b0\u5efasegment\u6587\u4ef6\u7684\u65f6\u95f4\uff0c\u6b64\u503c\u53ef\u4ee5\u88abtopic\u7ea7\u522b\u7684\u53c2\u6570\u8986\u76d6\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.retention.{ms,minutes,hours}<\/td>\n<td>7 days<\/td>\n<td>Kafka segment log\u7684\u4fdd\u5b58\u5468\u671f\uff0c\u4fdd\u5b58\u5468\u671f\u8d85\u8fc7\u6b64\u65f6\u95f4\u65e5\u5fd7\u5c31\u4f1a\u88ab\u5220\u9664\u3002\u6b64\u53c2\u6570\u53ef\u4ee5\u88abtopic\u7ea7\u522b\u53c2\u6570\u8986\u76d6\u3002\u6570\u636e\u91cf\u5927\u65f6\uff0c\u5efa\u8bae\u51cf\u5c0f\u6b64\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.retention.bytes<\/td>\n<td>-1<\/td>\n<td>\u6bcf\u4e2apartition\u7684\u6700\u5927\u5bb9\u91cf\uff0c\u82e5\u6570\u636e\u91cf\u8d85\u8fc7\u6b64\u503c\uff0cpartition\u6570\u636e\u5c06\u4f1a\u88ab\u5220\u9664\u3002\u6ce8\u610f\u8fd9\u4e2a\u53c2\u6570\u63a7\u5236\u7684\u662f\u6bcf\u4e2apartition\u800c\u4e0d\u662ftopic\u3002\u6b64\u53c2\u6570\u53ef\u4ee5\u88ablog\u7ea7\u522b\u53c2\u6570\u8986\u76d6\u3002<\/td>\n<\/tr>\n<tr>\n<td>log.retention.check.interval.ms<\/td>\n<td>5 minutes<\/td>\n<td>\u5220\u9664\u7b56\u7565\u7684\u68c0\u67e5\u5468\u671f<\/td>\n<\/tr>\n<tr>\n<td>auto.create.topics.enable<\/td>\n<td>true<\/td>\n<td>\u81ea\u52a8\u521b\u5efatopic\u53c2\u6570\uff0c\u5efa\u8bae\u6b64\u503c\u8bbe\u7f6e\u4e3afalse\uff0c\u4e25\u683c\u63a7\u5236topic\u7ba1\u7406\uff0c\u9632\u6b62\u751f\u4ea7\u8005\u9519\u5199topic\u3002<\/td>\n<\/tr>\n<tr>\n<td>default.replication.factor<\/td>\n<td>1<\/td>\n<td>\u9ed8\u8ba4\u526f\u672c\u6570\u91cf\uff0c\u5efa\u8bae\u6539\u4e3a2\u3002<\/td>\n<\/tr>\n<tr>\n<td>replica.lag.time.max.ms<\/td>\n<td>10000<\/td>\n<td>\u5728\u6b64\u7a97\u53e3\u65f6\u95f4\u5185\u6ca1\u6709\u6536\u5230follower\u7684fetch\u8bf7\u6c42\uff0cleader\u4f1a\u5c06\u5176\u4eceISR(in-sync replicas)\u4e2d\u79fb\u9664\u3002<\/td>\n<\/tr>\n<tr>\n<td>replica.lag.max.messages<\/td>\n<td>4000<\/td>\n<td>\u5982\u679creplica\u8282\u70b9\u843d\u540eleader\u8282\u70b9\u6b64\u503c\u5927\u5c0f\u7684\u6d88\u606f\u6570\u91cf\uff0cleader\u8282\u70b9\u5c31\u4f1a\u5c06\u5176\u4eceISR\u4e2d\u79fb\u9664\u3002<\/td>\n<\/tr>\n<tr>\n<td>replica.socket.timeout.ms<\/td>\n<td>30 * 1000<\/td>\n<td>replica\u5411leader\u53d1\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/td>\n<\/tr>\n<tr>\n<td>replica.socket.receive.buffer.bytes<\/td>\n<td>64 * 1024<\/td>\n<td>The socket receive buffer for network requests to the leader for replicating data.<\/td>\n<\/tr>\n<tr>\n<td>replica.fetch.max.bytes<\/td>\n<td>1024 * 1024<\/td>\n<td>The number of byes of messages to attempt to fetch for each partition in the fetch requests the replicas send to the leader.<\/td>\n<\/tr>\n<tr>\n<td>replica.fetch.wait.max.ms<\/td>\n<td>500<\/td>\n<td>The maximum amount of time to wait time for data to arrive on the leader in the fetch requests sent by the replicas to the leader.<\/td>\n<\/tr>\n<tr>\n<td>num.replica.fetchers<\/td>\n<td>1<\/td>\n<td>Number of threads used to replicate messages from leaders. Increasing this value can increase the degree of I\/O parallelism in the follower broker.<\/td>\n<\/tr>\n<tr>\n<td>fetch.purgatory.purge.interval.requests<\/td>\n<td>1000<\/td>\n<td>The purge interval (in number of requests) of the fetch request purgatory.<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.session.timeout.ms<\/td>\n<td>6000<\/td>\n<td>ZooKeeper session \u8d85\u65f6\u65f6\u95f4\u3002\u5982\u679c\u5728\u6b64\u65f6\u95f4\u5185server\u6ca1\u6709\u5411zookeeper\u53d1\u9001\u5fc3\u8df3\uff0czookeeper\u5c31\u4f1a\u8ba4\u4e3a\u6b64\u8282\u70b9\u5df2\u6302\u6389\u3002 \u6b64\u503c\u592a\u4f4e\u5bfc\u81f4\u8282\u70b9\u5bb9\u6613\u88ab\u6807\u8bb0\u6b7b\u4ea1\uff1b\u82e5\u592a\u9ad8\uff0c.\u4f1a\u5bfc\u81f4\u592a\u8fdf\u53d1\u73b0\u8282\u70b9\u6b7b\u4ea1\u3002<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.connection.timeout.ms<\/td>\n<td>6000<\/td>\n<td>\u5ba2\u6237\u7aef\u8fde\u63a5zookeeper\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.sync.time.ms<\/td>\n<td>2000<\/td>\n<td>H ZK follower\u843d\u540e ZK leader\u7684\u65f6\u95f4\u3002<\/td>\n<\/tr>\n<tr>\n<td>controlled.shutdown.enable<\/td>\n<td>true<\/td>\n<td>\u5141\u8bb8broker shutdown\u3002\u5982\u679c\u542f\u7528\uff0cbroker\u5728\u5173\u95ed\u81ea\u5df1\u4e4b\u524d\u4f1a\u628a\u5b83\u4e0a\u9762\u7684\u6240\u6709leaders\u8f6c\u79fb\u5230\u5176\u5b83brokers\u4e0a\uff0c\u5efa\u8bae\u542f\u7528\uff0c\u589e\u52a0\u96c6\u7fa4\u7a33\u5b9a\u6027\u3002<\/td>\n<\/tr>\n<tr>\n<td>auto.leader.rebalance.enable<\/td>\n<td>true<\/td>\n<td>If this is enabled the controller will automatically try to balance leadership for partitions among the brokers by periodically returning leadership to the \u201cpreferred\u201d replica for each partition if it is available.<\/td>\n<\/tr>\n<tr>\n<td>leader.imbalance.per.broker.percentage<\/td>\n<td>10<\/td>\n<td>The percentage of leader imbalance allowed per broker. The controller will rebalance leadership if this ratio goes above the configured value per broker.<\/td>\n<\/tr>\n<tr>\n<td>leader.imbalance.check.interval.seconds<\/td>\n<td>300<\/td>\n<td>The frequency with which to check for leader imbalance.<\/td>\n<\/tr>\n<tr>\n<td>offset.metadata.max.bytes<\/td>\n<td>4096<\/td>\n<td>The maximum amount of metadata to allow clients to save with their offsets.<\/td>\n<\/tr>\n<tr>\n<td>connections.max.idle.ms<\/td>\n<td>600000<\/td>\n<td>Idle connections timeout: the server socket processor threads close the connections that idle more than this.<\/td>\n<\/tr>\n<tr>\n<td>num.recovery.threads.per.data.dir<\/td>\n<td>1<\/td>\n<td>The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.<\/td>\n<\/tr>\n<tr>\n<td>unclean.leader.election.enable<\/td>\n<td>true<\/td>\n<td>Indicates whether to enable replicas not in the ISR set to be elected as leader as a last resort, even though doing so may result in data loss.<\/td>\n<\/tr>\n<tr>\n<td>delete.topic.enable<\/td>\n<td>false<\/td>\n<td>\u542f\u7528deletetopic\u53c2\u6570\uff0c\u5efa\u8bae\u8bbe\u7f6e\u4e3atrue\u3002<\/td>\n<\/tr>\n<tr>\n<td>offsets.topic.num.partitions<\/td>\n<td>50<\/td>\n<td>The number of partitions for the offset commit topic. Since changing this after deployment is currently unsupported, we recommend using a higher setting for production (e.g., 100-200).<\/td>\n<\/tr>\n<tr>\n<td>offsets.topic.retention.minutes<\/td>\n<td>1440<\/td>\n<td>Offsets that are older than this age will be marked for deletion. The actual purge will occur when the log cleaner compacts the offsets topic.<\/td>\n<\/tr>\n<tr>\n<td>offsets.retention.check.interval.ms<\/td>\n<td>600000<\/td>\n<td>The frequency at which the offset manager checks for stale offsets.<\/td>\n<\/tr>\n<tr>\n<td>offsets.topic.replication.factor<\/td>\n<td>3<\/td>\n<td>The replication factor for the offset commit topic. A higher setting (e.g., three or four) is recommended in order to ensure higher availability. If the offsets topic is created when fewer brokers than the replication factor then the offsets topic will be created with fewer replicas.<\/td>\n<\/tr>\n<tr>\n<td>offsets.topic.segment.bytes<\/td>\n<td>104857600<\/td>\n<td>Segment size for the offsets topic. Since it uses a compacted topic, this should be kept relatively low in order to facilitate faster log compaction and loads.<\/td>\n<\/tr>\n<tr>\n<td>offsets.load.buffer.size<\/td>\n<td>5242880<\/td>\n<td>An offset load occurs when a broker becomes the offset manager for a set of consumer groups (i.e., when it becomes a leader for an offsets topic partition). This setting corresponds to the batch size (in bytes) to use when reading from the offsets segments when loading offsets into the offset manager\u2019s cache.<\/td>\n<\/tr>\n<tr>\n<td>offsets.commit.required.acks<\/td>\n<td>-1<\/td>\n<td>The number of acknowledgements that are required before the offset commit can be accepted. This is similar to the producer\u2019s acknowledgement setting. In general, the default should not be overridden.<\/td>\n<\/tr>\n<tr>\n<td>offsets.commit.timeout.ms<\/td>\n<td>5000<\/td>\n<td>The offset commit will be delayed until this timeout or the required number of replicas have received the offset commit. This is similar to the producer request timeout.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3 id=\"62-producer-config\"><a name=\"t26\"><\/a>6.2 Producer Config<\/h3>\n<div class=\"table-box\">\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>metadata.broker.list<\/td>\n<td><\/td>\n<td>\u542f\u52a8\u65f6producer\u67e5\u8be2brokers\u7684\u5217\u8868\uff0c\u53ef\u4ee5\u662f\u96c6\u7fa4\u4e2d\u6240\u6709brokers\u7684\u4e00\u4e2a\u5b50\u96c6\u3002\u6ce8\u610f\uff0c\u8fd9\u4e2a\u53c2\u6570\u53ea\u662f\u7528\u6765\u83b7\u53d6topic\u7684\u5143\u4fe1\u606f\u7528\uff0cproducer\u4f1a\u4ece\u5143\u4fe1\u606f\u4e2d\u6311\u9009\u5408\u9002\u7684broker\u5e76\u4e0e\u4e4b\u5efa\u7acbsocket\u8fde\u63a5\u3002\u683c\u5f0f\u662f\uff1ahost1:port1,host2:port2\u3002<\/td>\n<\/tr>\n<tr>\n<td>request.required.acks<\/td>\n<td>0<\/td>\n<td>\u53c2\u89c13.2\u8282\u4ecb\u7ecd<\/td>\n<\/tr>\n<tr>\n<td>request.timeout.ms<\/td>\n<td>10000<\/td>\n<td>Broker\u7b49\u5f85ack\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u82e5\u7b49\u5f85\u65f6\u95f4\u8d85\u8fc7\u6b64\u503c\uff0c\u4f1a\u8fd4\u56de\u5ba2\u6237\u7aef\u9519\u8bef\u4fe1\u606f\u3002<\/td>\n<\/tr>\n<tr>\n<td>producer.type<\/td>\n<td>sync<\/td>\n<td>\u540c\u6b65\u5f02\u6b65\u6a21\u5f0f\u3002async\u8868\u793a\u5f02\u6b65\uff0csync\u8868\u793a\u540c\u6b65\u3002\u5982\u679c\u8bbe\u7f6e\u6210\u5f02\u6b65\u6a21\u5f0f\uff0c\u53ef\u4ee5\u5141\u8bb8\u751f\u4ea7\u8005\u4ee5batch\u7684\u5f62\u5f0fpush\u6570\u636e\uff0c\u8fd9\u6837\u4f1a\u6781\u5927\u7684\u63d0\u9ad8broker\u6027\u80fd\uff0c\u63a8\u8350\u8bbe\u7f6e\u4e3a\u5f02\u6b65\u3002<\/td>\n<\/tr>\n<tr>\n<td>serializer.class<\/td>\n<td>kafka.serializer.DefaultEncoder<\/td>\n<td>\u5e8f\u5217\u53f7\u7c7b\uff0c.\u9ed8\u8ba4\u5e8f\u5217\u5316\u6210 byte[] \u3002<\/td>\n<\/tr>\n<tr>\n<td>key.serializer.class<\/td>\n<td><\/td>\n<td>Key\u7684\u5e8f\u5217\u5316\u7c7b\uff0c\u9ed8\u8ba4\u540c\u4e0a\u3002<\/td>\n<\/tr>\n<tr>\n<td>partitioner.class<\/td>\n<td>kafka.producer.DefaultPartitioner<\/td>\n<td>Partition\u7c7b\uff0c\u9ed8\u8ba4\u5bf9key\u8fdb\u884chash\u3002<\/td>\n<\/tr>\n<tr>\n<td>compression.codec<\/td>\n<td>none<\/td>\n<td>\u6307\u5b9aproducer\u6d88\u606f\u7684\u538b\u7f29\u683c\u5f0f\uff0c\u53ef\u9009\u53c2\u6570\u4e3a\uff1a \u201cnone\u201d, \u201cgzip\u201d and \u201csnappy\u201d\u3002\u5173\u4e8e\u538b\u7f29\u53c2\u89c14.1\u8282<\/td>\n<\/tr>\n<tr>\n<td>compressed.topics<\/td>\n<td>null<\/td>\n<td>\u542f\u7528\u538b\u7f29\u7684topic\u540d\u79f0\u3002\u82e5\u4e0a\u9762\u53c2\u6570\u9009\u62e9\u4e86\u4e00\u4e2a\u538b\u7f29\u683c\u5f0f\uff0c\u90a3\u4e48\u538b\u7f29\u4ec5\u5bf9\u672c\u53c2\u6570\u6307\u5b9a\u7684topic\u6709\u6548\uff0c\u82e5\u672c\u53c2\u6570\u4e3a\u7a7a\uff0c\u5219\u5bf9\u6240\u6709topic\u6709\u6548\u3002<\/td>\n<\/tr>\n<tr>\n<td>message.send.max.retries<\/td>\n<td>3<\/td>\n<td>Producer\u53d1\u9001\u5931\u8d25\u65f6\u91cd\u8bd5\u6b21\u6570\u3002\u82e5\u7f51\u7edc\u51fa\u73b0\u95ee\u9898\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4e0d\u65ad\u91cd\u8bd5\u3002<\/td>\n<\/tr>\n<tr>\n<td>retry.backoff.ms<\/td>\n<td>100<\/td>\n<td>Before each retry, the producer refreshes the metadata of relevant topics to see if a new leader has been elected. Since leader election takes a bit of time, this property specifies the amount of time that the producer waits before refreshing the metadata.<\/td>\n<\/tr>\n<tr>\n<td>topic.metadata.refresh.interval.ms<\/td>\n<td>600 * 1000<\/td>\n<td>The producer generally refreshes the topic metadata from brokers when there is a failure (partition missing, leader not available\u2026). It will also poll regularly (default: every 10min so 600000ms). If you set this to a negative value, metadata will only get refreshed on failure. If you set this to zero, the metadata will get refreshed after each message sent (not recommended). Important note: the refresh happen only AFTER the message is sent, so if the producer never sends a message the metadata is never refreshed<\/td>\n<\/tr>\n<tr>\n<td>queue.buffering.max.ms<\/td>\n<td>5000<\/td>\n<td>\u542f\u7528\u5f02\u6b65\u6a21\u5f0f\u65f6\uff0cproducer\u7f13\u5b58\u6d88\u606f\u7684\u65f6\u95f4\u3002\u6bd4\u5982\u6211\u4eec\u8bbe\u7f6e\u62101000\u65f6\uff0c\u5b83\u4f1a\u7f13\u5b581\u79d2\u7684\u6570\u636e\u518d\u4e00\u6b21\u53d1\u9001\u51fa\u53bb\uff0c\u8fd9\u6837\u53ef\u4ee5\u6781\u5927\u7684\u589e\u52a0broker\u541e\u5410\u91cf\uff0c\u4f46\u4e5f\u4f1a\u9020\u6210\u65f6\u6548\u6027\u7684\u964d\u4f4e\u3002<\/td>\n<\/tr>\n<tr>\n<td>queue.buffering.max.messages<\/td>\n<td>10000<\/td>\n<td>\u91c7\u7528\u5f02\u6b65\u6a21\u5f0f\u65f6producer buffer \u961f\u5217\u91cc\u6700\u5927\u7f13\u5b58\u7684\u6d88\u606f\u6570\u91cf\uff0c\u5982\u679c\u8d85\u8fc7\u8fd9\u4e2a\u6570\u503c\uff0cproducer\u5c31\u4f1a\u963b\u585e\u6216\u8005\u4e22\u6389\u6d88\u606f\u3002<\/td>\n<\/tr>\n<tr>\n<td>queue.enqueue.timeout.ms<\/td>\n<td>-1<\/td>\n<td>\u5f53\u8fbe\u5230\u4e0a\u9762\u53c2\u6570\u503c\u65f6producer\u963b\u585e\u7b49\u5f85\u7684\u65f6\u95f4\u3002\u5982\u679c\u503c\u8bbe\u7f6e\u4e3a0\uff0cbuffer\u961f\u5217\u6ee1\u65f6producer\u4e0d\u4f1a\u963b\u585e\uff0c\u6d88\u606f\u76f4\u63a5\u88ab\u4e22\u6389\u3002\u82e5\u503c\u8bbe\u7f6e\u4e3a-1\uff0cproducer\u4f1a\u88ab\u963b\u585e\uff0c\u4e0d\u4f1a\u4e22\u6d88\u606f\u3002<\/td>\n<\/tr>\n<tr>\n<td>batch.num.messages<\/td>\n<td>200<\/td>\n<td>\u91c7\u7528\u5f02\u6b65\u6a21\u5f0f\u65f6\uff0c\u4e00\u4e2abatch\u7f13\u5b58\u7684\u6d88\u606f\u6570\u91cf\u3002\u8fbe\u5230\u8fd9\u4e2a\u6570\u91cf\u503c\u65f6producer\u624d\u4f1a\u53d1\u9001\u6d88\u606f\u3002<\/td>\n<\/tr>\n<tr>\n<td>send.buffer.bytes<\/td>\n<td>100 * 1024<\/td>\n<td>Socket write buffer size<\/td>\n<\/tr>\n<tr>\n<td>client.id<\/td>\n<td>\u201c\u201d<\/td>\n<td>The client id is a user-specified string sent in each request to help trace calls. It should logically identify the application making the request.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3 id=\"63-consumer-config\"><a name=\"t27\"><\/a>6.3 Consumer Config<\/h3>\n<div class=\"table-box\">\n<table>\n<thead>\n<tr>\n<th>\u5c5e\u6027<\/th>\n<th>\u9ed8\u8ba4\u503c<\/th>\n<th>\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>group.id<\/td>\n<td><\/td>\n<td>Consumer\u7684\u7ec4ID\uff0c\u76f8\u540cgoup.id\u7684consumer\u5c5e\u4e8e\u540c\u4e00\u4e2a\u7ec4\u3002<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.connect<\/td>\n<td><\/td>\n<td>Consumer\u7684zookeeper\u8fde\u63a5\u4e32\uff0c\u8981\u548cbroker\u7684\u914d\u7f6e\u4e00\u81f4\u3002<\/td>\n<\/tr>\n<tr>\n<td>consumer.id<\/td>\n<td>null<\/td>\n<td>\u5982\u679c\u4e0d\u8bbe\u7f6e\u4f1a\u81ea\u52a8\u751f\u6210\u3002<\/td>\n<\/tr>\n<tr>\n<td>socket.timeout.ms<\/td>\n<td>30 * 1000<\/td>\n<td>\u7f51\u7edc\u8bf7\u6c42\u7684socket\u8d85\u65f6\u65f6\u95f4\u3002\u5b9e\u9645\u8d85\u65f6\u65f6\u95f4\u7531max.fetch.wait + socket.timeout.ms \u786e\u5b9a\u3002<\/td>\n<\/tr>\n<tr>\n<td>socket.receive.buffer.bytes<\/td>\n<td>64 * 1024<\/td>\n<td>The socket receive buffer for network requests.<\/td>\n<\/tr>\n<tr>\n<td>fetch.message.max.bytes<\/td>\n<td>1024 * 1024<\/td>\n<td>\u67e5\u8be2topic-partition\u65f6\u5141\u8bb8\u7684\u6700\u5927\u6d88\u606f\u5927\u5c0f\u3002consumer\u4f1a\u4e3a\u6bcf\u4e2apartition\u7f13\u5b58\u6b64\u5927\u5c0f\u7684\u6d88\u606f\u5230\u5185\u5b58\uff0c\u56e0\u6b64\uff0c\u8fd9\u4e2a\u53c2\u6570\u53ef\u4ee5\u63a7\u5236consumer\u7684\u5185\u5b58\u4f7f\u7528\u91cf\u3002\u8fd9\u4e2a\u503c\u5e94\u8be5\u81f3\u5c11\u6bd4server\u5141\u8bb8\u7684\u6700\u5927\u6d88\u606f\u5927\u5c0f\u5927\uff0c\u4ee5\u514dproducer\u53d1\u9001\u7684\u6d88\u606f\u5927\u4e8econsumer\u5141\u8bb8\u7684\u6d88\u606f\u3002<\/td>\n<\/tr>\n<tr>\n<td>num.consumer.fetchers<\/td>\n<td>1<\/td>\n<td>The number fetcher threads used to fetch data.<\/td>\n<\/tr>\n<tr>\n<td>auto.commit.enable<\/td>\n<td>true<\/td>\n<td>\u5982\u679c\u6b64\u503c\u8bbe\u7f6e\u4e3atrue\uff0cconsumer\u4f1a\u5468\u671f\u6027\u7684\u628a\u5f53\u524d\u6d88\u8d39\u7684offset\u503c\u4fdd\u5b58\u5230zookeeper\u3002\u5f53consumer\u5931\u8d25\u91cd\u542f\u4e4b\u540e\u5c06\u4f1a\u4f7f\u7528\u6b64\u503c\u4f5c\u4e3a\u65b0\u5f00\u59cb\u6d88\u8d39\u7684\u503c\u3002<\/td>\n<\/tr>\n<tr>\n<td>auto.commit.interval.ms<\/td>\n<td>60 * 1000<\/td>\n<td>Consumer\u63d0\u4ea4offset\u503c\u5230zookeeper\u7684\u5468\u671f\u3002<\/td>\n<\/tr>\n<tr>\n<td>queued.max.message.chunks<\/td>\n<td>2<\/td>\n<td>\u7528\u6765\u88abconsumer\u6d88\u8d39\u7684message chunks \u6570\u91cf\uff0c \u6bcf\u4e2achunk\u53ef\u4ee5\u7f13\u5b58fetch.message.max.bytes\u5927\u5c0f\u7684\u6570\u636e\u91cf\u3002<\/td>\n<\/tr>\n<tr>\n<td>rebalance.max.retries<\/td>\n<td>4<\/td>\n<td>When a new consumer joins a consumer group the set of consumers attempt to \u201crebalance\u201d the load to assign partitions to each consumer. If the set of consumers changes while this assignment is taking place the rebalance will fail and retry. This setting controls the maximum number of attempts before giving up.<\/td>\n<\/tr>\n<tr>\n<td>fetch.min.bytes<\/td>\n<td>1<\/td>\n<td>The minimum amount of data the server should return for a fetch request. If insufficient data is available the request will wait for that much data to accumulate before answering the request.<\/td>\n<\/tr>\n<tr>\n<td>fetch.wait.max.ms<\/td>\n<td>100<\/td>\n<td>The maximum amount of time the server will block before answering the fetch request if there isn\u2019t sufficient data to immediately satisfy fetch.min.bytes.<\/td>\n<\/tr>\n<tr>\n<td>rebalance.backoff.ms<\/td>\n<td>2000<\/td>\n<td>Backoff time between retries during rebalance.<\/td>\n<\/tr>\n<tr>\n<td>refresh.leader.backoff.ms<\/td>\n<td>200<\/td>\n<td>Backoff time to wait before trying to determine the leader of a partition that has just lost its leader.<\/td>\n<\/tr>\n<tr>\n<td>auto.offset.reset<\/td>\n<td>largest<\/td>\n<td>What to do when there is no initial offset in ZooKeeper or if an offset is out of range ;smallest : automatically reset the offset to the smallest offset; largest : automatically reset the offset to the largest offset;anything else: throw exception to the consumer<\/td>\n<\/tr>\n<tr>\n<td>consumer.timeout.ms<\/td>\n<td>-1<\/td>\n<td>\u82e5\u5728\u6307\u5b9a\u65f6\u95f4\u5185\u6ca1\u6709\u6d88\u606f\u6d88\u8d39\uff0cconsumer\u5c06\u4f1a\u629b\u51fa\u5f02\u5e38\u3002<\/td>\n<\/tr>\n<tr>\n<td>exclude.internal.topics<\/td>\n<td>true<\/td>\n<td>Whether messages from internal topics (such as offsets) should be exposed to the consumer.<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.session.timeout.ms<\/td>\n<td>6000<\/td>\n<td>ZooKeeper session timeout. If the consumer fails to heartbeat to ZooKeeper for this period of time it is considered dead and a rebalance will occur.<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.connection.timeout.ms<\/td>\n<td>6000<\/td>\n<td>The max time that the client waits while establishing a connection to zookeeper.<\/td>\n<\/tr>\n<tr>\n<td>zookeeper.sync.time.ms<\/td>\n<td>2000<\/td>\n<td>How far a ZK follower can be behind a ZK leader<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3 id=\"64-topic-\u7ea7\u522b\u7684\u914d\u7f6e\"><a name=\"t28\"><\/a>6.4 Topic \u7ea7\u522b\u7684\u914d\u7f6e<\/h3>\n<p><a href=\"http:\/\/kafka.apache.org\/documentation.html#topic-config\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">topic-config<\/a><\/p>\n<\/div>\n<\/div>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u672a\u7ecf\u535a\u4e3b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[119],"class_list":["post-2890","post","type-post","status-publish","format-standard","hentry","tag-03-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2890","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=2890"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/2890\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=2890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=2890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=2890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}