admin管理员组

文章数量:1611572

1. 应用场景

本文只关注配置,关于调度器的算法以及核心内容将在下一篇介绍。 Capacity Scheduler是YARN中默认的资源调度器,但是在默认情况下只有root.default 一个queue。而当不同用户提交任务时,任务都会在这个队里里面按优先级先进先出,大大影响了多用户的资源使用率。现在公司的任务主要分为三种:

  • 每天晚上进行的日常任务dailyTask,这些任务需要在尽可能短的时间内完成,且由于关乎业务,所以一旦启动就必须提供尽可能多的资源,因为我分配的资源也最多 70%,队列名位dailyTask。
  • 白天,通过Hive来获取一些数据信息,这部分任务由其他的同事进行操作,对查询速度要求并不是很高,且断断续续的,我分配的中等20%,队列名hive。
  • 最后这种我定义为是其他的类型,长时间的一些数据处理任务,分配资源少一些10%,队列名为default(这个队列一定要存在)。

需要说明的是以下几点:

  • 单个队列比如dailyTask,如果有多个任务在队列里面,那么只能有一个任务在运行,其他任务在等待。
  • 虽然我设置了队列的资源容量capacity,但是由于资源是共享式的,所以如果有其他queue的资源处理空闲,那么该queue就会从空闲的queue借资源,但是该queue资源最多不会超过 maximum-capacity。所以dailyTask由于在晚上时候运行,其他queue都是空闲的,所以它的实际资源利用率基本上是 maximum-capacity,也就是100%。而白天只有Hive队列和Default队列在使用,所以他们两会共享dailyTask的空余的70%资源。
  • 如果在HIVE队列和Default队列都在运行时候,突然dailyTask队列add进了任务了,dailyTask就会等待借出去的资源被回收再分配。
  • 目前这样的配置,刚好符合现在的需求,相比于公平调度器较为复杂的配置,目前容量调度器无疑更合适,所以先选择容量调度器。

2. 配置

1.首先在yarn-site.xml中配置调度器类型

 
  1. <property>

  2. <name>yarn.resourcemanager.scheduler.class</name>

  3. <value>org.apache.hadoop.yarn.server.resourcemanager.scheduler.capacity.CapacityScheduler</value>

  4. </property>

