Spark SQL ThriftServer

Spark SQL ThriftServer

啓動命令

默認情況下,Spark 日誌目錄 SPARK_LOG_DIR 指向 SPARK_HOME/logs,如因權限訪問控制,可以通過顯示設置環境變量 SPARK_LOG_DIR,將日誌目錄指向其它路徑,如:

export SPARK_LOG_DIR=/tmp/spark_client_logs

啓動

/data0/spark/spark-2.2.1-bin/sbin/start-thriftserver.sh \
--name spark_sql_thriftserver \
--master yarn \
--deploy-mode client \
--driver-cores 3 \
--driver-memory 3g \
--executor-cores 8 \
--executor-memory 20g \
--num-executors 30 \
--hiveconf hive.server2.thrift.port=10000

其中,deploy-mode 用於指定部署模式,ThriftServer僅支持 clienthive.server2.thrift.port 用於指定實例端口。

終止命令

/data0/spark/spark-2.2.1-bin/sbin/stop-thriftserver.sh

Beeline

beeline> !connect jdbc:hive2://{HOSTNAME}:{PORT}
Connecting to jdbc:hive2://{HOSTNAME}:{PORT}
Enter username for jdbc:hive2://{HOSTNAME}:{PORT}:{USERNAME}
Enter password for jdbc:hive2://{HOSTNAME}:{PORT}:{PORT}

其中,{HOSTNAME} 爲ThriftServer實例域名或IP地址, {PORT} 爲ThriftServer實例端口,{USERNAME} 爲用戶名,{PASSWORD} 爲密碼。

公平調度

默認情況下,Spark應用內部的多個 Job 使用 FIFO 模式進行調度,可能導致多租戶場景下計算時延較高,可以啓用 FAIR 調度模式(公平調度),使多個 JobTasks 之間使用 round bobin(輪詢)的方式分配資源。

使用公平調度模式需要經過以下2步:

  1. 開啓公平調度器;
--conf spark.scheduler.mode=FAIR
  1. 配置若干個資源池(Pool),以及每個資源池的調度模式(schedulingMode,FIFO或FAIR)、權重(weight)和最小資源量(minShare);

資源池需要使用單獨的文件進行配置:

/usr/home/weibo_rd_dip/fairscheduler.xml
<allocations>
  <pool name="default">
    <schedulingMode>FAIR</schedulingMode>
    <weight>1</weight>
    <minShare>10</minShare>
  </pool>
  <pool name="pro">
    <schedulingMode>FIFO</schedulingMode>
    <weight>10</weight>
    <minShare>10</minShare>
  </pool>
</allocations>

fairscheduler.xml 配置兩個資源池:default和pro。其中,

default

調度模式:FAIR,公平調度;
權重:1;
最小資源量:10,CPU 10 Cores;

pro

調度模式:FIFO,先進先出,排隊;
權重:2,相較於default,可以使用2倍的資源;
最小資源量:10,CPU 10 Cores;

 
注意,公平調度器可以有多個資源池,且每個資源池使用不同的調度模式。

使用Beeline時,應用默認提交至default,可以使用如下命令切換資源池:

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

啓動命令示例:

export SPARK_LOG_DIR=/tmp/spark_client_logs

/data0/spark/spark-2.2.1-bin/sbin/start-thriftserver.sh \
--name spark_sql_thriftserver \
--master yarn \
--deploy-mode client \
--driver-cores 180 \
--driver-memory 3g \
--executor-cores 8 \
--executor-memory 30g \
--num-executors 30 \
--hiveconf hive.server2.thrift.port=10000 \
--conf spark.scheduler.mode=FAIR \
--conf spark.scheduler.allocation.file=/usr/home/weibo_rd_dip/fairscheduler.xml
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章