Spark资源管理

1、介绍

Spark资源管控分为spark集群自身可支配资源配置和job所用资源配置。

2、spark集群支配资源控制

在spark的conf/spark-env.sh文件中可以指定master和worker的支配资源数。

2.1 Spark集群可支配资源配置

  1. 每个worker使用内核数

    # 每个worker使用的内核数,默认是所有内核。
    export SPARK_WORKER_CORES=6
  2. 每个worker所用内存数

    # 每个worker使用的内存数,默认是1g内存
    export SPARK_WORKER_MEMORY=6g
  3. 每个节点可以启动worker实例的个数

    #是否可以在一个节点启动几个worker进程,默认1
    export SPARK_WORKER_INSTANCES=2
  4. spark守护进程本身占用的内存数

    spark守护进程指的是master和worker进程,该进程自身使用内存数也可以进行控制。

    #master和worker进程本身的内存数 ,默认1g
    export SPARK_DAEMON_MEMORY=200m

spark/conf/spark-env.sh配置全部内容如下:

#!/usr/bin/env bash

#
# 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.
# # This file is sourced when running various Spark programs.
# Copy it as spark-env.sh and edit that to configure Spark for your site. export JAVA_HOME=/soft/jdk
# Options read when launching programs locally with
# ./bin/run-example or ./bin/spark-submit
# - HADOOP_CONF_DIR, to point Spark towards Hadoop configuration files
# export HADOOP_CONF_DIR=/soft/hadoop/etc/hadoop
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public dns name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append # Options read by executors and drivers running inside the cluster
# - SPARK_LOCAL_IP, to set the IP address Spark binds to on this node
# - SPARK_PUBLIC_DNS, to set the public DNS name of the driver program
# - SPARK_CLASSPATH, default classpath entries to append
# - SPARK_LOCAL_DIRS, storage directories to use on this node for shuffle and RDD data
# - MESOS_NATIVE_JAVA_LIBRARY, to point to your libmesos.so if you use Mesos # Options read in YARN client mode
# - HADOOP_CONF_DIR, to point Spark towards Hadoop configuration files
# - SPARK_EXECUTOR_INSTANCES, Number of executors to start (Default: 2)
# - SPARK_EXECUTOR_CORES, Number of cores for the executors (Default: 1).
# - SPARK_EXECUTOR_MEMORY, Memory per Executor (e.g. 1000M, 2G) (Default: 1G)
# - SPARK_DRIVER_MEMORY, Memory for Driver (e.g. 1000M, 2G) (Default: 1G) # Options for the daemons used in the standalone deploy mode
# - SPARK_MASTER_HOST, to bind the master to a different IP address or hostname # - SPARK_MASTER_PORT / SPARK_MASTER_WEBUI_PORT, to use non-default ports for the master
#export SPARK_MASTER_PORT=7077
#export SPARK_MASTER_WEBUI_PORT=8080 # - SPARK_MASTER_OPTS, to set config properties only for the master (e.g. "-Dx=y") # - SPARK_WORKER_CORES, to set the number of cores to use on this machine
export SPARK_WORKER_CORES=6 # - SPARK_WORKER_MEMORY, to set how much total memory workers have to give executors (e.g. 1000m, 2g)
export SPARK_WORKER_MEMORY=6g # - SPARK_WORKER_PORT / SPARK_WORKER_WEBUI_PORT, to use non-default ports for the worker # - SPARK_WORKER_INSTANCES, to set the number of worker processes per node
export SPARK_WORKER_INSTANCES=1 # - SPARK_WORKER_DIR, to set the working directory of worker processes
# - SPARK_WORKER_OPTS, to set config properties only for the worker (e.g. "-Dx=y") # - SPARK_DAEMON_MEMORY, to allocate to the master, worker and history server themselves (default: 1g).
export SPARK_DAEMON_MEMORY=200m # - SPARK_HISTORY_OPTS, to set config properties only for the history server (e.g. "-Dx=y")
# - SPARK_SHUFFLE_OPTS, to set config properties only for the external shuffle service (e.g. "-Dx=y")
# - SPARK_DAEMON_JAVA_OPTS, to set config properties for all daemons (e.g. "-Dx=y")
# export SPARK_DAEMON_JAVA_OPTS="-Dspark.deploy.recoveryMode=ZOOKEEPER -Dspark.deploy.zookeeper.url=s102:2181,s103:2181,s104:2181 -Dspark.deploy.zookeeper.dir=/spark"
# - SPARK_PUBLIC_DNS, to set the public dns name of the master or workers # Generic options for the daemons used in the standalone deploy mode
# - SPARK_CONF_DIR Alternate conf dir. (Default: ${SPARK_HOME}/conf)
# - SPARK_LOG_DIR Where log files are stored. (Default: ${SPARK_HOME}/logs)
# - SPARK_PID_DIR Where the pid file is stored. (Default: /tmp)
# - SPARK_IDENT_STRING A string representing this instance of spark. (Default: $USER)
# - SPARK_NICENESS The scheduling priority for daemons. (Default: 0)
# - SPARK_NO_DAEMONIZE Run the proposed command in the foreground. It will not output a PID file.

2.2 job资源分配设置

spark-submit命令提交job时,可以为job指定使用的资源,包括内存和内核数。但在不同的spark集群模式下,使用的配置命令是不同的。命令使用如下:

