spark-shell运行spark任务参数设置

 

2016年09月23日 11:02:02 zrc199021 阅读数:12548

之前初学spark用spark-shell执行小程序的时候, 每次执行action操作(比如count,collect或者println),都会报错:

WARN TaskSchedulerImpl: Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources

同时如果去spark ui上(公司默认为ip:18080)会看到spark-shell为核数core为0: 
这里写图片描述

原因是启动spark-shell的时候没有给他分配资源, 所以我们应该在启动spark-shell的时候这么写:

/home/mr/spark/bin/spark-shell --executor-memory 4G \
                               --total-executor-cores 10 \ 
                               --executor-cores 1
  • 1
  • 2
  • 3

其中 :

--executor-memory 是指定每个executor(执行器)占用的内存 
--total-executor-cores是所有executor总共使用的cpu核数 
--executor-cores是每个executor使用的cpu核数 
对于spark-shell还可以在yarn上执行: 
--master yarn-client 
这里必须是client,不同于spark-submit的yarn-cluster, 因为spark-shell作为一个与用户交互的命令行,必须将Driver运行在本地,而不是yarn上, 其他的参数与submit一样.

以上参数就限制了总cpu核数为10, executor数目为10


但是, 每次执行都要写这么多参数显然很麻烦, 我们也可以通过修改spark-shell的方法将以上参数改成默认, 方法如下: 
spark-shell之前代码:

... ...
function main() {
...
else
    export SPARK_SUBMIT_OPTS
    "$FWDIR"/bin/spark-submit --class org.apache.spark.repl.Main "$@"
  fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

修改为:

... ...
function main() {
...
else
    export SPARK_SUBMIT_OPTS
    # CUN
    RESOURCE_OPTIONS="--executor-memory 1G --total-executor-cores 10 --executor-cores 1 "
    CMD_OPTIONS=$RESOURCE_OPTIONS$@
    echo "CMD_OPTIONS: " $CMD_OPTIONS
    "$FWDIR"/bin/spark-submit --class org.apache.spark.repl.Main --name "Spark shell" $CMD_OPTIONS
  fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

之后, 直接运行spark-shell即可

参考: http://www.2cto.com/kf/201511/450843.html

猜你喜欢

转载自blog.csdn.net/wangshuminjava/article/details/85264376
今日推荐