Dr.ElePhant编译安装与配置

一、Dr.Elephant介绍

1.1 概念背景

DrElephant编译安装配置

Dr.Elephant被定位成一个对Hadoop和Spark任务进行性能监控和调优的工具,它能够自动收集Hadoop平台所有的度量标准,并对收集的数据进行分析,并将分析结果以一种简单且易于理解的形式展示出来。Dr.Elephant的设计目的是通过它对任务的分析结果指导Hadoop/Spark开发者对其任务进行便捷的优化,从而提高开发者的效率以及 Hadoop集群的使用效率。

在Dr.Elephant中定义了一系列的启发式算法(Heuristics), 这些算法提供了对Hadoop/Spark任务进行性能分析的功能,这些启发式算法都是基于一定的Hadoop/Spark任务调优规则而设计的,而且这些启发式算法被设计成插件式的、可配置的,我们可以很方便的在Dr.Elephant中添加自定义的启发式算法。通过对任务进行分析,启发式算法会给我们一些优化建议,基于此,我们可以对任务进行调优,从而使任务的运行更加高效。

 

1.2 为什么要使用Dr.Elephant

针对Hadoop平台优化的工具有很多,有开源的也有收费的工具。但是,大部分工具的用途是简化Hadoop集群的部署和管理,很少有工具能帮助Hadoop开发者优化他们的任务流程。虽然有一些可用的工具是面向这个领域的,但是,他们要不就是不够受用户欢迎,要不就是在扩展性上做的不好,不能很好的支持快速发展的Hadoop框架。Dr.Elephant能够支持Hadoop平台的各种框架,而且对于新框架也有很好的扩展性。比如最近比较火的Spark框架,Dr.Elephant能很好的支持它,这是Dr.Elephant具有高扩展性的体现,对于任何新的Hadoop框架,我们可以配置和使用自定义的启发式算法,从而对新框架的性能进行分析。Dr.Elephant的强大功能能帮助Hadoop/Spark使用者理解他们任务流的内部机制,从而帮助他们轻松的优化这些任务。

1.3 核心功能点

  • 启发式算法是基于规则的,且是插件式、可配置的,具有良好扩展性,能分析各种各样的框架
  • 创造性的和Azkaban调度器集成,并且支持任意一种Hadoop任务调度器,例如Oozie
  • 能自动统计所有历史任务的性能
  • 能实现Job级别的任务流性能比较
  • 对Hadoop和Spark任务能进行性能诊断
  • 具有良好的扩展性,能支持新种类的任务、应用和调度器
  • 提供REST API,用户能够通过API获取所有信息

 

1.4 Dr.Elephant工作原理

Dr.Elephant定期从Hadoop平台的YARN资源管理中心获取近期所有的任务,这些任务既包含成功的任务,也包含哪些失败的任务。每个任务的元数据,例如任务计数器、配置信息以及运行信息都可以从Hadoop平台的历史任务服务端获取到。一旦获取到了任务的元数据,Dr.Elephant就基于这些元数据运行启发式算法,然后会产生一份该启发式算法对该任务性能的诊断报告。根据每个任务的执行情况,这份报告会为该任务标记一个待优化的严重性级别。严重性级别一共分为五级,报告会对该任务产生一个级别的定位,并通过级别来表明该任务中存在的性能问题的严重程度。

 

1.5 Dr.Elephant的一个应用场景

在LinkedIn,Hadoop平台的开发者使用Dr.Elephant来做很多事 情。比如,监控每个任务在集群上性能,或者用来分析理解为什么某个任务执行性能较差以及怎么样去优化它们,还可以用来比较任务的多次运行情况等等。在 LinkedIn,Dr.Elephant已经成为一个标准,只有被Dr.Elephant检查合格的任务才可以放到生产环境上执行。

 

1.6 任务优化分析示例

在Dr.Elephant的UI上,包含了近期所有的任务,以及这些任务的分析数据。

DrElephant编译安装配置

一旦一个任务执行完成,Dr.Elephant就会将它的分析信息加载到UI中。用户也 可以在UI的搜索页来搜索某个任务。搜索任务时,可以通过job id、任务的执行url(当用任务调度器调度任务时,是可以获取到执行url的)、任务的发起者、任务的结束时间、任务类型来进行任务搜索,甚至可以通过 任务分析报告中的等级来进行任务搜索。

DrElephant编译安装配置

搜索页中展示的搜索结果从高层面对任务的性能进行分析,通过使用不同的颜色代表不同的严重性等级,来表示任务和启发式算法的综合情况。当UI中某个任务的颜色标记为红色时,表明这个任务的性能问题很严重,亟待优化;当任务的颜色标记为绿色时,表明这个任务的运行效率很高。

DrElephant编译安装配置

