Hive使用Spark on Yarn作为执行引擎,yarn资源调度FAIR配置

Hive从1.1之后,支持使用Spark作为执行引擎,配置使用Spark On Yarn作为Hive的执行引擎,首先需要注意以下两个问题:

Hive的版本和Spark的版本要匹配;

具体来说,你使用的Hive版本编译时候用的哪个版本的Spark,那么就需要使用相同版本的Spark,可以在Hive的pom.xml中查看spark.version来确定;

Hive root pom.xml’s <spark.version> defines what version of Spark it was built/tested with.

Spark使用的jar包,必须是没有集成Hive的;

也就是说,编译时候没有指定-Phive.

一般官方提供的编译好的Spark下载,都是集成了Hive的,因此这个需要另外编译。

Note that you must have a version of Spark which does not include the Hive jars. Meaning one which was not built with the Hive profile.

如果不注意版本问题,则会遇到各种错误,比如:

  1. Caused by: java.lang.NoClassDefFoundError: org/apache/hive/spark/client/Job
  2. Caused by: java.lang.ClassNotFoundException: org.apache.hive.spark.client.Job

我这里使用的环境信息如下:

hadoop-2.3.0-cdh5.0.0

apache-hive-2.0.0-bin

spark-1.5.0-bin-hadoop2.3

其中,Spark使用了另外编译的spark-assembly-1.5.0-hadoop2.3.0.jar。编译很简单,下载spark-1.5.0的源码,使用命令:

mvn -Pyarn -Phadoop-2.3 -Dhadoop.version=2.3.0-cdh5.0.0 -DskipTests -Dscala-2.10 clean package

 

首先在hive-site.xml中添加spark.home:

<property>

<name>spark.home</name>

<value>/usr/local/spark/spark-1.5.0-bin-hadoop2.3</value>

</property>

同时也配置了环境变量

export SPARK_HOME=/usr/local/spark/spark-1.5.0-bin-hadoop2.3

这两块应该只需要配置一处即可。

进入hive-cli命令行,使用set的方式设置以下参数:

  1. set spark.master=yarn-cluster; //默认即为yarn-cluster模式,该参数可以不配置
  2. set hive.execution.engine=spark;
  3. set spark.eventLog.enabled=true;
  4. set spark.eventLog.dir=hdfs://cdh5/tmp/sparkeventlog;
  5. set spark.executor.memory=1g;
  6. set spark.executor.instances=50; //executor数量,默认貌似只有2个
  7. set spark.driver.memory=1g;
  8. set spark.serializer=org.apache.spark.serializer.KryoSerializer;

当然,这些参数也可以配置在hive-site.xml中。

接下来就可以执行HQL查询试试了:

hive

hive

可以看到,已经使用Spark作为执行引擎了。

hive

在Yarn的WEB页面上也看到了对应的Application。

在进入hive-cli命令行,第一次执行查询之后,Hive向Yarn申请Container资源,即参数spark.executor.instances指定的数量,另外加一个Driver使用的Container。该Application便会一直运行,直到退出hive-cli,该Application便会成功结束,期间占用的集群资源不会自动释放和回收。如果在hive-cli中修改和executor相关的参数,再次执行查询时候,Hive会结束上一次在Yarn上运行的Application,重新申请资源提交运行。

 

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

Fair Scheduler配置示例 
以上面图中所示的业务场景为例。 
yarn-site.xml中的配置:

<!– scheduler start –>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler</value>
</property>
<property>
<name>yarn.scheduler.fair.allocation.file</name>
<value>/etc/hadoop/conf/fair-scheduler.xml</value>
</property>
<property>
<name>yarn.scheduler.fair.preemption</name>
<value>true</value>
</property>
<property>
<name>yarn.scheduler.fair.user-as-default-queue</name>
<value>true</value>
<description>default is True</description>
</property>
<property>
<name>yarn.scheduler.fair.allow-undeclared-pools</name>
<value>false</value>
<description>default is True</description>
</property>
<!– scheduler end –>

    yarn.resourcemanager.scheduler.class

配置Yarn使用的调度器插件类名;

Fair Scheduler对应的是:

org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler

    yarn.scheduler.fair.allocation.file

配置资源池以及其属性配额的XML文件路径(本地路径);

    yarn.scheduler.fair.preemption

开启资源抢占。

    yarn.scheduler.fair.user-as-default-queue

设置成true,当任务中未指定资源池的时候,将以用户名作为资源池名。这个配置就实现了根据用户名自动分配资源池。

    yarn.scheduler.fair.allow-undeclared-pools

是否允许创建未定义的资源池。

如果设置成true,yarn将会自动创建任务中指定的未定义过的资源池。设置成false之后,任务中指定的未定义的资源池将无效,该任务会被分配到default资源池中。


fair-scheduler.xml中的配置:
<?xml version=”1.0″?>
<allocations>
<!– users max running apps –>
<userMaxAppsDefault>30</userMaxAppsDefault>
<!– queues –>
<queue name=”root”>
<minResources>51200mb,50vcores</minResources>
<maxResources>102400mb,100vcores</maxResources>
<maxRunningApps>100</maxRunningApps>
<weight>1.0</weight>
<schedulingMode>fair</schedulingMode>
<aclSubmitApps> </aclSubmitApps>
<aclAdministerApps> </aclAdministerApps>

<queue name=”default”>
<minResources>10240mb,10vcores</minResources>
<maxResources>30720mb,30vcores</maxResources>
<maxRunningApps>100</maxRunningApps>
<schedulingMode>fair</schedulingMode>
<weight>1.0</weight>
<aclSubmitApps>*</aclSubmitApps>
</queue>

