-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.html
1222 lines (586 loc) · 78.5 KB
/
info.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>介绍 · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="user.html" />
<link rel="prev" href="README.md" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../ch0/preface.html">
<a href="../ch0/preface.html">
开发环境准备:IDEA常用的插件
</a>
<ul class="articles">
<li class="chapter " data-level="1.2.1" data-path="../ch0/RepSearchPractice.html">
<a href="../ch0/RepSearchPractice.html">
Alibaba Java Coding Guidelines
</a>
</li>
<li class="chapter " data-level="1.2.2" data-path="../ch0/RepTaskBasic.html">
<a href="../ch0/RepTaskBasic.html">
SonarLint
</a>
</li>
<li class="chapter " data-level="1.2.3" data-path="../ch0/RepTaskAdvanced.html">
<a href="../ch0/RepTaskAdvanced.html">
ESLint
</a>
</li>
<li class="chapter " data-level="1.2.4" data-path="../ch0/handbook.html">
<a href="../ch0/handbook.html">
Git Commit Template
</a>
</li>
<li class="chapter " data-level="1.2.5" data-path="../ch0/PlantUML.html">
<a href="../ch0/PlantUML.html">
PlantUML
</a>
</li>
<li class="chapter " data-level="1.2.6" data-path="../ch0/DIagram.html">
<a href="../ch0/DIagram.html">
Diagram
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.3" data-path="../ch1/">
<a href="../ch1/">
Spring Cloud
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="../ch1/RepSearchPractice.md">
<span>
检索实操
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="../ch1/RepTaskBasic.html">
<a href="../ch1/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.3.3" data-path="../ch1/RepTaskAdvanced.html">
<a href="../ch1/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="../ch1/handbook.html">
<a href="../ch1/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="../ch2/">
<a href="../ch2/">
第二讲:Linux基本命令使用
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="../ch2/top.html">
<a href="../ch2/top.html">
Top命令详解
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="../ch2/RepTaskBasic.html">
<a href="../ch2/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.4.3" data-path="../ch2/RepTaskAdvanced.html">
<a href="../ch2/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.4.4" data-path="../ch2/handbook.html">
<a href="../ch2/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="../ch3/">
<a href="../ch3/">
第三讲:相关工具入门
</a>
<ul class="articles">
<li class="chapter " data-level="1.5.1" data-path="../ch3/UML.html">
<a href="../ch3/UML.html">
UML类图入门
</a>
</li>
<li class="chapter " data-level="1.5.2" data-path="../ch3/scoop.html">
<a href="../ch3/scoop.html">
SCOOP
</a>
</li>
<li class="chapter " data-level="1.5.3" data-path="../ch3/brewhome.html">
<a href="../ch3/brewhome.html">
BrewHome
</a>
</li>
<li class="chapter " data-level="1.5.4" data-path="../ch3/handbook.html">
<a href="../ch3/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6" data-path="../ch4/">
<a href="../ch4/">
第四讲:Spring Security Oauth2
</a>
<ul class="articles">
<li class="chapter " data-level="1.6.1" data-path="../ch4/oauth2.html">
<a href="../ch4/oauth2.html">
理解OAuth 2.0
</a>
</li>
<li class="chapter " data-level="1.6.2" data-path="../ch4/RepTaskBasic.html">
<a href="../ch4/RepTaskBasic.html">
Spring Security Oauth2(一)
</a>
</li>
<li class="chapter " data-level="1.6.3" data-path="../ch4/RepTaskAdvanced.html">
<a href="../ch4/RepTaskAdvanced.html">
Spring Security Oauth2(二)
</a>
</li>
<li class="chapter " data-level="1.6.4" data-path="../ch4/handbook.html">
<a href="../ch4/handbook.html">
Spring Security Oauth2(三)
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="../ch5/">
<a href="../ch5/">
第五讲:中台
</a>
<ul class="articles">
<li class="chapter " data-level="1.7.1" data-path="../ch5/MiddlePlatform.html">
<a href="../ch5/MiddlePlatform.html">
中台的概念与理解
</a>
</li>
<li class="chapter " data-level="1.7.2" data-path="../ch5/RepTaskBasic.html">
<a href="../ch5/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.7.3" data-path="../ch5/RepTaskAdvanced.html">
<a href="../ch5/RepTaskAdvanced.html">
进阶任务
</a>
</li>
<li class="chapter " data-level="1.7.4" data-path="../ch5/handbook.html">
<a href="../ch5/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.8" data-path="../ch6/">
<a href="../ch6/">
第六讲:单元测试
</a>
<ul class="articles">
<li class="chapter " data-level="1.8.1" data-path="../ch6/junit.html">
<a href="../ch6/junit.html">
mockito简单实用
</a>
</li>
<li class="chapter " data-level="1.8.2" data-path="../ch6/RepTaskBasic.html">
<a href="../ch6/RepTaskBasic.html">
基础任务
</a>
</li>
<li class="chapter " data-level="1.8.3" data-path="../ch6/AssertJ.html">
<a href="../ch6/AssertJ.html">
AssertJ断言机制记录
</a>
</li>
<li class="chapter " data-level="1.8.4" data-path="../ch6/handbook.html">
<a href="../ch6/handbook.html">
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.9" data-path="../ch7/README.md">
<span>
第七讲:缓存
</a>
<ul class="articles">
<li class="chapter " data-level="1.9.1" data-path="../ch7/junit.md">
<span>
mockito简单实用
</a>
</li>
<li class="chapter " data-level="1.9.2" data-path="../ch7/RepTaskBasic.md">
<span>
基础任务
</a>
</li>
<li class="chapter " data-level="1.9.3" data-path="../ch7/AssertJ.md">
<span>
AssertJ断言机制记录
</a>
</li>
<li class="chapter " data-level="1.9.4" data-path="../ch7/handbook.md">
<span>
个人教程
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.10" data-path="../ch8/">
<a href="../ch8/">
辅助
</a>
<ul class="articles">
<li class="chapter " data-level="1.10.1" data-path="../ch8/gitbook.html">
<a href="../ch8/gitbook.html">
gitbook
</a>
</li>
<li class="chapter " data-level="1.10.2" data-path="../ch8/github.html">
<a href="../ch8/github.html">
github
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.11" data-path="README.md">
<span>
第八讲:apache Flink
</a>
<ul class="articles">
<li class="chapter active" data-level="1.11.1" data-path="info.html">
<a href="info.html">
介绍
</a>
</li>
<li class="chapter " data-level="1.11.2" data-path="user.html">
<a href="user.html">
应用场景
</a>
</li>
<li class="chapter " data-level="1.11.3" data-path="install.html">
<a href="install.html">
部署
</a>
</li>
<li class="chapter " data-level="1.11.4" data-path="Flink概述与源码研读准备.html">
<a href="Flink概述与源码研读准备.html">
Flink概述与源码研读准备
</a>
</li>
<li class="chapter " data-level="1.11.5" data-path="从源码构建Flink.html">
<a href="从源码构建Flink.html">
从源码构建Flink
</a>
</li>
<li class="chapter " data-level="1.11.6" data-path="将Flink导入IDE.html">
<a href="将Flink导入IDE.html">
将Flink导入IDE
</a>
</li>
<li class="chapter " data-level="1.11.7" data-path="DataStream API.html">
<a href="DataStream API.html">
DataStream API
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.12" data-path="../ps/handbooks.html">
<a href="../ps/handbooks.html">
备注
</a>
</li>
<li class="chapter " data-level="1.13" data-path="../ps/ref.html">
<a href="../ps/ref.html">
参考文献
</a>
</li>
<li class="chapter " data-level="1.14" data-path="../ps/thanks.html">
<a href="../ps/thanks.html">
致谢
</a>
</li>
<li class="chapter " data-level="1.15" data-path="../no_end/postscript.html">
<a href="../no_end/postscript.html">
后记
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >介绍</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="什么是apache-flink?">什么是Apache Flink?</h1>
<p>Apache Flink 是一个框架和分布式处理引擎,用于在<em>无边界和有边界</em>数据流上进行有状态的计算。Flink 能在所有常见集群环境中运行,并能以内存速度和任意规模进行计算。</p>
<h2 id="架构">架构</h2>
<h3 id="有界数据"><strong>有界数据</strong></h3>
<p>有界数据集对开发者来说都很熟悉,在常规的处理中我们都会从Mysql,文本等获取数据进行计算分析。我们在处理此类数据时,特点就是数据是静止不动的。也就是说,没有再进行追加。又或者说再处理的当时时刻不考虑追加写入操作。所以有界数据集又或者说是有时间边界。在某个时间内的结果进行计算。那么这种计算称之为批计算,批处理。Batch Processing</p>
<h3 id="无界数据"><strong>无界数据</strong></h3>
<p>对于某些场景,类似于Kafka持续的计算等都被认定为无界数据,无界数据集是会发生持续变更的、连续追加的。例如:服务器信令、网络传输流、实时日志信息等。对于此类持续变更、追加的数据的计算方式称之为流计算。Streaming Processing</p>
<p><img src="image/bounded-unbounded.png" alt=""></p>
<h3 id="场景比较"><strong>场景比较</strong></h3>
<p>无界数据与有界数据有点类似于池塘和江河,我们在计算池塘中的鱼的数量时只需要把池塘中当前所有的鱼都计算一次就可以了。那么当前时刻,池塘中有多少条鱼就是结果。 无界数据集类似于江河中的鱼,在奔流到海的过程中每时每刻都会有鱼流过而进入大海。那么计算鱼的数量就像是持续追加的。</p>
<p>有界数据与无界数据是一个相对模糊的概念,如果数据一条一条的经过处理引擎那么则可以认为是无界的,那么如果每间隔一分钟、一小时、一天进行一次计算那么则认为这一段时间的数据又相对是有界的。有界的数据又可以把数据一条一条的通过计算引擎,造成无界的数据集。所以,有界数据集与无界数据集可以存在互换的。因此业内也就开始追寻批流统一的框架。</p>
<p>能够同时实现批处理与流处理的框架有Apache Spark和Apache Flink,而Apache Spark的流处理场景是一个微批场景,也就是它会在特定的时间间隔发起一次计算。而不是每条都会触发计算。也就是相当于把无界数据集切分为小量的有界数据。</p>
<p>Apache Flink基于有界数据集与无界数据集的特点,最终将批处理与流处理混合到同一套引擎当中,用户使用Apache Flink引擎能够同时实现批处理与流处理任务。</p>
<h3 id="部署应用到任意地方"><strong>部署应用到任意地方</strong></h3>
<p>Apache Flink 是一个分布式系统,它需要计算资源来执行应用程序。Flink 集成了所有常见的集群资源管理器,例如 <a href="https://hadoop.apache.org/docs/stable/hadoop-yarn/hadoop-yarn-site/YARN.html" target="_blank">Hadoop YARN</a>、 <a href="https://mesos.apache.org/" target="_blank">Apache Mesos</a> 和 <a href="https://kubernetes.io/" target="_blank">Kubernetes</a>,但同时也可以作为独立集群运行。</p>
<p>Flink 被设计为能够很好地工作在上述每个资源管理器中,这是通过资源管理器特定(resource-manager-specific)的部署模式实现的。Flink 可以采用与当前资源管理器相适应的方式进行交互。</p>
<p>部署 Flink 应用程序时,Flink 会根据应用程序配置的并行性自动标识所需的资源,并从资源管理器请求这些资源。在发生故障的情况下,Flink 通过请求新资源来替换发生故障的容器。提交或控制应用程序的所有通信都是通过 REST 调用进行的,这可以简化 Flink 与各种环境中的集成。</p>
<h3 id="运行任意规模应用"><strong>运行任意规模应用</strong></h3>
<p>Flink 旨在任意规模上运行有状态流式应用。因此,应用程序被并行化为可能数千个任务,这些任务分布在集群中并发执行。所以应用程序能够充分利用无尽的 CPU、内存、磁盘和网络 IO。而且 Flink 很容易维护非常大的应用程序状态。其异步和增量的检查点算法对处理延迟产生最小的影响,同时保证精确一次状态的一致性。</p>
<p><a href="https://flink.apache.org/zh/poweredby.html" target="_blank">Flink 用户报告了其生产环境中一些令人印象深刻的扩展性数字</a></p>
<ul>
<li><p>处理<strong>每天处理数万亿的事件</strong>,</p>
</li>
<li><p>应用维护<strong>几TB大小的状态</strong>, 和</p>
</li>
<li><p>应用<strong>在数千个内核上运行</strong>。</p>
</li>
</ul>
<h3 id="利用内存性能"><strong>利用内存性能</strong></h3>
<p>有状态Flink应用程序针对本地状态访问进行了优化。任务状态始终保持在内存中,或者,如果状态大小超出可用内存,则始终保持在访问有效的磁盘数据结构中。因此,任务通过访问本地(通常在内存中)状态执行所有计算,从而产生非常低的处理延迟。Flink通过定期将本地状态异步指向持久性存储来确保出现故障时一次状态的一致性。</p>
<p><img src="image/local-state.png" alt=""></p>
<h2 id="流处理应用的基本组件">流处理应用的基本组件</h2>
<p>可以由流处理框架构建和执行的应用程序类型是由框架对 <em>流</em>、<em>状态</em>、<em>时间</em> 的支持程度来决定的。在下文中,我们将对上述这些流处理应用的基本组件逐一进行描述,并对 Flink 处理它们的方法进行细致剖析。</p>
<h3 id="流streams">流(Streams)</h3>
<p>显而易见,(数据)流是流处理的基本要素。然而,流也拥有着多种特征。这些特征决定了流如何以及何时被处理。Flink 是一个能够处理任何类型数据流的强大处理框架。</p>
<ul>
<li><strong>有界</strong> 和 <strong>无界</strong> 的数据流:流可以是无界的;也可以是有界的,例如固定大小的数据集。Flink 在无界的数据流处理上拥有诸多功能强大的特性,同时也针对有界的数据流开发了专用的高效算子。</li>
<li><strong>实时</strong> 和 <strong>历史记录</strong> 的数据流:所有的数据都是以流的方式产生,但用户通常会使用两种截然不同的方法处理数据。或是在数据生成时进行实时的处理;亦或是先将数据流持久化到存储系统中——例如文件系统或对象存储,然后再进行批处理。Flink 的应用能够同时支持处理实时以及历史记录数据流。</li>
</ul>
<h3 id="状态state">状态(State)</h3>
<p>只有在每一个单独的事件上进行转换操作的应用才不需要状态,换言之,每一个具有一定复杂度的流处理应用都是有状态的。任何运行基本业务逻辑的流处理应用都需要在一定时间内存储所接收的事件或中间结果,以供后续的某个时间点(例如收到下一个事件或者经过一段特定时间)进行访问并进行后续处理。</p>
<p><img src="image/function-state.png" alt="img"></p>
<p>应用状态是 Flink 中的一等公民,Flink 提供了许多状态管理相关的特性支持,其中包括:</p>
<ul>
<li><strong>多种状态基础类型</strong>:Flink 为多种不同的数据结构提供了相对应的状态基础类型,例如原子值(value),列表(list)以及映射(map)。开发者可以基于处理函数对状态的访问方式,选择最高效、最适合的状态基础类型。</li>
<li><strong>插件化的State Backend</strong>:State Backend 负责管理应用程序状态,并在需要的时候进行 checkpoint。Flink 支持多种 state backend,可以将状态存在内存或者 <a href="https://rocksdb.org/" target="_blank">RocksDB</a>。RocksDB 是一种高效的嵌入式、持久化键值存储引擎。Flink 也支持插件式的自定义 state backend 进行状态存储。</li>
<li><strong>精确一次语义</strong>:Flink 的 checkpoint 和故障恢复算法保证了故障发生后应用状态的一致性。因此,Flink 能够在应用程序发生故障时,对应用程序透明,不造成正确性的影响。</li>
<li><strong>超大数据量状态</strong>:Flink 能够利用其异步以及增量式的 checkpoint 算法,存储数 TB 级别的应用状态。</li>
<li><strong>可弹性伸缩的应用</strong>:Flink 能够通过在更多或更少的工作节点上对状态进行重新分布,支持有状态应用的分布式的横向伸缩。</li>
</ul>