2.在Capacity Scheduler专属配置文件capacity-scheduler.xml,需要说明默认存在root的queue,其他的队列都是它的子队列。

  • yarn.scheduler.capacity.root.default.maximum-capacity,队列最大可使用的资源率。
  • capacity:队列的资源容量(百分比)。 当系统非常繁忙时,应保证每个队列的容量得到满足,而如果每个队列应用程序较少,可将剩余资源共享给其他队列。注意,所有队列的容量之和应小于100。
  • maximum-capacity:队列的资源使用上限(百分比)。由于存在资源共享,因此一个队列使用的资源量可能超过其容量,而最多使用资源量可通过该参数限制。
  • user-limit-factor:单个用户最多可以使用的资源因子,默认情况为1,表示单个用户最多可以使用队列的容量不管集群有空闲,如果该值设为5,表示这个用户最多可以使用5capacity的容量。实际上单个用户的使用资源为 min(user-limit-factorcapacity,maximum-capacity)。这里需要注意的是,如果队列中有多个用户的任务,那么每个用户的使用量将稀释。
  • minimum-user-limit-percent:每个用户最低资源保障(百分比)。任何时刻,一个队列中每个用户可使用的资源量均有一定的限制。当一个队列中同时运行多个用户的应用程序时中,每个用户的使用资源量在一个最小值和最大值之间浮动,其中,最小值取决于正在运行的应用程序数目,而最大值则由minimum-user-limit-percent决定。比如,假设minimum-user-limit-percent为25。当两个用户向该队列提交应用程序时,每个用户可使用资源量不能超过50%,如果三个用户提交应用程序,则每个用户可使用资源量不能超多33%,如果四个或者更多用户提交应用程序,则每个用户可用资源量不能超过25%。
  • maximum-applications :集群或者队列中同时处于等待和运行状态的应用程序数目上限,这是一个强限制,一旦集群中应用程序数目超过该上限,后续提交的应用程序将被拒绝,默认值为10000。所有队列的数目上限可通过参数yarn.scheduler.capacity.maximum-applications设置(可看做默认值),而单个队列可通过参数yarn.scheduler.capacity..maximum-applications设置适合自己的值。
  • maximum-am-resource-percent:集群中用于运行应用程序ApplicationMaster的资源比例上限,该参数通常用于限制处于活动状态的应用程序数目。该参数类型为浮点型,默认是0.1,表示10%。所有队列的ApplicationMaster资源比例上限可通过参数yarn.scheduler.capacity. maximum-am-resource-percent设置(可看做默认值),而单个队列可通过参数yarn.scheduler.capacity.. maximum-am-resource-percent设置适合自己的值。
  • state :队列状态可以为STOPPED或者RUNNING,如果一个队列处于STOPPED状态,用户不可以将应用程序提交到该队列或者它的子队列中,类似的,如果ROOT队列处于STOPPED状态,用户不可以向集群中提交应用程序,但正在运行的应用程序仍可以正常运行结束,以便队列可以优雅地退出。
  • acl_submit_applications:限定哪些Linux用户/用户组可向给定队列中提交应用程序。需要注意的是,该属性具有继承性,即如果一个用户可以向某个队列中提交应用程序,则它可以向它的所有子队列中提交应用程序。配置该属性时,用户之间或用户组之间用“,”分割,用户和用户组之间用空格分割,比如“user1, user2 group1,group2”。
  • acl_administer_queue:为队列指定一个管理员,该管理员可控制该队列的所有应用程序,比如杀死任意一个应用程序等。同样,该属性具有继承性,如果一个用户可以向某个队列中提交应用程序,则它可以向它的所有子队列中提交应用程序。
 
  1. <property>

  2. <name>yarn.scheduler.capacity.maximum-applications</name>

  3. <value>10000</value>

  4. <description>

  5. Maximum number of applications that can be pending and running.

  6. </description>

  7. </property>

  8. <property>

  9. <name>yarn.scheduler.capacity.maximum-am-resource-percent</name>

  10. <value>0.1</value>

  11. <description>

  12. Maximum percent of resources in the cluster which can be used to run

  13. application masters i.e. controls number of concurrent running

  14. applications.

  15. </description>

  16. </property>

  17. <property>

  18. <name>yarn.scheduler.capacity.resource-calculator</name>

  19. <value>org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator</value>

  20. <description>

  21. The ResourceCalculator implementation to be used to compare

  22. Resources in the scheduler.

  23. The default i.e. DefaultResourceCalculator only uses Memory while

  24. DominantResourceCalculator uses dominant-resource to compare

  25. multi-dimensional resources such as Memory, CPU etc.

  26. </description>

  27. </property>

  28. <property>

  29. <name>yarn.scheduler.capacity.root.queues</name>

  30. <value>default,dailyTask,hive</value>

  31. <description>

  32. The queues at the this level (root is the root queue).具有三个子队列

  33. </description>

  34. </property>

  35. <!-- default -->

  36. <property>

  37. <name>yarn.scheduler.capacity.root.default.capacity</name>

  38. <value>20</value>

  39. <description>Default queue target capacity.</description>

  40. </property>

  41. <property>

  42. <name>yarn.scheduler.capacity.root.default.user-limit-factor</name>

  43. <value>1</value>

  44. <description>

  45. Default queue user limit a percentage from 0.0 to 1.0.

  46. </description>

  47. </property>

  48. <property>

  49. <name>yarn.scheduler.capacity.root.default.maximum-capacity</name>

  50. <value>100</value>

  51. <description>

  52. The maximum capacity of the default queue.

  53. </description>

  54. </property>

  55. <property>

  56. <name>yarn.scheduler.capacity.root.default.state</name>

  57. <value>RUNNING</value>

  58. <description>

  59. The state of the default queue. State can be one of RUNNING or STOPPED.

  60. </description>

  61. </property>

  62. <property>

  63. <name>yarn.scheduler.capacity.root.default.acl_submit_applications</name>

  64. <value>*</value>

  65. <description>

  66. The ACL of who can submit jobs to the default queue.

  67. </description>

  68. </property>

  69. <property>

  70. <name>yarn.scheduler.capacity.root.default.acl_administer_queue</name>

  71. <value>*</value>

  72. <description>

  73. The ACL of who can administer jobs on the default queue.

  74. </description>

  75. </property>

  76. <!--dailyTask -->

  77. <property>

  78. <name>yarn.scheduler.capacity.root.dailyTask.capacity</name>

  79. <value>70</value>

  80. <description>Default queue target capacity.</description>

  81. </property>

  82. <property>

  83. <name>yarn.scheduler.capacity.root.dailyTask.user-limit-factor</name>

  84. <value>1</value>

  85. <description>

  86. Default queue user limit a percentage from 0.0 to 1.0.

  87. </description>

  88. </property>

  89. <property>

  90. <name>yarn.scheduler.capacity.root.dailyTask.maximum-capacity</name>

  91. <value>100</value>

  92. <description>

  93. The maximum capacity of the default queue..

  94. </description>

  95. </property>

  96. <property>

  97. <name>yarn.scheduler.capacity.root.dailyTask.state</name>

  98. <value>RUNNING</value>

  99. <description>

  100. The state of the default queue. State can be one of RUNNING or STOPPED.

  101. </description>

  102. </property>

  103. <property>

  104. <name>yarn.scheduler.capacity.root.dailyTask.acl_submit_applications</name>

  105. <value>hadoop</value>

  106. <description>

  107. The ACL of who can submit jobs to the default queue.

  108. </description>

  109. </property>

  110. <property>

  111. <name>yarn.scheduler.capacity.root.dailyTask.acl_administer_queue</name>

  112. <value>hadoop</value>

  113. <description>

  114. The ACL of who can administer jobs on the default queue.

  115. </description>

  116. </property>

  117. <!--hive -->

  118. <property>

  119. <name>yarn.scheduler.capacity.root.hive.capacity</name>

  120. <value>10</value>

  121. <description>Default queue target capacity.</description>

  122. </property>

  123. <property>

  124. <name>yarn.scheduler.capacity.root.hive.user-limit-factor</name>

  125. <value>1</value>

  126. <description>

  127. Default queue user limit a percentage from 0.0 to 1.0.

  128. </description>

  129. </property>

  130. <property>

  131. <name>yarn.scheduler.capacity.root.hive.maximum-capacity</name>

  132. <value>100</value>

  133. <description>

  134. The maximum capacity of the default queue..

  135. </description>

  136. </property>

  137. <property>

  138. <name>yarn.scheduler.capacity.root.hive.state</name>

  139. <value>RUNNING</value>

  140. <description>

  141. The state of the default queue. State can be one of RUNNING or STOPPED.

  142. </description>

  143. </property>

  144. <property>

  145. <name>yarn.scheduler.capacity.root.hive.acl_submit_applications</name>

  146. <value>*</value>

  147. <description>

  148. The ACL of who can submit jobs to the default queue.

  149. </description>

  150. </property>

  151. <property>

  152. <name>yarn.scheduler.capacity.root.hive.acl_administer_queue</name>

  153. <value>*</value>

  154. <description>

  155. The ACL of who can administer jobs on the default queue.

  156. </description>

  157. </property>

  158. <property>

  159. <name>yarn.scheduler.capacity.node-locality-delay</name>

  160. <value>40</value>

  161. <description>

  162. Number of missed scheduling opportunities after which the CapacityScheduler

  163. attempts to schedule rack-local containers.

  164. Typically this should be set to number of nodes in the cluster, By default is setting

  165. approximately number of nodes in one rack which is 40.

  166. </description>

  167. </property>

  168. <property>

  169. <name>yarn.scheduler.capacity.queue-mappings</name>

  170. <value></value>

  171. <description>

  172. A list of mappings that will be used to assign jobs to queues

  173. The syntax for this list is [u|g]:[name]:[queue_name][,next mapping]*

  174. Typically this list will be used to map users to queues,

  175. for example, u:%user:%user maps all users to queues with the same name

  176. as the user. 进行过映射后,user只能访问对应的quue_name,后续的queue.name设置都没用了。

  177. </description>

  178. </property>

  179. <property>

  180. <name>yarn.scheduler.capacity.queue-mappings-override.enable</name>

  181. <value>false</value>

  182. <description>

  183. If a queue mapping is present, will it override the value specified

  184. by the user? This can be used by administrators to place jobs in queues

  185. that are different than the one specified by the user.

  186. The default is false.

  187. </description>

  188. </property>

