{"id":68696,"date":"2026-01-30T14:08:51","date_gmt":"2026-01-30T06:08:51","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/68696.html"},"modified":"2026-01-30T14:08:51","modified_gmt":"2026-01-30T06:08:51","slug":"%e5%a4%a7%e6%95%b0%e6%8d%ae%e6%8a%80%e6%9c%af-flink-%e4%bc%98%e5%8c%96%e4%b9%8b%e6%95%b0%e6%8d%ae%e5%80%be%e6%96%9c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/68696.html","title":{"rendered":"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c"},"content":{"rendered":"<p>\u672c\u535a\u5ba2\u603b\u7ed3\u4e3aB\u7ad9\u5c1a\u7845\u8c37\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316\u89c6\u9891\u7684\u7b14\u8bb0\u603b\u7ed3\u3002  <span class=\"link-card-box\"><span class=\"link-title\">\u5c1a\u7845\u8c37<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0bbf7a.png\" \/>https:\/\/so.csdn.net\/so\/search?q&#061;%E5%B0%9A%E7%A1%85%E8%B0%B7&amp;spm&#061;1001.2101.3001.7020<\/span><\/span><\/p>\n<p><span class=\"link-card-box\"><span class=\"link-title\">\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316<\/span><span class=\"link-link\"><img decoding=\"async\" class=\"link-link-icon\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0bbf7a.png\" \/>https:\/\/www.bilibili.com\/video\/BV1Q5411f76P<\/span><\/span><\/p>\n<h4>1\u3001 \u5224\u65ad\u662f\u5426\u5b58\u5728\u6570\u636e\u503e\u659c<\/h4>\n<p>\u76f8\u540c Task \u7684\u591a\u4e2a Subtask \u4e2d&#xff0c;\u4e2a\u522b Subtask \u63a5\u6536\u5230\u7684\u6570\u636e\u91cf\u660e\u663e\u5927\u4e8e\u5176\u4ed6Subtask \u63a5\u6536\u5230\u7684\u6570\u636e\u91cf&#xff0c;\u901a\u8fc7 Flink Web UI \u53ef\u4ee5\u7cbe\u786e\u5730\u770b\u5230\u6bcf\u4e2a Subtask \u5904\u7406\u4e86\u591a\u5c11\u6570\u636e&#xff0c;\u5373\u53ef\u5224\u65ad\u51fa Flink \u4efb\u52a1\u662f\u5426\u5b58\u5728\u6570\u636e\u503e\u659c\u3002\u901a\u5e38&#xff0c;\u6570\u636e\u503e\u659c\u4e5f\u4f1a\u5f15\u8d77\u53cd\u538b\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"210\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0ccfee.png\" width=\"834\" \/><\/p>\n<p>\u53e6\u5916&#xff0c;\u6709\u65f6 Checkpoint detail \u91cc\u4e0d\u540c SubTask \u7684 State size \u4e5f\u662f\u4e00\u4e2a\u5206\u6790\u6570\u636e\u503e\u659c\u7684\u6709\u7528\u6307\u6807\u3002<\/p>\n<h4>2\u3001 \u6570\u636e\u503e\u659c\u7684\u89e3\u51b3<\/h4>\n<h5>2.1 keyBy \u540e\u7684\u805a\u5408\u64cd\u4f5c\u5b58\u5728\u6570\u636e\u503e\u659c<\/h5>\n<p>\u63d0\u4ea4\u6848\u4f8b&#xff1a;<\/p>\n<p>bin\/flink run \\\\<br \/>\n\u200b<br \/>\n-t yarn-per-job \\\\<br \/>\n\u200b<br \/>\n-d \\\\<br \/>\n\u200b<br \/>\n-p 5 \\\\<br \/>\n\u200b<br \/>\n-Drest.flamegraph.enabled&#061;true \\\\<br \/>\n\u200b<br \/>\n-Dyarn.application.queue&#061;test \\\\<br \/>\n\u200b<br \/>\n-Djobmanager.memory.process.size&#061;1024mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.memory.process.size&#061;2048mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.numberOfTaskSlots&#061;2 \\\\<br \/>\n\u200b<br \/>\n-c com.atguigu.flink.tuning.SkewDemo1 \\\\<br \/>\n\u200b<br \/>\n\/opt\/module\/flink-1.13.1\/myjar\/flink-tuning-1.0-SNAPSHOT.jar \\\\<br \/>\n\u200b<br \/>\n&#8211;local-keyby false <\/p>\n<p>\u67e5\u770b webui&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"202\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0ea260.png\" width=\"823\" \/><\/p>\n<p>1&#xff09;\u4e3a\u4ec0\u4e48\u4e0d\u80fd\u76f4\u63a5\u7528\u4e8c\u6b21\u805a\u5408\u6765\u5904\u7406<\/p>\n<p>Flink \u662f\u5b9e\u65f6\u6d41\u5904\u7406&#xff0c;\u5982\u679c keyby \u4e4b\u540e\u7684\u805a\u5408\u64cd\u4f5c\u5b58\u5728\u6570\u636e\u503e\u659c&#xff0c;\u4e14\u6ca1\u6709\u5f00\u7a97\u53e3&#xff08;\u6ca1\u6512\u6279&#xff09;\u7684\u60c5\u51b5\u4e0b&#xff0c;\u7b80\u5355\u7684\u8ba4\u4e3a\u4f7f\u7528\u4e24\u9636\u6bb5\u805a\u5408&#xff0c;\u662f\u4e0d\u80fd\u89e3\u51b3\u95ee\u9898\u7684\u3002\u56e0\u4e3a\u8fd9\u4e2a\u65f6\u5019 Flink \u662f\u6765\u4e00\u6761\u5904\u7406\u4e00\u6761&#xff0c;\u4e14\u5411\u4e0b\u6e38\u53d1\u9001\u4e00\u6761\u7ed3\u679c&#xff0c;\u5bf9\u4e8e\u539f\u6765 keyby \u7684\u7ef4\u5ea6&#xff08;\u7b2c\u4e8c\u9636\u6bb5\u805a\u5408&#xff09;\u6765\u8bb2&#xff0c;\u6570\u636e\u91cf\u5e76\u6ca1\u6709\u51cf\u5c11&#xff0c;\u4e14\u7ed3\u679c\u91cd\u590d\u8ba1\u7b97&#xff08;\u975e FlinkSQL&#xff0c;\u672a\u4f7f\u7528\u56de\u64a4\u6d41&#xff09;&#xff0c;\u5982\u4e0b\u56fe\u6240\u793a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"326\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060849-697c4af1145be.png\" width=\"845\" \/><\/p>\n<p>2&#xff09;\u4f7f\u7528 LocalKeyBy \u7684\u601d\u60f3<\/p>\n<p>\u5728 keyBy \u4e0a\u6e38\u7b97\u5b50\u6570\u636e\u53d1\u9001\u4e4b\u524d&#xff0c;\u9996\u5148\u5728\u4e0a\u6e38\u7b97\u5b50\u7684\u672c\u5730\u5bf9\u6570\u636e\u8fdb\u884c\u805a\u5408\u540e&#xff0c;\u518d\u53d1\u9001\u5230\u4e0b\u6e38&#xff0c;\u4f7f\u4e0b\u6e38\u63a5\u6536\u5230\u7684\u6570\u636e\u91cf\u5927\u5927\u51cf\u5c11&#xff0c;\u4ece\u800c\u4f7f\u5f97 keyBy \u4e4b\u540e\u7684\u805a\u5408\u64cd\u4f5c\u4e0d\u518d\u662f\u4efb\u52a1\u7684\u74f6\u9888\u3002\u7c7b\u4f3c MapReduce \u4e2d Combiner \u7684\u601d\u60f3&#xff0c;<span style=\"color:#fe2c24\">\u4f46\u662f\u8fd9\u8981\u6c42\u805a\u5408\u64cd\u4f5c\u5fc5\u987b\u662f\u591a\u6761\u6570\u636e\u6216\u8005\u4e00\u6279\u6570\u636e\u624d\u80fd\u805a\u5408&#xff0c;\u5355\u6761\u6570\u636e\u6ca1\u6709\u529e\u6cd5\u901a\u8fc7\u805a\u5408\u6765\u51cf\u5c11\u6570\u636e\u91cf\u3002<\/span>\u4ece Flink LocalKeyBy \u5b9e\u73b0\u539f\u7406\u6765\u8bb2&#xff0c;\u5fc5\u7136\u4f1a\u5b58\u5728\u4e00\u4e2a<span style=\"color:#fe2c24\">\u79ef\u6512\u6279\u6b21<\/span>\u7684\u8fc7\u7a0b&#xff0c;\u5728\u4e0a\u6e38\u7b97\u5b50\u4e2d\u5fc5\u987b\u6512\u591f\u4e00\u5b9a\u7684\u6570\u636e\u91cf&#xff0c;\u5bf9\u8fd9\u4e9b\u6570\u636e\u805a\u5408\u540e\u518d\u53d1\u9001\u5230\u4e0b\u6e38\u3002<\/p>\n<p>\u5b9e\u73b0\u65b9\u5f0f&#xff1a;<\/p>\n<p>\u27a2 DataStreamAPI \u9700\u8981\u81ea\u5df1\u5199\u4ee3\u7801\u5b9e\u73b0<\/p>\n<p>\u27a2 SQL \u53ef\u4ee5\u6307\u5b9a\u53c2\u6570&#xff0c;\u5f00\u542f miniBatch \u548c LocalGlobal \u529f\u80fd&#xff08;\u63a8\u8350&#xff0c;\u540e\u7eed\u4ecb\u7ecd&#xff09;<\/p>\n<p>3&#xff09;DataStream API \u81ea\u5b9a\u4e49\u5b9e\u73b0\u7684\u6848\u4f8b<\/p>\n<p>\u4ee5\u8ba1\u7b97\u6bcf\u4e2a mid \u51fa\u73b0\u7684\u6b21\u6570\u4e3a\u4f8b&#xff0c;keyby \u4e4b\u524d&#xff0c;\u4f7f\u7528 flatMap \u5b9e\u73b0 LocalKeyby \u529f\u80fd<\/p>\n<p>import org.apache.flink.api.common.functions.RichFlatMapFunction;<br \/>\n\u200b<br \/>\nimport org.apache.flink.api.common.state.ListState;<br \/>\n\u200b<br \/>\nimport org.apache.flink.api.common.state.ListStateDescriptor;<br \/>\n\u200b<br \/>\nimport org.apache.flink.api.common.typeinfo.Types;<br \/>\n\u200b<br \/>\nimport org.apache.flink.api.java.tuple.Tuple2;<br \/>\n\u200b<br \/>\nimport org.apache.flink.runtime.state.FunctionInitializationContext;<br \/>\n\u200b<br \/>\nimport org.apache.flink.runtime.state.FunctionSnapshotContext;<br \/>\n\u200b<br \/>\nimport org.apache.flink.streaming.api.checkpoint.CheckpointedFunction;<br \/>\n\u200b<br \/>\nimport org.apache.flink.util.Collector;<br \/>\n\u200b<br \/>\nimport java.util.HashMap;<br \/>\n\u200b<br \/>\nimport java.util.Map;<br \/>\n\u200b<br \/>\nimport java.util.concurrent.atomic.AtomicInteger;<br \/>\n\u200b<br \/>\npublic class LocalKeyByFlatMapFunc extends RichFlatMapFunction&lt;Tuple2&lt;String,<br \/>\n\u200b<br \/>\nLong&gt;, Tuple2&lt;String, Long&gt;&gt; implements CheckpointedFunction {<br \/>\n\u200b<br \/>\n \/\/Checkpoint \u65f6\u4e3a\u4e86\u4fdd\u8bc1 Exactly Once&#xff0c;\u5c06 buffer \u4e2d\u7684\u6570\u636e\u4fdd\u5b58\u5230\u8be5 ListState \u4e2d<br \/>\n\u200b<br \/>\n private ListState&lt;Tuple2&lt;String, Long&gt;&gt; listState;<br \/>\n\u200b<br \/>\n \/\/\u672c\u5730 buffer&#xff0c;\u5b58\u653e local \u7aef\u7f13\u5b58\u7684 mid \u7684 count \u4fe1\u606f<br \/>\n\u200b<br \/>\n private HashMap&lt;String, Long&gt; localBuffer;<br \/>\n\u200b<br \/>\n \/\/\u7f13\u5b58\u7684\u6570\u636e\u91cf\u5927\u5c0f&#xff0c;\u5373&#xff1a;\u7f13\u5b58\u591a\u5c11\u6570\u636e\u518d\u5411\u4e0b\u6e38\u53d1\u9001<br \/>\n\u200b<br \/>\n private int batchSize;<br \/>\n\u200b<br \/>\n \/\/\u8ba1\u6570\u5668&#xff0c;\u83b7\u53d6\u5f53\u524d\u6279\u6b21\u63a5\u6536\u7684\u6570\u636e\u91cf<br \/>\n\u200b<br \/>\n private AtomicInteger currentSize;<br \/>\n\u200b<br \/>\n \/\/\u6784\u9020\u5668&#xff0c;\u6279\u6b21\u5927\u5c0f\u4f20\u53c2<br \/>\n\u200b<br \/>\n public LocalKeyByFlatMapFunc(int batchSize) {<br \/>\n\u200b<br \/>\n this.batchSize &#061; batchSize;<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n &#064;Override<br \/>\n\u200b<br \/>\n public void flatMap(Tuple2&lt;String, Long&gt; value, Collector&lt;Tuple2&lt;String, Long&gt;&gt;<br \/>\n\u200b<br \/>\nout) throws Exception {<br \/>\n\u200b<br \/>\n \/\/ 1\u3001\u5c06\u65b0\u6765\u7684\u6570\u636e\u6dfb\u52a0\u5230 buffer \u4e2d<br \/>\n\u200b<br \/>\n Long count &#061; localBuffer.getOrDefault(value, 0L);<br \/>\n\u200b<br \/>\n localBuffer.put(value.f0, count &#043; 1);<br \/>\n\u200b<br \/>\n \/\/ 2\u3001\u5982\u679c\u5230\u8fbe\u8bbe\u5b9a\u7684\u6279\u6b21&#xff0c;\u5219\u5c06 buffer \u4e2d\u7684\u6570\u636e\u53d1\u9001\u5230\u4e0b\u6e38<br \/>\n\u200b<br \/>\n if (currentSize.incrementAndGet() &gt;&#061; batchSize) {<br \/>\n\u200b<br \/>\n \/\/ 2.1 \u904d\u5386 Buffer \u4e2d\u6570\u636e&#xff0c;\u53d1\u9001\u5230\u4e0b\u6e38<br \/>\n\u200b<br \/>\n for (Map.Entry&lt;String, Long&gt; midAndCount : localBuffer.entrySet()) {<br \/>\n\u200b<br \/>\n out.collect(Tuple2.of(midAndCount.getKey(),<br \/>\n\u200b<br \/>\nmidAndCount.getValue()));<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n \/\/ 2.2 Buffer \u6e05\u7a7a&#xff0c;\u8ba1\u6570\u5668\u6e05\u96f6<br \/>\n\u200b<br \/>\n localBuffer.clear();<br \/>\n\u200b<br \/>\n currentSize.set(0);<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n &#064;Override<br \/>\n\u200b<br \/>\n public void snapshotState(FunctionSnapshotContext context) throws Exception {<br \/>\n\u200b<br \/>\n \/\/ \u5c06 buffer \u4e2d\u7684\u6570\u636e\u4fdd\u5b58\u5230\u72b6\u6001\u4e2d&#xff0c;\u6765\u4fdd\u8bc1 Exactly Once<br \/>\n\u200b<br \/>\n listState.clear();<br \/>\n\u200b<br \/>\n for (Map.Entry&lt;String, Long&gt; midAndCount : localBuffer.entrySet()) {<br \/>\n\u200b<br \/>\n listState.add(Tuple2.of(midAndCount.getKey(), midAndCount.getValue()));<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n &#064;Override<br \/>\n\u200b<br \/>\n public void initializeState(FunctionInitializationContext context) throws Exception {<br \/>\n\u200b<br \/>\n \/\/ \u4ece\u72b6\u6001\u4e2d\u6062\u590d buffer \u4e2d\u7684\u6570\u636e<br \/>\n\u200b<br \/>\n listState &#061; context.getOperatorStateStore().getListState(<br \/>\n\u200b<br \/>\n new ListStateDescriptor&lt;Tuple2&lt;String, Long&gt;&gt;(<br \/>\n\u200b<br \/>\n &#034;localBufferState&#034;,<br \/>\n\u200b<br \/>\n Types.TUPLE(Types.STRING, Types.LONG)<br \/>\n\u200b<br \/>\n )<br \/>\n\u200b<br \/>\n );<br \/>\n\u200b<br \/>\n localBuffer &#061; new HashMap();<br \/>\n\u200b<br \/>\n if (context.isRestored()) {<br \/>\n\u200b<br \/>\n \/\/ \u4ece\u72b6\u6001\u4e2d\u6062\u590d\u6570\u636e\u5230 buffer \u4e2d<br \/>\n\u200b<br \/>\n for (Tuple2&lt;String, Long&gt; midAndCount : listState.get()) {<br \/>\n\u200b<br \/>\n \/\/ \u5982\u679c\u51fa\u73b0 pv !&#061; 0,\u8bf4\u660e\u6539\u53d8\u4e86\u5e76\u884c\u5ea6&#xff0c;ListState \u4e2d\u7684\u6570\u636e\u4f1a\u88ab\u5747\u5300\u5206\u53d1\u5230<br \/>\n\u200b<br \/>\n\u65b0\u7684 subtask \u4e2d<br \/>\n\u200b<br \/>\n \/\/ \u5355\u4e2a subtask \u6062\u590d\u7684\u72b6\u6001\u4e2d\u53ef\u80fd\u5305\u542b\u591a\u4e2a\u76f8\u540c\u7684 mid \u7684 count \u6570\u636e<br \/>\n\u200b<br \/>\n \/\/ \u6240\u4ee5\u6bcf\u6b21\u5148\u53d6\u4e00\u4e0b buffer \u7684\u503c&#xff0c;\u7d2f\u52a0\u518d put<br \/>\n\u200b<br \/>\n long count &#061; localBuffer.getOrDefault(midAndCount.f0, 0L);<br \/>\n\u200b<br \/>\n localBuffer.put(midAndCount.f0, count &#043; midAndCount.f1);<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n \/\/ \u4ece\u72b6\u6001\u6062\u590d\u65f6&#xff0c;\u9ed8\u8ba4\u8ba4\u4e3a buffer \u4e2d\u6570\u636e\u91cf\u8fbe\u5230\u4e86 batchSize&#xff0c;\u9700\u8981\u5411\u4e0b\u6e38\u53d1<br \/>\n\u200b<br \/>\n currentSize &#061; new AtomicInteger(batchSize);<br \/>\n\u200b<br \/>\n } else {<br \/>\n\u200b<br \/>\n currentSize &#061; new AtomicInteger(0);<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n }<br \/>\n\u200b<br \/>\n} <\/p>\n<p>\u63d0\u4ea4 localkeyby \u6848\u4f8b&#xff1a;<\/p>\n<p>bin\/flink run \\\\<br \/>\n\u200b<br \/>\n-t yarn-per-job \\\\<br \/>\n\u200b<br \/>\n-d \\\\<br \/>\n\u200b<br \/>\n-p 5 \\\\<br \/>\n\u200b<br \/>\n-Drest.flamegraph.enabled&#061;true \\\\<br \/>\n\u200b<br \/>\n-Dyarn.application.queue&#061;test \\\\<br \/>\n\u200b<br \/>\n-Djobmanager.memory.process.size&#061;1024mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.memory.process.size&#061;2048mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.numberOfTaskSlots&#061;2 \\\\<br \/>\n\u200b<br \/>\n-c com.atguigu.flink.tuning.SkewDemo1 \\\\<br \/>\n\u200b<br \/>\n\/opt\/module\/flink-1.13.1\/myjar\/flink-tuning-1.0-SNAPSHOT.jar \\\\<br \/>\n\u200b<br \/>\n&#8211;local-keyby true <\/p>\n<p>\u67e5\u770b webui&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"265\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060849-697c4af15c491.png\" width=\"831\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u53ef\u4ee5\u770b\u5230\u6bcf\u4e2a subtask \u5904\u7406\u7684\u6570\u636e\u91cf\u57fa\u672c\u5747\u8861&#xff0c;\u53e6\u5916\u5904\u7406\u7684\u6570\u636e\u91cf\u76f8\u6bd4\u539f\u5148\u5c11\u4e86\u5f88\u591a\u3002<\/span><\/p>\n<h5>2.2 keyBy \u4e4b\u524d\u53d1\u751f\u6570\u636e\u503e\u659c<\/h5>\n<p>\u5982\u679c keyBy \u4e4b\u524d\u5c31\u5b58\u5728\u6570\u636e\u503e\u659c&#xff0c;\u4e0a\u6e38\u7b97\u5b50\u7684\u67d0\u4e9b\u5b9e\u4f8b\u53ef\u80fd\u5904\u7406\u7684\u6570\u636e\u8f83\u591a&#xff0c;\u67d0\u4e9b\u5b9e\u4f8b\u53ef\u80fd\u5904\u7406\u7684\u6570\u636e\u8f83\u5c11&#xff0c;\u4ea7\u751f\u8be5\u60c5\u51b5\u53ef\u80fd\u662f\u56e0\u4e3a\u6570\u636e\u6e90\u7684\u6570\u636e\u672c\u8eab\u5c31\u4e0d\u5747\u5300&#xff0c;\u4f8b\u5982\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0 Kafka \u7684 topic \u4e2d\u67d0\u4e9b partition \u7684\u6570\u636e\u91cf\u8f83\u5927&#xff0c;\u67d0\u4e9b partition \u7684\u6570\u636e\u91cf\u8f83\u5c11\u3002\u5bf9\u4e8e\u4e0d\u5b58\u5728 keyBy \u7684 Flink \u4efb\u52a1\u4e5f\u4f1a\u51fa\u73b0\u8be5\u60c5\u51b5\u3002<\/p>\n<p>\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u9700\u8981\u8ba9 Flink \u4efb\u52a1\u5f3a\u5236\u8fdb\u884c shuffle\u3002\u4f7f\u7528 shuffle\u3001rebalance \u6216 rescale\u7b97\u5b50\u5373\u53ef\u5c06\u6570\u636e\u5747\u5300\u5206\u914d&#xff0c;\u4ece\u800c\u89e3\u51b3\u6570\u636e\u503e\u659c\u7684\u95ee\u9898\u3002<\/p>\n<h5>2.3 keyBy \u540e\u7684\u7a97\u53e3\u805a\u5408\u64cd\u4f5c\u5b58\u5728\u6570\u636e\u503e\u659c<\/h5>\n<p>\u56e0\u4e3a\u4f7f\u7528\u4e86\u7a97\u53e3&#xff0c;\u53d8\u6210\u4e86\u6709\u754c\u6570\u636e&#xff08;\u6512\u6279&#xff09;\u7684\u5904\u7406&#xff0c;\u7a97\u53e3\u9ed8\u8ba4\u662f\u89e6\u53d1\u65f6\u624d\u4f1a\u8f93\u51fa\u4e00\u6761\u7ed3\u679c\u53d1\u5f80\u4e0b\u6e38&#xff0c;\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528\u4e24\u9636\u6bb5\u805a\u5408\u7684\u65b9\u5f0f&#xff1a;<\/p>\n<p>1&#xff09;\u5b9e\u73b0\u601d\u8def&#xff1a;<\/p>\n<p>\u27a2 \u7b2c\u4e00\u9636\u6bb5\u805a\u5408&#xff1a;key \u62fc\u63a5\u968f\u673a\u6570\u524d\u7f00\u6216\u540e\u7f00&#xff0c;\u8fdb\u884c keyby\u3001\u5f00\u7a97\u3001\u805a\u5408<\/p>\n<p><span style=\"color:#fe2c24\">\u6ce8\u610f&#xff1a;<\/span>\u805a\u5408\u5b8c\u4e0d\u518d\u662f WindowedStream&#xff0c;\u8981\u83b7\u53d6 WindowEnd \u4f5c\u4e3a\u7a97\u53e3\u6807\u8bb0\u4f5c\u4e3a\u7b2c\u4e8c\u9636\u6bb5\u5206\u7ec4\u4f9d\u636e&#xff0c;\u907f\u514d\u4e0d\u540c\u7a97\u53e3\u7684\u7ed3\u679c\u805a\u5408\u5230\u4e00\u8d77&#xff09;<\/p>\n<p>\u27a2 \u7b2c\u4e8c\u9636\u6bb5\u805a\u5408&#xff1a;\u6309\u7167\u539f\u6765\u7684 key \u53ca windowEnd \u4f5c keyby\u3001\u805a\u5408<\/p>\n<p>2&#xff09;\u63d0\u4ea4\u539f\u59cb\u6848\u4f8b<\/p>\n<p>bin\/flink run \\\\<br \/>\n\u200b<br \/>\n-t yarn-per-job \\\\<br \/>\n\u200b<br \/>\n-d \\\\<br \/>\n\u200b<br \/>\n-p 5 \\\\<br \/>\n\u200b<br \/>\n-Drest.flamegraph.enabled&#061;true \\\\<br \/>\n\u200b<br \/>\n-Dyarn.application.queue&#061;test \\\\<br \/>\n\u200b<br \/>\n-Djobmanager.memory.process.size&#061;1024mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.memory.process.size&#061;2048mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.numberOfTaskSlots&#061;2 \\\\<br \/>\n\u200b<br \/>\n-c com.atguigu.flink.tuning.SkewDemo2 \\\\<br \/>\n\u200b<br \/>\n\/opt\/module\/flink-1.13.1\/myjar\/flink-tuning-1.0-SNAPSHOT.jar \\\\<br \/>\n\u200b<br \/>\n&#8211;two-phase false <\/p>\n<p>\u67e5\u770b WebUI&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"208\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060849-697c4af18e35e.png\" width=\"833\" \/><\/p>\n<p>3&#xff09;\u63d0\u4ea4\u4e24\u9636\u6bb5\u805a\u5408\u7684\u6848\u4f8b<\/p>\n<p>bin\/flink run \\\\<br \/>\n\u200b<br \/>\n-t yarn-per-job \\\\<br \/>\n\u200b<br \/>\n-d \\\\<br \/>\n\u200b<br \/>\n-p 5 \\\\<br \/>\n\u200b<br \/>\n-Drest.flamegraph.enabled&#061;true \\\\<br \/>\n\u200b<br \/>\n-Dyarn.application.queue&#061;test \\\\<br \/>\n\u200b<br \/>\n-Djobmanager.memory.process.size&#061;1024mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.memory.process.size&#061;2048mb \\\\<br \/>\n\u200b<br \/>\n-Dtaskmanager.numberOfTaskSlots&#061;2 \\\\<br \/>\n\u200b<br \/>\n-c com.atguigu.flink.tuning.SkewDemo2 \\\\<br \/>\n\u200b<br \/>\n\/opt\/module\/flink-1.13.1\/myjar\/flink-tuning-1.0-SNAPSHOT.jar \\\\<br \/>\n\u200b<br \/>\n&#8211;two-phase true \\\\<br \/>\n\u200b<br \/>\n&#8211;random-num 16 <\/p>\n<p>\u67e5\u770b WebUI&#xff1a;\u53ef\u4ee5\u770b\u5230\u7b2c\u4e00\u6b21\u6253\u6563\u7684\u7a97\u53e3\u805a\u5408&#xff0c;\u6bd4\u8f83\u5747\u5300<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"223\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060849-697c4af1d2398.png\" width=\"829\" \/><\/p>\n<p>\u7b2c\u4e8c\u6b21\u805a\u5408&#xff0c;\u4e5f\u6bd4\u8f83\u5747\u5300&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"222\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060850-697c4af22cb00.png\" width=\"832\" \/><\/p>\n<p><span style=\"color:#fe2c24\">\u968f\u673a\u6570\u8303\u56f4&#xff0c;\u9700\u8981\u81ea\u5df1\u53bb\u6d4b&#xff0c;\u56e0\u4e3a keyby \u7684\u5206\u533a\u5668\u662f&#xff08;\u4e24\u6b21 hash*\u4e0b\u6e38\u5e76\u884c\u5ea6\/\u6700\u5927\u5e76\u884c\u5ea6&#xff09;<\/span><\/p>\n<p>SQL \u5199\u6cd5\u53c2\u8003&#xff1a;https:\/\/zhuanlan.zhihu.com\/p\/197299746<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u535a\u5ba2\u603b\u7ed3\u4e3aB\u7ad9\u5c1a\u7845\u8c37\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316\u89c6\u9891\u7684\u7b14\u8bb0\u603b\u7ed3\u3002  \u5c1a\u7845\u8c37https:\/\/so.csdn.net\/so\/search?q%E5%B0%9A%E7%A1%85%E8%B0%B7&amp;spm1001.2101.3001.7020<br \/>\n\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316https:\/\/www.bilibili.com\/video\/BV1Q5411f76P<br \/>\n1\u3001 \u5224\u65ad\u662f\u5426\u5b58\u5728\u6570\u636e\u503e\u659c<br \/>\n\u76f8\u540c Task \u7684\u591a\u4e2a S<\/p>\n","protected":false},"author":2,"featured_media":68688,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1138,323],"topic":[],"class_list":["post-68696","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-flink","tag-323"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/68696.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u535a\u5ba2\u603b\u7ed3\u4e3aB\u7ad9\u5c1a\u7845\u8c37\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316\u89c6\u9891\u7684\u7b14\u8bb0\u603b\u7ed3\u3002 \u5c1a\u7845\u8c37https:\/\/so.csdn.net\/so\/search?q%E5%B0%9A%E7%A1%85%E8%B0%B7&amp;spm1001.2101.3001.7020 \u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316https:\/\/www.bilibili.com\/video\/BV1Q5411f76P 1\u3001 \u5224\u65ad\u662f\u5426\u5b58\u5728\u6570\u636e\u503e\u659c \u76f8\u540c Task \u7684\u591a\u4e2a S\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/68696.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-30T06:08:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0bbf7a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68696.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/68696.html\",\"name\":\"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-30T06:08:51+00:00\",\"dateModified\":\"2026-01-30T06:08:51+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/68696.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/68696.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/68696.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/68696.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u535a\u5ba2\u603b\u7ed3\u4e3aB\u7ad9\u5c1a\u7845\u8c37\u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316\u89c6\u9891\u7684\u7b14\u8bb0\u603b\u7ed3\u3002 \u5c1a\u7845\u8c37https:\/\/so.csdn.net\/so\/search?q%E5%B0%9A%E7%A1%85%E8%B0%B7&amp;spm1001.2101.3001.7020 \u5927\u6570\u636eFlink2.0\u8c03\u4f18&#xff0c;Flink\u6027\u80fd\u4f18\u5316https:\/\/www.bilibili.com\/video\/BV1Q5411f76P 1\u3001 \u5224\u65ad\u662f\u5426\u5b58\u5728\u6570\u636e\u503e\u659c \u76f8\u540c Task \u7684\u591a\u4e2a S","og_url":"https:\/\/www.wsisp.com\/helps\/68696.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-30T06:08:51+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260130060848-697c4af0bbf7a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/68696.html","url":"https:\/\/www.wsisp.com\/helps\/68696.html","name":"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-30T06:08:51+00:00","dateModified":"2026-01-30T06:08:51+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/68696.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/68696.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/68696.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5927\u6570\u636e\u6280\u672f Flink \u4f18\u5316\u4e4b\u6570\u636e\u503e\u659c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/68696","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=68696"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/68696\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/68688"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=68696"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=68696"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=68696"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=68696"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}