This series includes:
- [Big Data] Detailed Explanation of Flink (1): Basics
- [Big Data] Detailed Explanation of Flink (2): Core Part I
- [Big Data] Detailed Explanation of Flink (3): Core Part II
- [Big Data] Detailed Explanation of Flink (4): Core Part III
- [Big Data] Detailed Explanation of Flink (5): Core Part IV
- [Big Data] Detailed Explanation of Flink (6): Source Code Part I
Flink Detailed Explanation (6): Source Code Ⅰ
- 55. What is the submission process of Flink jobs?
- 56. How many ways are there for Flink job submission?
- 57. When is the Flink JobGraph generated?
- 58. What process did JobGraph go through before submitting the cluster?
- 59. Seeing that you mentioned PipeExecutor, what implementation classes does it have?
- 60. What are the characteristics of the Local submission mode, and how is it realized?
- 61. What are the remote submission modes?
- 62. Briefly introduce the Standalone mode?
- 63. Tell me about the yarn cluster submission method?
- 64. What are the characteristics of yarn-session mode?
- 65. What are the characteristics of yarn-per-job mode?
- 66. What are the characteristics of yarn-application mode?
- 67. Tell me about the yarn-session submission process in detail?
- 68. Tell me about the yarn-per-job submission process in detail?
55. What is the submission process of Flink jobs?
Flink's submission process:
- In , start the function in , generate Flink StreamGraph and JobGraph
Flink Client
through reflection , and submit the JobGraph to the Flink cluster.jar
main
- After the Flink cluster receives the JobGraph (
JobManager
received), it translates the JobGraph into an ExecutionGraph, then starts scheduling, and starts consuming data after the startup is successful.
To sum up: Flink core execution process, calls to user APIs can be converted to StreamGraph
→ JobGraph
→ ExecutionGraph
.
56. How many ways are there for Flink job submission?
Flink's job submission is divided into two ways:
- Local mode : that is, the local submission mode, which runs the code directly in IDEA.
- Remote submission method : divided into
standalone
method,yarn
method,K8s
method. Among them,yarn
the method is divided into three submission modes:yarn-per-job
mode,yarn-session
mode,yarn-application
mode.
57. When is the Flink JobGraph generated?
StreamGraph and JobGraph are all Flink Client
generated on the client side, that is, before submitting to the cluster. The schematic diagram is as follows:
58. What process did JobGraph go through before submitting the cluster?
- Users start the Flink cluster, use the command line to submit jobs, and run them
flink run -c WordCount xxx.jar
. - After running the command line, the entry will be invoked through
run
the scriptCliFrontend
, which will trigger the method in the fileCliFrontend
submitted by the user , and then hand it over to the method, and finally trigger a specific execution according to the submission mode.jar
main
PipelineExecuteor
execute
PipelineExecutor
- According to the specific
PipelineExecutor
execution, the user's code will be compiled to generate StreamGraph, and Jobgraph will be generated after optimization.
The specific flow chart is as follows:
59. Seeing that you mentioned PipeExecutor, what implementation classes does it have?
PipeExecutor
In Flink, it is called a pipeline executor . It is an interface and Flink Client
an important part of submitting jobs to the cluster after JobGraph is generated. As mentioned earlier, there are several ways to submit jobs to the cluster, the most commonly used method is yarn
the method, yarn
which includes 3 33 submission modes, mainly usingsession
mode,per-job
mode. application
In the mode, the JobGraph is generated in the cluster.
So PipeExecutor
the implementation class of is as shown in the figure below: (press in the code and CTRL+H
it will come out)
In addition to the above two modes in the red box, use it when running Flink MiniCluster in the IDEA environment for debugging LocalExecutor
.
60. What are the characteristics of the Local submission mode, and how is it realized?
Local is the submission method running in the local IDEA environment. Not on the cluster. Mainly used for debugging, the schematic diagram is as follows:
-
Flink programs
JobClient
are submitted by . -
JobClient
Submit assignments toJobManager
. -
JobManager
Responsible for coordinating resource allocation and job execution. After the resource allocation is completed, the task will be submitted to the correspondingTaskManager
. -
TaskManager
Starts a thread to start executing,TaskManager
and willJobManager
report status changes to , such as started, in progress, or completed. -
After the job execution is complete, the results are sent back to the client.
Source code analysis: through Flink 1.12.2 1.12.21.12.2 The source code is analyzed.
(1) Create and get the corresponding StreamExecutionEnvironment
object: LocalStreamEnvironment
.
Invoke StreamExecutionEnvironment
the object's execute
method.
(2) Get the StreamGraph.
(3) Execute specific PipeLineExecutor
Get localExecutorFactory.
(4) Get the JobGraph.
Generate JobGraph according to the implementation class LocalExecutor of localExecutorFactory.
The above part is all Flink Client
generated in . Since it is submitted in Local mode, a MiniCluster cluster will be created next, and miniCluster.submitJob
the jobGraph to be submitted will be specified by .
(5) Instantiate the MiniCluster cluster.
(6) Return to JobClient
the client.
After executing the above miniCluster.submitJob
to submit the JobGraph to the local cluster, a JobClient
client will be returned, which JobClient
contains some detailed information of the application, including the JobID, the status of the application, and so on. Finally, return to the previous layer of code execution, and the corresponding class is StreamExecutionEnvironment
.
The above is the source code execution process of the Local mode.
61. What are the remote submission modes?
Remote submission method: divided into Standalone method , Yarn method , and K8s method .
- Standalone : Contains
session
the schema. - The Yarn method is divided into three submission modes:
yarn-per-job
mode,yarn-Session
mode,yarn-application
mode. - K8s way : contains
session
mode.
62. Briefly introduce the Standalone mode?
The Standalone mode is the stand-alone version submission method of the Flink cluster . Only one node is used for submission, and the Session mode is commonly used.
Submit the command as follows:
bin/flink run org.apache.flink.WordCount xxx.jar
Client
The client submits tasks toJobManager
.JobManager
Responsible for applying for the resources required for task operation and managing tasks and resources.JobManager
Distribute tasks toTaskManager
execute.TaskManager
RegularlyJobManager
report status to .
63. Tell me about the yarn cluster submission method?
Submission through the yarn cluster is divided into 3 33 ways to submit:
session
modelper-job
modelapplication
model
64. What are the characteristics of yarn-session mode?
Submit the command as follows:
./bin/flink run -t yarn-session \
-Dyarn.application.id=application_XXXX_YY xxx.jar
yarn-session mode : All jobs share cluster resources, poor isolation, JM load bottleneck, andmain
methods are executed on the client. It is suitable for short tasks with short execution time and frequent execution. There is only one job in the clusterJobManager
. In addition, Jobs are randomly assignedTaskManager
.
Features: session-cluster
The mode needs to start the cluster first, then submit the job, and then apply for a space from Yarn, and the resources will remain unchanged forever. If the resource is full, the next job cannot be submitted, and the next job can only be submitted normally after one of the jobs in Yarn is completed and the resources are released. All jobs share Dispatcher
and ResourceManager
share resources, which is suitable for jobs with small scale and short execution time.
65. What are the characteristics of yarn-per-job mode?
Commit command:
./bin/flink run -t yarn-per-job --detached xxx.jar
yarn-per-job mode : Each job starts the cluster independently, with good isolation, JM load balancing, andmain
the method is executed on the client. Inper-job
mode, there is one for each JobJobManager
,TaskManager
and only a single Job for each.
Features: A task corresponds to a job. Each submitted job will apply for resources from Yarn separately according to its own situation until the job is completed. The failure of a job will not affect the normal submission and operation of the next job. Exclusive Dispatcher
and ResourceManager
, resource applications are accepted on demand. Suitable for large-scale long-running jobs.
66. What are the characteristics of yarn-application mode?
Submit the command as follows:
./bin/flink run-application -t yarn-application xxx.jar
yarn-application mode : Each job starts the cluster independently, with good isolation, JM load balancing, andmain
methodsJobManager
are executed on .
In yarn-per-job
both the and yarn-session
modes, the client needs to perform the following three steps, namely:
- Get the dependencies required by the job;
- By performing an environmental analysis and obtaining a logical plan, ie
StreamGraph
→JobGraph
; - Upload dependencies and JobGraph to the cluster.
Only after these are completed, env.execute()
the Flink runtime will be triggered to actually start executing the job through the method. If all users submit jobs on the same client, larger dependencies will consume more bandwidth, and the translation of more complex job logic into JobGraph will also consume more CPU and memory, and the resources of the client will instead become bottleneck.
In order to solve it, the community implemented the Application mode on the basis of the traditional deployment mode. The three things that originally required the client to do have been transferred to JobManager
, that is to say, main()
the method is executed in the cluster (where the entry point is located ApplicationClusterEntryPoint
), and the client only needs to be responsible for initiating the deployment request.
To sum up, the Flink community recommends using yarn-per-job
the or yarn-application
mode to submit applications.
67. Tell me about the yarn-session submission process in detail?
The submission flow chart is as follows:
1. Start the cluster
Flink Client
Yarn ResourceManager
Submit task information to .Flink Client
Upload the application configuration (Flink-conf.yaml
,logback.xml
,log4j.properties
) and related files (Flink Jar, configuration class files, user Jar files, JobGraph objects, etc.) to the distributed storage HDFS.Flink Client
Yarn ResourceManager
Submit task information to .
- Yarn starts the Flink cluster, do 2 22 steps:
- By
Yarn Client
submittingYarn ResourceManager
an application for Flink to create a cluster to ,Yarn ResourceManager
allocate Container resources, and notify the corresponding toNodeManager
start oneApplicationMaster
(every time a Flink Job is submitted, one will be startedApplicationMaster
),ApplicationMaster
which will include the currently to be startedJobManager
and the internal use of Flink itselfResourceManager
. JobManager
Runs in the process asYarnSessionClusterEntryPoint
the entry point for cluster startup. InitializationDispatcher
, which is used internally by FlinkResourceManager
, starts related RPC services, and waits forFlink Client
JobGraph to be submitted through the Rest interface.
- By
2. Job submission
-
Flink Client
Dispatcher
Submit the compiled JobGraph to via Rest .Dispatcher
It is a Rest interface and is not responsible for the actual scheduling and assignment work. -
Dispatcher
After receiving the JobGraph, create one for the jobJobMaster
, hand over the jobJobMaster
,JobMaster
be responsible for job scheduling, manage the life cycle of the job and Task, and build the ExecutionGraph (the parallelized version of the JobGraph, the core data structure of the scheduling layer).
After the above two steps are executed, the job enters the scheduling execution stage.
3. Job scheduling execution
-
JobMaster
Apply for resources fromResourceManager
and start scheduling ExecutionGraph. -
ResourceManager
Add resource requests to the waiting queue, andYarnResourceManager
start the process by applying for a new Container through heartbeatTaskManager
. -
YarnResourceManager
Start, and then load Jar files and other required related resources from HDFS, start in the containerTaskManager
, andTaskManager
startTaskExecutor
. -
TaskManager
After starting,ResourceManager
register with , and report your Slot resource status toResourceManager
. -
ResourceManager
Take out the Slot request from the waiting queue,TaskManager
confirm the availability of resources to , and tell toTaskManager
which Slot is allocated toJobMaster
. -
TaskManager
Reply toJobMaster
a Slot of yourself that belongs to your task, andJobMaser
the Slot will be cached in the SlotPool. -
JobMaster
Schedule the Task toTaskMnager
be executed on the Slot.
68. Tell me about the yarn-per-job submission process in detail?
Submit the command as follows:
./bin/flink run -t yarn-per-job --detached xxx.jar
The submission flow chart is as follows:
1. Start the cluster
Flink Client
Yarn ResourceManager
Submit task information to .Flink Client
Upload the application configuration (Flink-conf.yaml
,logback.xml
,log4j.properties
) and related files (Flink Jar, configuration class files, user Jar files, JobGraph objects, etc.) to the distributed storage HDFS.Flink Client
Yarn ResourceManager
Submit task information to .
- Yarn starts the Flink cluster, do 2 22 steps operation.
- By
Yarn Client
submittingYarn ResourceManager
an application for Flink to create a cluster to ,Yarn ResourceManager
allocate Container resources, and notify the corresponding toNodeManager
start oneApplicationMaster
(every time a Flink Job is submitted, one will be startedApplicationMaster
),ApplicationMaster
which will include the currently to be startedJobManager
and the internal use of Flink itselfResourceManager
. JobManager
Runs in the process asYarnJobClusterEntryPoint
the entry point for cluster startup. InitializationDispatcher
, which is used internally by FlinkResourceManager
, starts related RPC services, and waits forFlink Client
JobGraph to be submitted through the Rest interface.
- By
2. Job submission
ApplicationMaster
StartDispatcher
,Dispatcher
startResourceManager
andJobMaster
(this stepJobMaster
is different from Session, it isDispatcher
pulled by rather than passed by Client).JobMaster
Responsible for job scheduling, managing the life cycle of jobs and Tasks, and constructing ExecutionGraph (the parallelized version of JobGraph, the core data structure of the scheduling layer).
After the above two steps are executed, the job enters the scheduling execution stage.
3. Job scheduling execution
-
JobMaster
ResourceManager
Apply for Slot resources from and start scheduling ExecutionGraph. -
ResourceManager
Add resource requests to the waiting queue, andYarnResourceManager
start the process by applying for a new Container through heartbeatTaskManager
. -
YarnResourceManager
Start, then load Jar files and other required related resources from HDFS, and start in the containerTaskManager
. -
TaskManager
Start internallyTaskExecutor
. -
TaskManager
After starting,ResourceManager
register with , and report your Slot resource status toResourceManager
. -
ResourceManager
Take out the Slot request from the waiting queue,TaskManager
confirm the availability of resources to , and tell toTaskManager
which Slot is allocated toJobMaster
. -
TaskManager
Reply toJobMaster
a Slot of yourself that belongs to your task, andJobMaser
the Slot will be cached in the SlotPool. -
JobMaster
Schedule the Task toTaskMnager
be executed on the Slot.