本文记录yarn container内存资源在启动和监控两个过程中涉及的原理关键点,作为源码阅读笔记。如有差错,盼不吝指正。
启动
执行Container启动的组件
- NodeManager
- ContainerManagerImpl
public StartContainersResponse startContainers(StartContainersRequest requests)
private void startContainerInternal
- Container(ContainerImpl)
- Application(ApplicationImpl)
- ContainersLauncher
public void handle(ContainersLauncherEvent event)
- ContainerLaunch
- ContainerManagerImpl
NodeManager由ContainerManagerImpl#startContainers()
处理container启动调用(该方法入参封装了启动需执行进程的shell(linux)或cmd(windows)命令),在该方法中为每个container启动请求实例化Container(ContainerImpl)对象和Application(ApplicationImpl)对象;ContainerImpl、ApplicationImpl与ContainersLauncher组件通过ContainerManagerImpl#dispatcher
(AsyncDispatcher)通过事件消息传递通信,触发各组件启动container的行为。
Container启动流程
以下仅显示与container启动关联的主要流程
ContainersLauncher接收到ContainersLauncherEventType.LAUNCH_CONTAINER事件后,创建ContainerLaunch(implements Callable
)对象,提交给自己内部持有的线程池执行。ContainerLaunch被执行时,实际用ContainerExecutor为container启动jvm进程。
启动原理
客户进程申请container时,会将container启动进程的命令封装到请求参数中,对于需要的资源,会通过启动命令传递。
例如,spark中的YarnAllocator在申请到container之后申请executor进程的启动时,将executorMemory设置为java命令的-Xmx
参数:
// org.apache.spark.deploy.yarn.ExecutorRunnable为YarnAllocator创建的向NodeManager申请启动container进程的任务
private[yarn] class ExecutorRunnable(
container: Option[Container],
conf