3. 如何使用该队列

 
  1. mapreduce:在Job的代码中,设置Job属于的队列,例如hive:

  2. conf.setQueueName("hive");

  3. hive:在执行hive任务时,设置hive属于的队列,例如dailyTask:

  4. set mapred.job.queue.name=dailyTask;

4. 刷新配置

生产环境中,队列及其容量的修改在现实中是不可避免的,而每次修改,需要重启集群,这个代价很高,如果修改队列及其容量的配置不重启呢: 1.在主节点上根据具体需求,修改好mapred-site.xml和capacity-scheduler.xml 2.把配置同步到所有节点上yarn rmadmin -refreshQueues 这样就可以动态修改集群的队列及其容量配置,不需要重启了,刷新mapreduce的web管理控制台可以看到结果。 注意:如果配置没有同步到所有的节点,一些队列会无法启用。 可以查看http://hadoop-master:8088/cluster/scheduler

 

 
  1. 队列容量=yarn.scheduler.capacity.<queue-path>.capacity/100

  2. 队列绝对容量=父队列的 队列绝对容量*队列容量

  3. 队列最大容量=yarn.scheduler.capacity.<queue-path>.maximum-capacity/100

  4. 队列绝对最大容量=父队列的 队列绝对最大容量*队列最大容量

  5. 绝对资源使用比=使用的资源/全局资源

  6. 资源使用比=使用的资源/(全局资源 * 队列绝对容量)

  7. 最小分配量=yarn.scheduler.minimum-allocation-mb

  8. 用户上限=MAX(yarn.scheduler.capacity.<queue-path>.minimum-user-limit-percent,1/队列用户数量)

  9. 用户调整因子=yarn.scheduler.capacity.<queue-path>.user-limit-factor

  10. 最大提交应用=yarn.scheduler.capacity.<queue-path>.maximum-applications

  11. 如果小于0 设置为(yarn.scheduler.capacity.maximum-applications*队列绝对容量)

  12. 单用户最大提交应用=最大提交应用*(用户上限/100)*用户调整因子

  13. AM资源占比(AM可占用队列资源最大的百分比)

  14. =yarn.scheduler.capacity.<queue-path>.maximum-am-resource-percent

  15. 如果为空,设置为yarn.scheduler.capacity.maximum-am-resource-percent

  16. 最大活跃应用数量=全局总资源/最小分配量*AM资源占比*队列绝对最大容量

  17. 单用户最大活跃应用数量=(全局总资源/最小分配量*AM资源占比*队列绝对容量)*用户上限*用户调整因子

  18. 本地延迟分配次数=yarn.scheduler.capacity.node-locality-delay<code>

5. 总结

本文介绍了如何配置yarn的容量调度器Capacity Scheduler配置。

转自:http://www.lamborryan/hadoop-capacity-scheduler/

本文标签: 容量系列HadoopCapacityscheduler