美文网首页
YARN源码解析(3)-作业提交2

YARN源码解析(3)-作业提交2

作者: AlstonWilliams | 来源:发表于2018-03-05 23:34 被阅读48次

    在上一篇文章中,我们初步介绍了一个客户端是如何准备一个Job并提交给YARN.在这篇文章中,我们会简单介绍,在YARN端,是如何提交并启动这个Job的.

    过程

    首先,Client会发送ApplicationSubmissionContext以及ContainerLaunchContext到ResourceManager.

    我们可以看到,这里并不会使用rmClient.submitApplication(request)这个方法的返回结果,而是会在后面一直通过getApplicationReport(applicationId)方法返回的ApplicationReport中的YarnApplicationState来判断Job是否提交成功.

    ApplicationReport中,包含了这么一些信息:

    • ApplicationId
    • Application user
    • Application queue
    • Application name
    • Host on which the ApplicationMaster is running
    • RPC port of the ApplicationMaster
    • Tracking URL
    • YarnApplicationState of the application
    • Diagnostic information in case of errors
    • Start time of the application
    • Client Token of the application(if security is enabled)

    其中的Host on which the ApplicationMaster is running以及RPC port of the ApplicationMaster,就可以让Client知道去哪里读取MapReduce Job的状态信息.

    然后,ResourceManager中的ClientRMService接收到Client发送来的数据结构,并进行一些验证.

    然后,ResourceManager通知YarnScheduler进行资源的分配,为ApplicationMaster分配Container.

    然后,ResourceManager给ApplicationMasterLauncher发送一个事件-AMLauncherEventType.LAUNCH

    然后,ApplicationMasterLauncher在接收到这个事件之后,会启动一个AMLauncher

    然后,这个AMLauncher通知NodeManager的ContainerManagerImpl启动一个ApplicationMaster.

    ContainerManagerImpl在接收到AMLauncher的通知之后,就会检查AMLauncher发送给它的Container相关的信息是否正确.如果验证通过,就将需要的资源进行本地化,供Container执行的时候使用.

    这里我们可以看到,总共有三种visibility的LocalResource:

    • PUBLIC: All the LocalResources that are marked PUBLIC are accessible for containers of any user.
    • PRIVATE: LocalResources that are marked PRIVATE are shared among all applications of the same user on the node.
    • APPLICATION: All the resources that are marked as having the APPLICATION scope are shared only among containers of the same application on the node.

    在资源本地化完成之后,就会通过ContainersLauncher进行容器的加载.

    从上面的代码中,我们可以看到,ContainerLaunch会一直阻塞,直到Container执行完成,并向ApplicationMaster或者ResourceManager报告结果.

    这样ApplicationMaster就启动完成了.

    在ApplicationMaster内部,会根据InputSplit来决定Mapper的数量,通过ResourceRequest向ResourceManager请求资源,然后在NodeManager上进行分配.

    ApplicationMaster为Mapper或者Reducer分配Container的过程,跟上面给ApplicationMaster分配Container的过程,都是一样的,这里我们不再赘述.

    而ApplicationMaster中,具体的工作流程,我们会在以后的文章中进行介绍.

    总结

    其实过程倒是不复杂,但是由于采用状态机的机制,以及基于消息转发器的实现,而且每个组件的状态都有好多种,所以读起来可能有点琐碎,需要画好多流程图来辅助理解.

    相关文章

      网友评论

          本文标题:YARN源码解析(3)-作业提交2

          本文链接:https://www.haomeiwen.com/subject/eyekfftx.html