首页 > 代码库 > yarn状态机可视化

yarn状态机可视化

YARN中实现了多个状态机对象,包括ResourceManager中的RMAppImpl、RMApp-AttemptImpl、RMContainerImpl和RMNodeImpl,NodeManager中的ApplicationImpl、ContainerImpl和LocalizedResource,MRAppMaster中的JobImpl、TaskImpl和TaskAttemptImpl等。为了便于用户查看这些状态机的状态变化以及相关事件,YARN提供了一个状态机可视化工具,具体操作步骤如下。

步骤1 将状态机转化为graphviz(.gv)格式的文件,在源代码根目录下执行编译命令如下:

mvn compile -Pvisualize

经过该步骤后,本地目录中生成了ResourceManager.gv、NodeManager.gv和MapReduce.gv三个graphviz格式的文件。NodeManager.gv文件中LocalizedResource状态机部分内容如下:

subgraph cluster_LocalizedResource {
label="LocalizedResource"
  "LocalizedResource.FAILED" [ label = FAILED ];
  "LocalizedResource.DOWNLOADING" [ label = DOWNLOADING ];
  "LocalizedResource.DOWNLOADING" -> "LocalizedResource.DOWNLOADING" [ label = "REQUEST,\nRELEASE" ];
  "LocalizedResource.DOWNLOADING" -> "LocalizedResource.FAILED" [ label = "LOCALIZATION_FAILED" ];
  "LocalizedResource.DOWNLOADING" -> "LocalizedResource.LOCALIZED" [ label = "LOCALIZED" ];
  "LocalizedResource.INIT" [ label = INIT ];
  "LocalizedResource.INIT" -> "LocalizedResource.DOWNLOADING" [ label = "REQUEST" ];
  "LocalizedResource.LOCALIZED" [ label = LOCALIZED ];
  "LocalizedResource.LOCALIZED" -> "LocalizedResource.LOCALIZED" [ label = "REQUEST,\nRELEASE" ];
}

步骤2 使用可视化包graphviz中的相关命令生成状态机图,Shell命令具体如下:

dot -Tpng NodeManager.gv > NodeManager.png

如果尚未安装graphviz包,操作该步骤之前先要安装该包,cent os安装命令如下:

sudo yum install graphviz

打开NodeManager.png,如下图所示(为了便于展示,分拆成了两个图):




yarn状态机可视化