在UI中点击每个任务块,可以得到每个任务的完整诊断报告。在诊断报告中,每个启发式算法都会对该任务生成一个详细的分析。点击每个链接可以看到每个启发式算法对应的分析结果,这个结果提供了针对该任务在该启发式算法上的优化建议。

DrElephant编译安装配置


二、创建Dr.Elephant项目

2.1 获取源代码

从Github仓库中获取代码,dr-elephant。下文中的版本2.0.4是很早的版本,是在本地环境中测试验证通过的版本,github上已经找不到了,本地有保存。其他版本在编译和部署过程中都有问题。

 

2.2编译代码

Dr.Elephant项目基于Play框架开发,所以开发Dr.Elephant项目的第一步就是安装Play框架。可以在下面这个链接下载到最新版本的Play框架:https://www.playframework.com/download。安装Play框架之后,一定要将play命令添加到环境变量$PATH中。我们这里下载的是play-2.2.6

export PATH=/root/play-2.2.6/:$PATH

执行编译脚本,就可以对Dr.Elephant项目进行编译。

编译正确执行完过后会在/dist目录下生成一个zip包,该zip文件就是最终输出文件,解压即可使用。

在执行编译命令时,可以选择带一个参数选项来指明编译的配置文件。在这个配置文件中,可以指定Hadoop或者Spark的版本信息。在不指定的情况下,默认的配置是Hadoop2.3.0以及Spark1.4.0 。在配置文件中除了可以指定以上两个版本信息外,还可以通过play_opts参数来指定play/sbt的选项。

$> ./compile.sh [./app-conf/compile.conf]

$> cat compile.conf

hadoop_version = 2.3.0            // The Hadoop version to compile with

spark_version = 1.4.0              // The Spark version to compile with

play_opts="-Dsbt.repository.config=app-conf/resolver.conf"  // Other play/sbt options

我们环境下的具体配置文件内容为:

[[email protected] dr-elephant-2.0.4]# cat app-conf/compile.conf

hadoop_version=2.7.1

spark_version=1.6.1

play_opts="-Dsbt.repository.config=app-conf/resolver.conf"

resolver.conf是play中sbt和mvn解析获取仓库地址的配置文件,我们环境下配置为:

[[email protected] dr-elephant-2.0.4]# cat app-conf/resolver.conf

[repositories]

  local

  #maven2: http://repo.maven.apache.org/maven2

  #maven2-ivy: http://repo.maven.apache.org/maven2, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  #activator-launcher-local: file:////${activator.local.repository-${activator.home-${user.home}/.activator}/repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  #osc: http://maven.oschina.net/content/groups/public/

  #activator-local: file:////${activator.local.repository-E:/development/Tools/typesafe-activator-1.3.9/activator-dist-1.3.9//repository}, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

  #maven-central

  #typesafe-releases: http://repo.typesafe.com/typesafe/releases

  #typesafe-ivy-releasez: http://repo.typesafe.com/typesafe/ivy-releases, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]

这样配置的话,编译过程中resolve完ivy.xml文件后,会提示我们在local目录下没有对应的jar包,我们可以手动去下载然后按照对应名称放到对应目录***释部分让设备自己去下的话可能太耽误时间,另外设备不一定能连接外网)

以上的三个参数如果没有通过配置文件指定,默认就会使用上面列举出的默认值。如果想指定一个固定的仓库,可以通过设置sbt.repository.config 为resolver文件的位置来实现,如上面所示即可。

 

2.3启动单元测试

调用编译脚本,就会运行所有的单元测试程序。

 

2.3.1本地部署测试Dr.Elephant

 

(1)Yarn和Hadoop/Spark

在本地部署Dr.Elephant之前,先要在本地安装Hadoop和 Spark(Yarn模式),而且要确保资源管理器(Resource Manager)和历史任务服务(Job History Service)程序的正确运行。关于Yarn上MapReduce任务的伪分布式模式可以参考伪分布式部署。

指定环境变量HADOOP_HOME:

$>export HADOOP_HOME=/path/to/hadoop/home

$>export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop

将Hadoop的Home目录添加到系统环境变量,Dr.Elephant会使用到Hadoop的Classpath中的某些Class文件。

$>export PATH=$HADOOP_HOME/bin:$PATH

 

(2)数据库

Dr.Elephant需要将任务信息和任务的诊断信息存储在本地数据库MySQL中。

在本地安装启动MySQL。可以在这个链接下载到最新版本的MySQL:https://www.mysql.com/downloads/ 。Dr.Elephant目前只支持MySQL5.5以上的版本。在MySQL中创建一个数据库,名称为drelephant,有关于数据库的配置可查看和修改app-conf目录下的elephant.conf文件

具体配置:

DrElephant配置mysql数据库

[[email protected] dr-elephant-2.0.4]# systemctl start mariadb.service

[[email protected] dr-elephant-2.0.4]# systemctl status mariadb.service

