zoukankan      html  css  js  c++  java
  • spark-调度策略之FAIR

    1、概述

    spark有两种调度模式:FIFO、FAIR。FIFO是先进先出,有很强的顺序性,只有前一个处理完成后才会去处理后进来的。FAIR是公平调度,通过配置进行控制优先执行的任务。spark默认使用FIFO模式,如果应用场景里面有很多比较大的查询、也有很多小的查询,此时建议使用FAIR模式可以先执行小的查询在执行耗时比较旧的查询。

    2、配置

    默认安装spark后再conf目录下有一个fairscheduler.xml.template文件,把此文件复制一份:

    #cp fairscheduler.xml.template    fairscheduler.xml

    #cat fairscheduler.xml

    <?xml version="1.0"?>

    <!--
       Licensed to the Apache Software Foundation (ASF) under one or more
       contributor license agreements.  See the NOTICE file distributed with
       this work for additional information regarding copyright ownership.
       The ASF licenses this file to You under the Apache License, Version 2.0
       (the "License"); you may not use this file except in compliance with
       the License.  You may obtain a copy of the License at

           http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing, software
       distributed under the License is distributed on an "AS IS" BASIS,
       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       See the License for the specific language governing permissions and
       limitations under the License.
    -->

    <allocations>
      <pool name="default">
        <schedulingMode>FAIR</schedulingMode>
        <weight>5</weight>
        <minShare>22</minShare>
      </pool>
    </allocations>

    参数解释:

    pool  name:调度池的名称

    schedulingMode:调度模式,有两种FIFO、FAIR

    weight:配置某个线程池的资源权重,默认为1,这里配置5,代表default池会获得5倍的资源

    minShare:给每个调度池指定一个最小的shares(cpu的核数),公平调度器通过权重重新分配资源之前总是试图满足所有活动调度池的最小share,默认为0

    修改完fairscheduler.xml文件,还需要配置spark-default.conf,添加如下内容:

    #cat spark-default.conf

    spark.scheduler.mode  FAIR
    spark.scheduler.allocation.file /data/spark-2.2.0-bin-hadoop2.7/conf/fairscheduler.xml

    3、使配置生效

    #./stop-all.sh

    #./start-all.sh

    4、集群多任务使用

    可以在fairscheduler.xml文件中添加多个调度池,配置不同的weight、minShare来控制,使用调度池要显示指定:

    SET spark.sql.thriftserver.scheduler.pool=default;

  • 相关阅读:
    T3java核心API基础类
    java字符编码
    Servlet 1
    T2java面向对象
    T1java语言基础
    Mac OS mysql数据库安装与初始化
    java多线程中注入Spring对象问题
    T4java核心API集合类
    The first day Teddy
    Spring第二节 注入依赖
  • 原文地址:https://www.cnblogs.com/cuishuai/p/7910348.html
Copyright © 2011-2022 走看看