$>spark-submit --master spark://s101:7077 --executor-memory 200m --executor-cores 4
  1. 设置driver内存数

    $>spark-submit --driver-cores 2		#默认是1
  2. standalone和mesos模式下

    • 执行器内核总数设置

      $>spark-submit --total-executor-cores 32
  3. standalone和yarn模式

    • 每个执行器内核数设置

      # yarn下模式为1,standalone模式下为worker上可有的所有内核数
      $>spark-submit --executor-cores 4
  4. yarn-only

    只在yarn模式下,使用的资源控制选线:

    • driver内核数设置

      driver使用的cpu内核数,只在cluster模式下有效,默认1。

      $>spark-submit --driver-cores 3
    • 执行器个数设置

      启动的执行器个数,默认为2。

      $>spark-submit --num-executors 3

3、资源控制细则

spark资源控制在集群配置时不进行物理资源检查,即可以配置任意的资源值。比如物理内核是16,但是配置成每个worker占用32核。如图所示:

图中箭头指向的部分是worker进程能够支配使用的资源,包括内存和内核数。

Spark job执行时,指定的资源同时受到内存和内核两方面的限制,即任何一个条件不满足,都无法启动executor进程。例如指定每个executor使用3个core,worker可以支配8个core,但是最终该worker只能启动两个executor。

Spark资源管理的更多相关文章

  1. spark on yarn模式下内存资源管理(笔记1)

    问题:1. spark中yarn集群资源管理器,container资源容器与集群各节点node,spark应用(application),spark作业(job),阶段(stage),任务(task) ...

  2. 【转】Spark源码分析之-deploy模块

    原文地址:http://jerryshao.me/architecture/2013/04/30/Spark%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90%E4%B9%8B- ...

  3. Spark调优指南

    Spark相关问题 Spark比MR快的原因? 1) Spark的计算结果可以放入内存,支持基于内存的迭代,MR不支持. 2) Spark有DAG有向无环图,可以实现pipeline的计算模式. 3) ...

  4. spark延迟调度与动态资源管理

    Spark中的延迟调度 Spark的Task的调度过程有五个本地性级别:PROCESS_NODE.NODE_LOCAL.NO_PREF.RACK_LOCAL.ANY.在理想的状态下,我们肯定是想所有的 ...

  5. spark on yarn模式下内存资源管理(笔记2)

    1.spark 2.2内存占用计算公式 https://blog.csdn.net/lingbo229/article/details/80914283 2.spark on yarn内存分配** 本 ...

  6. Hive on Spark安装配置详解(都是坑啊)

    个人主页:http://www.linbingdong.com 简书地址:http://www.jianshu.com/p/a7f75b868568 简介 本文主要记录如何安装配置Hive on Sp ...

  7. (一)Spark简介-Java&Python版Spark

    Spark简介 视频教程: 1.优酷 2.YouTube 简介: Spark是加州大学伯克利分校AMP实验室,开发的通用内存并行计算框架.Spark在2013年6月进入Apache成为孵化项目,8个月 ...

  8. Spark 运行架构核心总结

    摘要: 1.基本术语 2.运行架构 2.1基本架构 2.2运行流程  2.3相关的UML类图  2.4调度模块: 2.4.1作业调度简介 2.4.2任务调度简介 3.运行模式 3.1 standalo ...

  9. Spark运行模式与Standalone模式部署

    上节中简单的介绍了Spark的一些概念还有Spark生态圈的一些情况,这里主要是介绍Spark运行模式与Spark Standalone模式的部署: Spark运行模式 在Spark中存在着多种运行模 ...

随机推荐

  1. JS模式和原型精解

    首先需要知道的是 模式只是思想.不要用 结构 看模式. ES中函数是对象,因此函数也有属性和方法. 每个函数含有两个属性: length 和 prototype 每个函数含有两个非继承的方法: app ...

  2. spoj COT - Count on a tree(主席树 +lca,树上第K大)

    您将获得一个包含N个节点的树.树节点的编号从1到Ñ.每个节点都有一个整数权重. 我们会要求您执行以下操作: uvk:询问从节点u到节点v的路径上的第k个最小权重 输入 在第一行中有两个整数Ñ和中号.( ...

  3. day_06 再谈编码

    1. 小数据池(常量池) 1.id() 通过id()查询一个变量在内存中的地址 2.is和== 1.is 判断左右两端内存地址是否一致,如果返回值是TRUE,则可以判断这两个变量值是同一对象 2.== ...

  4. python3 repr()函数笔记

    a=[1,2,3,4]print(repr(a))print(type(repr(a)))for i in repr(a): print(i)#repr函数是将对象转换成string类型

  5. node服务器端模块化-commomjs

    modele.js getmodule.js 用exports 返回的是一个对象中的每个属性

  6. 【ACM】阶乘因式分解(二)

    阶乘因式分解(二) 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 给定两个数n,m,其中m是一个素数. 将n(0<=n<=2^31)的阶乘分解质因数,求 ...

  7. 软件使用---Eclipse

    代码提示快捷操作.这个叫做,内容分析(content assist) 1.设置自动提示: 2.设置快捷键:

  8. Murano Weekly Meeting 2015.10.20

    Meeting time: 2015.October.20th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting sum ...

  9. .NET平台下使用C#连接各种数据库

    在.NET平台下,通常我们需要连接不同的数据库,这就需要我们配置连接字符串以及提供常用的class进行数据存取. 1.C#连接Access @"Provider=Microsoft.ACE. ...

  10. Ubuntu瞎胡搞

    ubutnu的几个必不可少的软件: 1.Guake,超级方便的终端 2.Unity tweak tool 3.VLC,本地视频播放器 4.MyPint,简单画图软件 5.GIMP,PS工具 Subli ...