● mariadb.service - MariaDB database server

   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)

   Active: active (running) since Wed 2016-07-27 11:08:32 CST; 10s ago

  Process: 20074 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)

  Process: 19986 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)

 Main PID: 20073 (mysqld_safe)

   CGroup: /system.slice/mariadb.service

           ├─20073 /bin/sh /usr/bin/mysqld_safe --basedir=/usr

           └─20230 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log ...

 

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: The latest information about MariaDB is available at http://mariadb.org/.

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: You can find additional information about the MySQL part at:

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: http://dev.mysql.com

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: Support MariaDB development by buying support/new features from MariaDB

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: Corporation Ab. You can contact us about this at [email protected]

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: Alternatively consider joining our community based development effort:

Jul 27 11:08:29 node2.dcom mariadb-prepare-db-dir[19986]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

Jul 27 11:08:29 node2.dcom mysqld_safe[20073]: 160727 11:08:29 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.

Jul 27 11:08:29 node2.dcom mysqld_safe[20073]: 160727 11:08:29 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

Jul 27 11:08:32 node2.dcom systemd[1]: Started MariaDB database server.

 

[[email protected] dr-elephant-2.0.4]# mysql -u root   //这里是之前配置过无密码登陆的

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 3

Server version: 5.5.44-MariaDB MariaDB Server

 

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]>

    -> \h

 

General information about MariaDB can be found at

http://mariadb.org

 

List of all MySQL commands:

Note that all text commands must be first on line and end with ';'

