{"id":10021037,"date":"2025-10-17T01:49:24","date_gmt":"2025-10-16T17:49:24","guid":{"rendered":"https:\/\/itmax.cn\/?p=10021037"},"modified":"2025-10-17T01:49:24","modified_gmt":"2025-10-16T17:49:24","slug":"%e5%88%ab%e5%86%8d%e4%b9%b1%e6%8e%92%e6%9f%a5%e4%ba%86%ef%bc%81kafka-%e6%b6%88%e6%81%af%e7%a7%af%e5%8e%8b%e3%80%81%e9%87%8d%e5%a4%8d%e3%80%81%e4%b8%a2%e5%a4%b1%ef%bc%8c%e6%a0%b9%e6%ba%90%e5%9f%ba","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10021037","title":{"rendered":"\u522b\u518d\u4e71\u6392\u67e5\u4e86\uff01Kafka \u6d88\u606f\u79ef\u538b\u3001\u91cd\u590d\u3001\u4e22\u5931\uff0c\u6839\u6e90\u57fa\u672c\u90fd\u662f Rebalance\uff01"},"content":{"rendered":"<p><strong>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u5c0f\u5bcc\uff5e<\/strong><\/p>\n<p>\u6709\u6b21\u4e0a\u7ebf\u76d1\u63a7\u544a\u8b66\u7a81\u7136\u70b8\u4e86\uff0cKafka \u8ba2\u5355 Topic \u6d88\u606f\u79ef\u538b\u91cf\u7a81\u7834 10 \u4e07\u6761\uff0c\u4e0b\u6e38\u652f\u4ed8\u670d\u52a1\u62ff\u4e0d\u5230\u6570\u636e\uff0c\u90e8\u5206\u7528\u6237\u4ed8\u6b3e\u540e\u4e00\u76f4\u663e\u793a\u5904\u7406\u4e2d\u3002<\/p>\n<p>\u7d27\u6025\u767b\u5f55\u96c6\u7fa4\u6392\u67e5\uff0c\u53d1\u73b0\u6d88\u8d39\u8005\u7ec4\u660e\u660e\u6709 3 \u4e2a\u8282\u70b9\uff0c\u5374\u53ea\u6709 1 \u4e2a\u5728\u6b63\u5e38\u6d88\u8d39\uff0c\u539f\u6765 10 \u5206\u949f\u524d\u89e6\u53d1\u4e86 Rebalance\uff0c\u53e6\u5916\u4e24\u4e2a\u8282\u70b9\u8fd8\u5361\u5728\u5206\u533a\u91cd\u65b0\u5206\u914d\u7684\u72b6\u6001\uff0c\u5bfc\u81f4\u6d88\u8d39\u80fd\u529b\u76f4\u63a5\u780d\u534a\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u7684\u7ecf\u9a8c\u662f\uff1a<strong>Kafka\u51fa\u73b0\u6d88\u606f\u79ef\u538b\u3001\u91cd\u590d\u3001\u4e22\u5931\u8fd9\u7c7b\u95ee\u9898\uff0c\u76f4\u63a5\u770b\u662f\u5426\u6709Rebalance\uff0c\u80fd\u89e3\u51b3\u5927\u90e8\u5206\u95ee\u9898\u3002<\/strong><\/p>\n<h2>\u4ec0\u4e48\u65f6\u5019\u4f1a\u89e6\u53d1 Rebalance\uff1f<\/h2>\n<p>Rebalance \u672c\u8d28\u662f<strong>\u6d88\u8d39\u8005\u7ec4\u5185\u5206\u533a\u4e0e\u6d88\u8d39\u8005\u7684\u91cd\u65b0\u5206\u914d<\/strong>\uff0c\u53ea\u6709\u5f53\u6d88\u8d39\u8005\u3001\u5206\u533a\u7684\u5bf9\u5e94\u5173\u7cfb\u88ab\u6253\u7834\u65f6\u624d\u4f1a\u89e6\u53d1\uff0c\u4e0b\u8fb9\u54b1\u4eec\u770b\u770b\u51e0\u79cd\u6bd4\u8f83\u5e38\u89c1\u7684\u573a\u666f\uff1a<\/p>\n<h3>1. \u6d88\u8d39\u8005\u6570\u91cf\u53d8\u4e86\uff08\u6700\u9891\u7e41\uff09<\/h3>\n<p><strong>\u6269\u5bb9\u89e6\u53d1<\/strong>\uff1a\u4e1a\u52a1\u9ad8\u5cf0\u65f6\u52a0\u4e86\u6d88\u8d39\u8005\u8282\u70b9\uff0c\u6bd4\u5982 3 \u4e2a\u5206\u533a\u539f\u672c 2 \u4e2a\u6d88\u8d39\u8005\u627f\u62c5\uff0c\u65b0\u589e 1 \u4e2a\u540e\uff0c\u9700\u8981\u91cd\u65b0\u5206\u914d\u6210 1 \u4e2a\u6d88\u8d39\u8005\u5bf9\u5e94 1 \u4e2a\u5206\u533a\uff1b<\/p>\n<p><strong>\u4e0b\u7ebf\u89e6\u53d1<\/strong>\uff1a\u6d88\u8d39\u8005\u8282\u70b9\u5b95\u673a\u3001\u7f51\u7edc\u65ad\u8fde\uff0c\u6216\u8fdb\u7a0b\u88ab\u8bef\u6740\uff0c\u6bd4\u5982 3 \u4e2a\u6d88\u8d39\u8005\u5c11\u4e86 1 \u4e2a\uff0c\u5269\u4e0b 2 \u4e2a\u8981\u63a5\u624b\u5b83\u7684\u5206\u533a\uff0c\u5fc5\u7136\u89e6\u53d1 Rebalance\u3002<\/p>\n<p>\u4e4b\u524d\u6211\u4eec\u7684\u65e5\u5fd7\u670d\u52a1\u5c31\u8e29\u8fc7\u5751\uff1aK8s \u8282\u70b9\u8d44\u6e90\u4e0d\u8db3\uff0c\u5bfc\u81f4\u6d88\u8d39\u8005 Pod \u9891\u7e41\u91cd\u542f\uff0c\u6bcf\u91cd\u542f\u4e00\u6b21\u5c31\u89e6\u53d1\u4e00\u6b21 Rebalance\uff0c\u6d88\u606f\u79ef\u538b\u8d8a\u6765\u8d8a\u4e25\u91cd\u3002<\/p>\n<h3>2. Topic \u5206\u533a\u6570\u52a0\u4e86<\/h3>\n<p>Kafka \u4e0d\u652f\u6301\u51cf\u5c11\u5206\u533a\uff0c\u4f46\u65b0\u589e\u5206\u533a\u65f6\uff0c\u5df2\u5b58\u5728\u7684\u6d88\u8d39\u8005\u7ec4\u4e0d\u4f1a\u81ea\u52a8\u611f\u77e5\u65b0\u5206\u533a\uff0c\u5fc5\u987b\u901a\u8fc7 Rebalance\uff0c\u624d\u80fd\u628a\u65b0\u5206\u533a\u5206\u914d\u7ed9\u7ec4\u5185\u6d88\u8d39\u8005\u3002<\/p>\n<p>\u6bd4\u5982\u7ed9 <code>order-topic<\/code> \u4ece 5 \u4e2a\u5206\u533a\u6269\u5230 8 \u4e2a\uff0c\u539f\u672c\u7684\u6d88\u8d39\u8005\u7ec4\u53ea\u4f1a\u6d88\u8d39\u65e7\u7684 5 \u4e2a\u5206\u533a\uff0c\u76f4\u5230\u89e6\u53d1 Rebalance \u540e\uff0c\u624d\u4f1a\u63a5\u624b\u65b0\u589e\u7684 3 \u4e2a\u5206\u533a\u3002<\/p>\n<h3>3. \u8ba2\u9605\u7684 Topic \u53d8\u4e86<\/h3>\n<p>\u6d88\u8d39\u8005\u7ec4\u901a\u8fc7 <code>subscribe()<\/code> \u8ba2\u9605 Topic \u65f6\uff0c\u82e5\u4fee\u6539\u8ba2\u9605\u5217\u8868\uff08\u6bd4\u5982\u4ece\u53ea\u8ba2\u9605 <code>order-topic<\/code>\uff0c\u6539\u6210\u540c\u65f6\u8ba2\u9605 <code>order-topic<\/code> \u548c <code>pay-topic<\/code>\uff09\uff0c\u4f1a\u89e6\u53d1 Rebalance\uff0c\u91cd\u65b0\u5206\u914d\u6240\u6709\u8ba2\u9605 Topic \u7684\u5206\u533a\u3002<\/p>\n<h3>4. \u5fc3\u8df3\u6216\u6d88\u8d39\u8d85\u65f6\uff08\u9690\u6027\u5751\uff09<\/h3>\n<p>\u6d88\u8d39\u8005\u9760\u5fc3\u8df3\u5411 Coordinator\uff08\u534f\u8c03\u8005\uff09\u8bc1\u660e\u81ea\u5df1\u6d3b\u7740\uff0c\u8fd9\u4e24\u4e2a\u8d85\u65f6\u53c2\u6570\u8bbe\u4e0d\u597d\uff0c\u5f88\u5bb9\u6613\u89e6\u53d1\u8bef\u5224\u5f0f Rebalance\uff1a<\/p>\n<p><strong>\u5fc3\u8df3\u8d85\u65f6<\/strong>\uff1a\u6d88\u8d39\u8005\u6bcf 3 \u79d2\uff08\u9ed8\u8ba4 <code>heartbeat.interval.ms<\/code>\uff09\u53d1\u4e00\u6b21\u5fc3\u8df3\uff0c\u8d85\u8fc7 45 \u79d2\uff08\u9ed8\u8ba4 <code>session.timeout.ms<\/code>\uff09\u6ca1\u53d1\uff0c\u5c31\u88ab\u5224\u5b9a\u6b7b\u4ea1\uff1b<\/p>\n<p><strong>\u6d88\u8d39\u8d85\u65f6<\/strong>\uff1a\u5904\u7406\u5355\u6279\u6d88\u606f\u8d85\u8fc7 5 \u5206\u949f\uff08\u9ed8\u8ba4 <code>max.poll.interval.ms<\/code>\uff09\uff0c\u54ea\u6015\u5fc3\u8df3\u6b63\u5e38\uff0c\u4e5f\u4f1a\u88ab\u5f3a\u5236\u8e22\u51fa\u7ec4\uff0c\u89e6\u53d1 Rebalance\u3002<\/p>\n<p>\u6211\u4eec\u4e4b\u524d\u5904\u7406\u5927\u8ba2\u5355\u6d88\u606f\u65f6\uff0c\u5355\u6761\u6d88\u606f\u5904\u7406\u8981 6 \u5206\u949f\uff0c\u76f4\u63a5\u89e6\u53d1\u6d88\u8d39\u8d85\u65f6\uff0c\u5bfc\u81f4 Rebalance \u9891\u7e41\u53d1\u751f\u3002<\/p>\n<h2>Rebalance \u5f15\u8d77\u54ea\u4e9b\u95ee\u9898<\/h2>\n<p>Rebalance \u4e0d\u662f\u77ac\u95f4\u5b8c\u6210\u7684\uff0c\u6574\u4e2a\u8fc7\u7a0b\u8981\u7ecf\u5386\u6ce8\u9500\u65e7\u5206\u533a\u2192\u9009\u4e3e Leader\u2192\u5206\u914d\u65b0\u5206\u533a\u2192\u6d88\u8d39\u8005\u521d\u59cb\u5316\uff0c\u671f\u95f4\u5bf9\u4e1a\u52a1\u7684\u5f71\u54cd\u6bd4\u4f60\u60f3\u7684\u5927\u3002<\/p>\n<h3>1. \u6d88\u8d39\u6682\u505c\uff0c\u6d88\u606f\u79ef\u538b<\/h3>\n<p>Rebalance \u671f\u95f4\uff0c<strong>\u6240\u6709\u6d88\u8d39\u8005\u90fd\u4f1a\u6682\u505c\u6d88\u8d39<\/strong>\uff0c\u7b49\u5f85\u65b0\u7684\u5206\u533a\u5206\u914d\u3002\u5982\u679c\u6d88\u8d39\u8005\u7ec4\u89c4\u6a21\u5927\uff08\u6bd4\u5982 100 \u4e2a\u6d88\u8d39\u8005\u30011000 \u4e2a\u5206\u533a\uff09\uff0cRebalance \u53ef\u80fd\u6301\u7eed\u51e0\u5341\u79d2\uff0c\u8fd9\u6bb5\u65f6\u95f4 Topic \u6d88\u606f\u53ea\u4f1a\u5806\u79ef\uff0c\u4e0b\u6e38\u670d\u52a1\u62ff\u4e0d\u5230\u6570\u636e\u3002<\/p>\n<p>\u6240\u4ee5\u5728\u6709\u6d88\u606f\u79ef\u538b\u7684\u60c5\u51b5\uff0c\u4f18\u5148\u770b\u770b\u662f\u5426\u6709 Rebalance \u7684\u60c5\u51b5\u3002<\/p>\n<h3>2. \u6d88\u606f\u91cd\u590d\u548c\u6d88\u606f\u4e22\u5931<\/h3>\n<p>Rebalance \u540e\uff0c\u6d88\u8d39\u8005\u91cd\u65b0\u62ff\u5230\u5206\u533a\u65f6\uff0c\u6d88\u8d39\u8fdb\u5ea6\u53ef\u80fd\u5012\u9000\uff1a\u82e5\u6ca1\u53ca\u65f6\u63d0\u4ea4 offset\uff08\u4e0d\u7ba1\u81ea\u52a8\u8fd8\u662f\u624b\u52a8\uff09\uff0c\u4f1a\u4ece\u6700\u540e\u4e00\u6b21\u63d0\u4ea4\u7684 offset \u5f00\u59cb\u6d88\u8d39\uff0c\u4e2d\u95f4\u6ca1\u63d0\u4ea4\u7684\u6d88\u606f\u8981\u4e48\u91cd\u590d\u5904\u7406\uff0c\u8981\u4e48\u76f4\u63a5\u8df3\u8fc7\uff0c\u4e5f\u5c31\u662f\u6d88\u606f\u91cd\u590d\u6d88\u8d39\u548c\u6d88\u606f\u4e22\u5931\u7684\u539f\u56e0\u3002<\/p>\n<p>\u6781\u7aef\u60c5\u51b5\uff08\u6bd4\u5982 Coordinator \u5b95\u673a\uff09\uff0coffset \u5b58\u50a8\u7684\u5206\u533a\u53d1\u751f\u4e3b\u4ece\u5207\u6362\uff0c\u53ef\u80fd\u5bfc\u81f4 offset \u6570\u636e\u9519\u4e71\uff0c\u8fdb\u5ea6\u76f4\u63a5\u56de\u5230\u51e0\u5929\u524d\u3002<\/p>\n<h3>3. \u8d44\u6e90\u6d6a\u8d39\uff0c\u8d1f\u8f7d\u4e0d\u5747<\/h3>\n<p>Rebalance \u8981\u9760 Coordinator \u534f\u8c03\uff0c\u9891\u7e41\u89e6\u53d1\u4f1a\u5360\u7528 Kafka \u96c6\u7fa4\u7684 CPU \u548c\u7f51\u7edc\u8d44\u6e90\uff1b\u800c\u4e14 Kafka \u9ed8\u8ba4\u7684\u5206\u533a\u5206\u914d\u7b56\u7565\uff08Range \u6216 RoundRobin\uff09\uff0c\u5f88\u5bb9\u6613\u5bfc\u81f4\u8d1f\u8f7d\u4e0d\u5747\u3002<\/p>\n<p>\u6bd4\u5982 5 \u4e2a\u5206\u533a\u5206\u914d\u7ed9 2 \u4e2a\u6d88\u8d39\u8005\uff0c\u53ef\u80fd\u51fa\u73b0 3 \u4e2a\u5206\u533a vs 2 \u4e2a\u5206\u533a\u7684\u60c5\u51b5\uff0c\u5176\u4e2d\u4e00\u4e2a\u6d88\u8d39\u8005\u538b\u529b\u7ffb\u500d\uff0c\u5904\u7406\u901f\u5ea6\u53d8\u6162\uff0c\u53c8\u4f1a\u89e6\u53d1\u65b0\u7684 Rebalance\uff0c\u9677\u5165\u6076\u6027\u5faa\u73af\u3002<\/p>\n<h2>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u4e22\u6570\u636e<\/h2>\n<p>Rebalance \u672c\u8eab\u4e0d\u4f1a\u76f4\u63a5\u4e22\u6570\u636e\uff0c\u4f46\u7ed3\u5408offset \u63d0\u4ea4\u548c\u5904\u7406\u903b\u8f91\uff0c\u5f88\u5bb9\u6613\u51fa\u73b0\u6d88\u606f\u6f0f\u6d88\u8d39\u3002<\/p>\n<h3>1.\u81ea\u52a8\u63d0\u4ea4 offset + \u6d88\u8d39\u6ca1\u5b8c\u6210<\/h3>\n<p>Kafka \u9ed8\u8ba4\u81ea\u52a8\u63d0\u4ea4 offset\uff0c\u63d0\u4ea4\u65f6\u673a\u662f poll \u5230\u6d88\u606f\u540e\uff0c\u7b49 5 \u79d2\uff08\u9ed8\u8ba4 <code>auto.commit.interval.ms<\/code>\uff09\u81ea\u52a8\u63d0\u4ea4\u3002\u5982\u679c\u521a\u63d0\u4ea4\u5b8c offset\uff0c\u6d88\u606f\u8fd8\u6ca1\u5904\u7406\u5b8c\u5c31\u89e6\u53d1 Rebalance\uff0c\u65b0\u6d88\u8d39\u8005\u4f1a\u4ece\u5df2\u63d0\u4ea4\u7684 offset \u4e4b\u540e \u5f00\u59cb\u6d88\u8d39\uff0c\u4e2d\u95f4\u6ca1\u5904\u7406\u7684\u6d88\u606f\u5c31\u4e22\u4e86\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<ul>\n<li>\u6d88\u8d39\u8005 A  poll \u5230 offset 100-200 \u7684\u6d88\u606f\uff0c5 \u79d2\u540e\u81ea\u52a8\u63d0\u4ea4 offset 200\uff1b<\/li>\n<li>\u5904\u7406\u5230 150 \u6761\u65f6\uff0c\u8282\u70b9\u7a81\u7136\u5b95\u673a\uff0c\u89e6\u53d1 Rebalance\uff1b<\/li>\n<li>\u65b0\u6d88\u8d39\u8005 B \u4ece offset 200 \u5f00\u59cb\u6d88\u8d39\uff0coffset 150-199 \u7684\u6d88\u606f\u76f4\u63a5\u4e22\u5931\u3002<\/li>\n<\/ul>\n<h3>2. \u624b\u52a8\u63d0\u4ea4 offset \u65f6\u673a\u9519\u4e86<\/h3>\n<p>\u624b\u52a8\u63d0\u4ea4\u65f6\uff0c\u5982\u679c\u628a\u63d0\u4ea4 offset \u653e\u5728\u5904\u7406\u6d88\u606f\u4e4b\u524d\uff0c\u4e5f\u4f1a\u4e22\u6570\u636e\u3002<\/p>\n<ul>\n<li>\u9519\u8bef\u903b\u8f91\uff1a\u5148\u63d0\u4ea4 offset \u2192 \u518d\u5904\u7406\u6d88\u606f\uff1b<\/li>\n<li>\u98ce\u9669\uff1a\u63d0\u4ea4\u540e\u3001\u5904\u7406\u524d\u89e6\u53d1 Rebalance\uff0c\u65b0\u6d88\u8d39\u8005\u4f1a\u8df3\u8fc7\u5df2\u63d0\u4ea4\u7684\u6d88\u606f\uff0c\u5bfc\u81f4\u672a\u5904\u7406\u7684\u6d88\u606f\u4e22\u5931\u3002<\/li>\n<\/ul>\n<p>\u6b63\u786e\u7684\u505a\u6cd5\u5e94\u8be5\u662f\u5148\u5904\u7406\u6d88\u606f\u2192\u518d\u63d0\u4ea4 offset\uff0c\u786e\u4fdd\u6d88\u606f\u5904\u7406\u5b8c\u624d\u66f4\u65b0\u8fdb\u5ea6\u3002<\/p>\n<h2>\u4ec0\u4e48\u60c5\u51b5\u4e0b\u4f1a\u91cd\u590d\u6d88\u8d39\uff1f<\/h2>\n<p>\u76f8\u6bd4\u4e22\u6570\u636e\uff0ckafka Rebalance \u5bfc\u81f4\u7684\u91cd\u590d\u6d88\u8d39\u66f4\u666e\u904d\uff0c\u6838\u5fc3\u539f\u56e0\u90fd\u662f offset \u63d0\u4ea4\u6ede\u540e\u4e8e\u6d88\u606f\u5904\u7406\u3002<\/p>\n<h3>1. \u624b\u52a8\u63d0\u4ea4\u65f6\uff0cRebalance \u6253\u65ad\u4e86\u63d0\u4ea4<\/h3>\n<p>\u5f00\u542f\u624b\u52a8\u63d0\u4ea4\u540e\uff0c\u82e5\u5728\u5904\u7406\u5b8c\u6d88\u606f\u2192\u63d0\u4ea4 offset \u7684\u95f4\u9699\u89e6\u53d1 Rebalance\uff0coffset \u6ca1\u63d0\u4ea4\u6210\u529f\uff0c\u65b0\u6d88\u8d39\u8005\u4f1a\u4ece\u4e0a\u6b21\u63d0\u4ea4\u7684\u4f4d\u7f6e\u91cd\u65b0\u6d88\u8d39\u3002<\/p>\n<ul>\n<li>\u6d88\u8d39\u8005 A \u5904\u7406\u5b8c offset 100-200 \u7684\u6d88\u606f\uff0c\u51c6\u5907\u63d0\u4ea4\u65f6\uff0c\u56e0\u5fc3\u8df3\u8d85\u65f6\u88ab\u8e22\u51fa\u7ec4\uff1b<\/li>\n<li>\u65b0\u6d88\u8d39\u8005 B \u4ece offset 100 \u5f00\u59cb\u6d88\u8d39\uff0c\u5bfc\u81f4 100-200 \u7684\u6d88\u606f\u88ab\u91cd\u590d\u5904\u7406\u3002<\/li>\n<\/ul>\n<h3>2. \u6d88\u8d39\u8d85\u65f6\u88ab\u8e22\uff0c\u6d88\u606f\u8fd8\u5728\u5904\u7406<\/h3>\n<p>\u5904\u7406\u6d88\u606f\u8017\u65f6\u8d85\u8fc7 <code>max.poll.interval.ms<\/code>\uff0c\u6d88\u8d39\u8005\u88ab\u5224\u5b9a\u6b7b\u4ea1\uff0c\u4f46\u5b9e\u9645\u8fd8\u5728\u5904\u7406\u6d88\u606f\u3002<\/p>\n<ul>\n<li>\u6d88\u8d39\u8005 A \u5904\u7406\u5927\u6d88\u606f\u7528\u4e86 6 \u5206\u949f\uff0c\u8d85\u8fc7\u9ed8\u8ba4 5 \u5206\u949f\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u88ab\u8e22\u51fa\u7ec4\uff1b<\/li>\n<li>\u65b0\u6d88\u8d39\u8005 B \u63a5\u624b\u5206\u533a\uff0c\u4ece\u4e0a\u6b21\u63d0\u4ea4\u7684 offset \u5f00\u59cb\u6d88\u8d39\uff1b<\/li>\n<li>\u6d88\u8d39\u8005 A \u540e\u6765\u5904\u7406\u5b8c\u6d88\u606f\uff0c\u60f3\u63d0\u4ea4 offset \u5374\u53d1\u73b0\u81ea\u5df1\u5df2\u88ab\u8e22\u51fa\uff0c\u63d0\u4ea4\u5931\u8d25\uff0c\u5bfc\u81f4\u6d88\u606f\u91cd\u590d\u3002<\/li>\n<\/ul>\n<h3>3. offset \u627e\u4e0d\u5230\uff0c\u56de\u9000\u5230\u6700\u65e9<\/h3>\n<p>\u5982\u679c\u6d88\u8d39\u8005\u7ec4\u7684 <code>auto.offset.reset<\/code> \u8bbe\u4e3a <code>earliest<\/code>\uff08\u9ed8\u8ba4\u662f <code>latest<\/code>\uff09\uff0cRebalance \u540e\u627e\u4e0d\u5230\u5df2\u63d0\u4ea4\u7684 offset\uff08\u6bd4\u5982 offset \u6570\u636e\u635f\u574f\uff09\uff0c\u4f1a\u4ece Topic \u6700\u65e9\u7684\u6d88\u606f\u5f00\u59cb\u6d88\u8d39\uff0c\u5bfc\u81f4\u5386\u53f2\u6d88\u606f\u91cd\u590d\u3002<\/p>\n<h2>\u5982\u4f55\u4f18\u5316 Rebalance<\/h2>\n<p>Rebalance \u8fd9\u79cd\u60c5\u51b5\u662f\u65e0\u6cd5\u5b8c\u5168\u907f\u514d\uff0c\u4e0d\u8fc7\u6211\u4eec\u53ef\u4ee5\u6765\u4f18\u5316\uff0c\u80fd\u628a\u5f71\u54cd\u964d\u5230\u6700\u4f4e\u3002<\/p>\n<h3>1. \u907f\u514d\u9891\u7e41\u89e6\u53d1 Rebalance<\/h3>\n<p>\u8c03\u4f18\u8d85\u65f6\u53c2\u6570\uff1a\u6839\u636e\u6d88\u606f\u5904\u7406\u8017\u65f6\uff0c\u628a <code>max.poll.interval.ms<\/code> \u8bbe\u5927\uff08\u6bd4\u5982\u5927\u6d88\u606f\u8bbe\u4e3a 10 \u5206\u949f\uff09\uff0c<code>session.timeout.ms<\/code> \u8bbe\u4e3a 60-120 \u79d2\uff0c\u907f\u514d\u8bef\u5224\u6b7b\u4ea1\uff1b<\/p>\n<p>\u4fdd\u8bc1\u6d88\u8d39\u8005\u7a33\u5b9a\uff1a\u7528\u76d1\u63a7\u76ef\u7d27\u6d88\u8d39\u8005\u8282\u70b9\u7684 CPU\u3001\u5185\u5b58\uff0c\u907f\u514d K8s Pod \u9891\u7e41\u91cd\u542f\uff0c\u6216\u670d\u52a1\u5668\u5b95\u673a\u3002<\/p>\n<h3>2. \u5b89\u5168\u5904\u7406 offset \u63d0\u4ea4<\/h3>\n<p>\u4f18\u5148\u624b\u52a8\u63d0\u4ea4\uff0c\u5173\u95ed\u81ea\u52a8\u63d0\u4ea4\uff08<code>enable.auto.commit=false<\/code>\uff09\uff0c\u5728\u6d88\u606f\u5904\u7406\u5b8c\u6210\u540e\u518d\u8c03\u7528 <code>commitSync()<\/code> \u63d0\u4ea4\uff1b<\/p>\n<p>\u5fc5\u8981\u65f6\u7528\u4e8b\u52a1\uff0c\u5982\u679c\u4e1a\u52a1\u4e0d\u5141\u8bb8\u91cd\u590d\u6d88\u8d39\uff0c\u7ed3\u5408 Kafka \u4e8b\u52a1\uff0c\u786e\u4fdd\u6d88\u606f\u5904\u7406 \u548c offset \u63d0\u4ea4\u539f\u5b50\u6027\u3002<\/p>\n<h3>3. \u4f18\u5316\u5206\u533a\u5206\u914d<\/h3>\n<p>\u9009\u7c98\u6027\u5206\u914d\u7b56\u7565\uff1a\u628a <code>partition.assignment.strategy<\/code> \u8bbe\u4e3a <code>StickyAssignor<\/code>\uff0cRebalance \u65f6\u5c3d\u91cf\u4fdd\u7559\u539f\u6709\u5206\u914d\uff0c\u51cf\u5c11\u5206\u533a\u53d8\u52a8\u3002<\/p>\n<h3>4. \u4f18\u5316\u6d88\u8d39\u903b\u8f91<\/h3>\n<p>\u505a\u597d\u5e42\u7b49\u6027\uff1a\u6bd4\u5982\u7528\u8ba2\u5355 ID \u4f5c\u4e3a\u552f\u4e00\u952e\uff0c\u5373\u4f7f\u91cd\u590d\u6d88\u8d39\uff0c\u4e5f\u4e0d\u4f1a\u5bfc\u81f4\u4e1a\u52a1\u903b\u8f91\u51fa\u9519\uff08\u6bd4\u5982\u91cd\u590d\u6263\u94b1\u3001\u91cd\u590d\u751f\u6210\u8ba2\u5355\uff09\u3002<\/p>\n<h2>\u5199\u5728\u6700\u540e<\/h2>\n<p>Rebalance \u662f\u9762\u8bd5\u7684\u65f6\u5019\u5e38\u7231\u95ee\u7684\u573a\u666f\u9898\uff0c\u5b83\u662f Kafka \u6d88\u8d39\u8005\u7ec4\u7684\u53cc\u5203\u5251\uff0c\u7528\u597d\u80fd\u5747\u8861\u8d1f\u8f7d\uff0c\u7528\u4e0d\u597d\u5c31\u4f1a\u5f15\u53d1\u6545\u969c\uff0c\u6700\u540e\u6211\u603b\u7ed3\u4e0b\uff1a<\/p>\n<ol>\n<li>\u89e6\u53d1 Rebalance \u4e3b\u8981\u662f\u6d88\u8d39\u8005\u6216\u5206\u533a\u53d8\u4e86\u6216\u8d85\u65f6\u4e86\uff1b<\/li>\n<li>\u4e22\u6570\u636e\u548c\u91cd\u590d\u6d88\u8d39\uff0c\u672c\u8d28\u662f offset \u63d0\u4ea4\u548c Rebalance \u65f6\u673a\u6ca1\u914d\u5408\u597d\uff1b<\/li>\n<li>\u4f18\u5316\u8d85\u65f6\u53c2\u6570\u3001\u624b\u52a8\u63d0\u4ea4 offset\u3001\u505a\u597d\u5e42\u7b49\u6027\uff0c\u662f\u51cf\u5c11\u5f71\u54cd\u7684\u5173\u952e\u3002<\/li>\n<\/ol>\n<p><strong>\u770b\u5b8c\u7b49\u4e8e\u5b66\u4f1a\uff0c\u70b9\u4e2a\u8d5e\u5427\uff01\uff01\uff01<\/strong><\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000047325237\">https:\/\/segmentfault.com\/a\/1190000047325237<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u5c0f\u5bcc\uff5e \u6709\u6b21\u4e0a\u7ebf\u76d1\u63a7\u544a\u8b66\u7a81\u7136\u70b8\u4e86\uff0cKafka \u8ba2\u5355 Topic \u6d88\u606f\u79ef\u538b\u91cf\u7a81\u7834 10 \u4e07\u6761\uff0c\u4e0b\u6e38\u652f [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10021037","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10021037"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10021037\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10021037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10021037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10021037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}