<queue name=”businessA”>
<minResources>5120mb,5vcores</minResources>
<maxResources>20480mb,20vcores</maxResources>
<maxRunningApps>100</maxRunningApps>
<schedulingMode>fair</schedulingMode>
<weight>2.0</weight>
<aclSubmitApps>businessA,szb group_businessA,group_szb</aclSubmitApps>
<aclAdministerApps>businessA,hadoop group_businessA,supergroup</aclAdministerApps>
</queue>

<queue name=”businessB”>
<minResources>5120mb,5vcores</minResources>
<maxResources>20480mb,20vcores</maxResources>
<maxRunningApps>100</maxRunningApps>
<schedulingMode>fair</schedulingMode>
<weight>1</weight>
<aclSubmitApps>businessB group_businessA</aclSubmitApps>
<aclAdministerApps>businessA,hadoop group_businessA,supergroup</aclAdministerApps>
</queue>
<queue name=”businessC”>
<minResources>5120mb,5vcores</minResources>
<maxResources>20480mb,20vcores</maxResources>
<maxRunningApps>100</maxRunningApps>
<schedulingMode>fair</schedulingMode>
<weight>1.5</weight>
<aclSubmitApps>businessC group_businessC</aclSubmitApps>
<aclAdministerApps>businessC,hadoop group_businessC,supergroup</aclAdministerApps>
</queue>
</queue>
</allocations>

minResources
最小资源

maxResources
最大资源

maxRunningApps
最大同时运行application数量

weight
资源池权重

aclSubmitApps
允许提交任务的用户名和组;

格式为: 用户名 用户组

当有多个用户时候,格式为:用户名1,用户名2 用户名1所属组,用户名2所属组

aclAdministerApps
允许管理任务的用户名和组;

格式同上。

根据用户组分配资源池 
假设在生产环境Yarn中,总共有四类用户需要使用集群,开发用户、测试用户、业务1用户、业务2用户。为了使其提交的任务不受影响,我们在Yarn上规划配置了五个资源池,分别为 dev_group(开发用户组资源池)、test_group(测试用户组资源池)、business1_group(业务1用户组资源池)、business2_group(业务2用户组资源池)、default(只分配了极少资源)。并根据实际业务情况,为每个资源池分配了相应的资源及优先级等。

ResourceManager上fair-scheduler.xml配置如下:

    <?xml version="1.0"?>
    <allocations>  
      <!-- users max running apps -->
      <userMaxAppsDefault>30</userMaxAppsDefault>
    <queue name="root">
      <aclSubmitApps> </aclSubmitApps>
      <aclAdministerApps> </aclAdministerApps>

      <queue name="default">
              <minResources>2000mb,1vcores</minResources>
              <maxResources>10000mb,1vcores</maxResources>
              <maxRunningApps>1</maxRunningApps>
              <schedulingMode>fair</schedulingMode>
              <weight>0.5</weight>
              <aclSubmitApps>*</aclSubmitApps>
      </queue>

      <queue name="dev_group">
              <minResources>200000mb,33vcores</minResources>
              <maxResources>300000mb,90vcores</maxResources>
              <maxRunningApps>150</maxRunningApps>
              <schedulingMode>fair</schedulingMode>
              <weight>2.5</weight>
              <aclSubmitApps> dev_group</aclSubmitApps>
              <aclAdministerApps> hadoop,dev_group</aclAdministerApps>
      </queue>

      <queue name="test_group">
              <minResources>70000mb,20vcores</minResources>
              <maxResources>95000mb,25vcores</maxResources>
              <maxRunningApps>60</maxRunningApps>
              <schedulingMode>fair</schedulingMode>
              <weight>1</weight>
              <aclSubmitApps> test_group</aclSubmitApps>
              <aclAdministerApps> hadoop,test_group</aclAdministerApps>
      </queue>

      <queue name="business1_group">
              <minResources>75000mb,15vcores</minResources>
              <maxResources>100000mb,20vcores</maxResources>
              <maxRunningApps>80</maxRunningApps>
              <schedulingMode>fair</schedulingMode>
              <weight>1</weight>
              <aclSubmitApps> business1_group</aclSubmitApps>
              <aclAdministerApps> hadoop,business1_group</aclAdministerApps>
      </queue>


      <queue name="business2_group">
          <minResources>75000mb,15vcores</minResources>
          <maxResources>102400mb,20vcores</maxResources>
          <maxRunningApps>80</maxRunningApps>
          <schedulingMode>fair</schedulingMode>
          <weight>1</weight>
          <aclSubmitApps> business2_group</aclSubmitApps>
          <aclAdministerApps> hadoop,business2_group</aclAdministerApps>
      </queue>

    </queue>
      <queuePlacementPolicy>
          <rule name="primaryGroup" create="false" />
          <rule name="secondaryGroupExistingQueue" create="false" />
          <rule name="default" />
      </queuePlacementPolicy>

    </allocations>

这样,每个用户组下的用户提交任务时候,会到相应的资源池中,而不影响其他业务。

需要注意的是,所有客户端提交任务的用户和用户组的对应关系,需要维护在ResourceManager上,ResourceManager在分配资源池时候,是从ResourceManager上读取用户和用户组的对应关系的,否则就会被分配到default资源池。在日志中出现”UserGroupInformation: No groups available for user”类似的警告。而客户端机器上的用户对应的用户组无关紧要。

每次在ResourceManager上新增用户或者调整资源池配额后,需要执行下面的命令刷新使其生效:

    yarn rmadmin -refreshQueues
    yarn rmadmin -refreshUserToGroupsMappings
-----------------------------------------------------------------------------------------------------------------------------------------

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值