?         (\?) Synonym for `help'.

clear     (\c) Clear the current input statement.

connect   (\r) Reconnect to the server. Optional arguments are db and host.

delimiter (\d) Set statement delimiter.

edit      (\e) Edit command with $EDITOR.

ego       (\G) Send command to mysql server, display result vertically.

exit      (\q) Exit mysql. Same as quit.

go        (\g) Send command to mysql server.

help      (\h) Display this help.

nopager   (\n) Disable pager, print to stdout.

notee     (\t) Don't write into outfile.

pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.

print     (\p) Print current command.

prompt    (\R) Change your mysql prompt.

quit      (\q) Quit mysql.

rehash    (\#) Rebuild completion hash.

source    (\.) Execute an SQL script file. Takes a file name as an argument.

status    (\s) Get status information from the server.

system    (\!) Execute a system shell command.

tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.

use       (\u) Use another database. Takes database name as argument.

charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.

warnings  (\W) Show warnings after every statement.

nowarning (\w) Don't show warnings after every statement.

 

For server side help, type 'help contents'

 

MariaDB [(none)]> create database drelephant;

Query OK, 1 row affected (0.01 sec)

 

MariaDB [(none)]> print;

--------------

print

--------------

 

unknown [elephant]> connect drelephant;

Connection id:    5

Current database: drelephant

MariaDB [drelephant]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| drelephant         |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)

 

MariaDB [drelephant]> use drelephant;

Database changed

MariaDB [drelephant]> show tables;

+-----------------------------------+

| Tables_in_drelephant              |

+-----------------------------------+

| play_evolutions                   |

| yarn_app_heuristic_result         |        //出现这些个表格说明drelephant安装配置成功了

| yarn_app_heuristic_result_details |

| yarn_app_result                   |

+-----------------------------------+

4 rows in set (0.00 sec)

 

MariaDB [drelephant]>

在Dr.Elephant的配置文件app-conf/elephant.conf中可以配置数据库的url、数据库名称、用户名称和密码。

 

(3)使用其他数据库

目前,Dr.Elephant默认是用MySQL数据库。我们可以在演化文件(evolution files)中看到MySQL的DDL声明。如果我们希望能够使用其他的数据库,可以参考https://www.playframework.com/documentation/2.6.x/ScalaDatabase进行配置。

 

2.3.2本地安装Dr.Elephant

完成上面的安装前准备之后,可以开始在本地安装Dr.Elephant。

运行Hadoop,并运行Hadoop历史任务服务。

$> $HADOOP_HOME/sbin/mr-jobhistory-daemon.sh start historyserver

编译Dr.Elephant项目,生成分布式部署的包。进入项目中的dist文件夹,这个文件夹包含了需要进行分布式部署的zip包。使用unzip命令将zip包解包,然后修改dr-elephant的发布目录。以后的描述中,我们都用DR_RELEASE来表示dr-elephant的发布目录。

$>cd dist; unzip dr-elephant*.zip;cd dr-elephant*

创建完数据库之后,首次运行Dr.Elephant时,需要启动演化功能 (evolution)。启动演化功能时,可以在elephant.conf配置文件中参数jvm_props添加(或者将对jvm_props的注释符去掉)-Devolutionplugin=enable -DapplyEvolutions.default=true

$> vim ./app-conf/elephant.conf

jvm_props=" -Devolutionplugin=enabled -DapplyEvolutions.default=true"

启动Dr.Elephant时,运行start.sh脚本,并在参数中带上应用程序的配置文件目录。

$> $DR_RELEASE/bin/start.sh $DR_RELEASE/../../app-conf

如果需要停止Dr.Elephant,运行:

$> $DR_RELEASE/bin/stop.sh

当Dr.Elephant运行成功之后,可以通过”ip:port”(localhost:8080)在浏览器中打开UI。Port的值可以在app-conf目录下的elephant.conf文件中修改(因为ambari-server的port也是8080):

[[email protected] dr-elephant-2.0.4]# cat app-conf/elephant.conf

# Play application server port

port=8090

Dr.Elephant的日志默认输出到logs目录下的application.log文件中

 

2.4项目结构

app                             → Contains all the source files

 └ com.linkedin.drelepahnt      → Application Daemons

 └ org.apache.spark             → Spark Support

 └ controllers                  → Controller logic

 └ models                       → Includes models that Map to DB

 └ views                        → Page templates

app-conf                        → Application Configurations

 └ elephant.conf                → Port, DB, Keytab and other JVM Configurations (Overrides application.conf)

 └ FetcherConf.xml              → Fetcher Configurations

 └ HeuristicConf.xml            → Heuristic Configurations

 └ JobTypeConf.xml              → JobType Configurations

conf                            → Configurations files

 └ evolutions                   → DB Schema

 └ application.conf             → Main configuration file

 └ log4j.properties             → log configuration file

 └ routes                       → Routes definition

images

 └ wiki                         → Contains the images used in the wiki documentation

public                          → Public assets

 └ assets                       → Library files

 └ css                          → CSS files

 └ images                       → Image files

 └ js                           → JavaScript files

scripts

 └ start.sh                     → Starts Dr. Elephant

 └ stop.sh                      → Stops Dr. Elephant

test                            → Source folder for unit tests

compile.sh                      → Compiles the application

 

2.5 启发式算法

针对MapReduce和Spark,Dr.Elephant已经实现了一系列的启发式算法。如果想对启发式算法进行更深入的了解,请阅读“启发式算法指南”部分。所有的启发式算法都是插件式的,可以简单的配置使用。

 

2.5.1 添加新的启发式算法

我们可以按照下面的步骤去添加自定义的启发式算法,并把它添加到Dr.Elephant中。

  1. 创建新的启发式算法,并完成测试。
  2. 为该启发式算法创建一个新的view页,例如helpMapperSpill.scala.html。
  3. 在HeuristicConf.xml文件中添加该启发式算法的详情。
  4. HeuristicConf.xml文件中启发式算法的详情包含以下内容:

           i. 应用程序类型:是mapreduce程序还是spark程序。

           ii. 启发式算法名称。

          iii. 类名称:类名的全称。

          iv. view页的名称

           v. 该启发式算法适用的Hadoop版本号

5.  启动Dr.Elephant,就包含了新的启发式算法

HeuristicConf.xm文件示例:

<heuristic>

<applicationtype>mapreduce</applicationtype>

<heuristicname>Mapper GC</heuristicname>

<classname>com.linkedin.drelephant.mapreduce.heuristics.MapperGCHeuristic</classname>

<viewname>views.html.help.mapreduce.helpGC</viewname>

</heuristic>

 

2.5.2 配置启发式算法

每个启发式算法都有一些阈值,用来计算不同的待优化等级。我们可以在HeuristicConf.xml文件中指定这些阈值。

下面给出一个例子,介绍如何指定启发式算法的阈值:

<heuristic>

<applicationtype>mapreduce</applicationtype>

<heuristicname>Mapper Data Skew</heuristicname>

<classname>com.linkedin.drelephant.mapreduce.heuristics.MapperDataSkewHeuristic</classname>

<viewname>views.html.help.mapreduce.helpMapperDataSkew</viewname>

<params>

  <num_tasks_severity>10, 50, 100, 200</num_tasks_severity>

  <deviation_severity>2, 4, 8, 16</deviation_severity>

  <files_severity>1/8, 1/4, 1/2, 1</files_severity>

</params>

</heuristic>

 

2.6 分数计算

在Dr.Elephant中,使用启发式算法来分析运行完成的任务,会得到一个分数。这个分数的计算方法比较简单,可以通过将待优化等级的值乘以作业(task)数量。

int score =0;

if (severity != Severity.NONE&& severity!= Severity.LOW) {

    score = severity.getValue()* tasks;

}

return score;

 

Dr.Elephant可以计算不同任务类型的得分:

作业分数:所有作业的待优化等级数值之和

任务分数:该任务中所有的作业分数之和

任务流分数:该任务流中所有的任务分数之和

三、参考资料

 

相关文章: