AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 776687
Accepted
mxmlnkn
mxmlnkn
Asked: 2016-05-14 13:46:27 +0800 CST2016-05-14 13:46:27 +0800 CST 2016-05-14 13:46:27 +0800 CST

如何使用 Slurm 在集群上运行 Spark?

  • 772

我编写了一个example.jar使用火花上下文的程序。如何在使用 Slurm 的集群上运行它?这与https://stackoverflow.com/questions/29308202/running-spark-on-top-of-slurm有关,但答案不是很详细,也不是关于 serverfault。

apache-spark
  • 2 2 个回答
  • 5253 Views

2 个回答

  • Voted
  1. Best Answer
    mxmlnkn
    2016-05-14T13:46:27+08:002016-05-14T13:46:27+08:00

    为了使用 spark 上下文运行应用程序,首先需要运行一个 Slurm 作业,该作业启动一个 master 和一些 worker。使用 Slurm 时需要注意一些事项:

    • 不要将 Spark 作为守护进程启动
    • 使 Spark 工作人员仅使用 Slurm 作业所需的内核和内存
    • 为了在同一个工作中运行 master 和 worker,你必须在脚本中的某个地方分支

    我正在使用安装到$HOME/spark-1.5.2-bin-hadoop2.6/. 请记住用脚本中的一些有效值替换<username>和。<shared folder>

    #!/bin/bash
    #start_spark_slurm.sh
    
    #SBATCH --nodes=3
    #  ntasks per node MUST be one, because multiple slaves per work doesn't
    #  work well with slurm + spark in this script (they would need increasing 
    #  ports among other things)
    #SBATCH --ntasks-per-node=1
    #SBATCH --cpus-per-task=4
    #SBATCH --mem-per-cpu=500
    #  Beware! $HOME will not be expanded and invalid paths will result Slurm jobs
    #  hanging indefinitely with status CG (completing) when calling scancel!
    #SBATCH --output="/home/<username>/spark/logs/%j.out"
    #SBATCH --error="/home/<username>/spark/logs/%j.err"
    #SBATCH --time=01:00:00
    
    # This section will be run when started by sbatch
    if [ "$1" != 'srunning' ]; then
        this=$0
        # I experienced problems with some nodes not finding the script:
        #   slurmstepd: execve(): /var/spool/slurm/job123/slurm_script:
        #   No such file or directory
        # that's why this script is being copied to a shared location to which 
        # all nodes have access to:
        script=/<shared folder>/${SLURM_JOBID}_$( basename -- "$0" )
        cp "$this" "$script"
    
        # This might not be necessary on all clusters
        module load scala/2.10.4 java/jdk1.7.0_25 cuda/7.0.28
    
        export sparkLogs=$HOME/spark/logs
        export sparkTmp=$HOME/spark/tmp
        mkdir -p -- "$sparkLogs" "$sparkTmp"
    
        export SPARK_ROOT=$HOME/spark-1.5.2-bin-hadoop2.6/
        export SPARK_WORKER_DIR=$sparkLogs
        export SPARK_LOCAL_DIRS=$sparkLogs
        export SPARK_MASTER_PORT=7077
        export SPARK_MASTER_WEBUI_PORT=8080
        export SPARK_WORKER_CORES=$SLURM_CPUS_PER_TASK
        export SPARK_DAEMON_MEMORY=$(( $SLURM_MEM_PER_CPU * $SLURM_CPUS_PER_TASK / 2 ))m
        export SPARK_MEM=$SPARK_DAEMON_MEMORY
    
        srun "$script" 'srunning'
    # If run by srun, then decide by $SLURM_PROCID whether we are master or worker
    else
        source "$SPARK_ROOT/sbin/spark-config.sh"
        source "$SPARK_PREFIX/bin/load-spark-env.sh"
        if [ "$SLURM_PROCID" -eq 0 ]; then
            export SPARK_MASTER_IP=$( hostname )
            MASTER_NODE=$( scontrol show hostname $SLURM_NODELIST | head -n 1 )
    
            # The saved IP address + port is necessary alter for submitting jobs
            echo "spark://$SPARK_MASTER_IP:$SPARK_MASTER_PORT" > "$sparkLogs/${SLURM_JOBID}_spark_master"
    
            "$SPARK_ROOT/bin/spark-class" org.apache.spark.deploy.master.Master \
                --ip "$SPARK_MASTER_IP"                                         \
                --port "$SPARK_MASTER_PORT "                                    \
                --webui-port "$SPARK_MASTER_WEBUI_PORT"
        else
            # $(scontrol show hostname) is used to convert e.g. host20[39-40]
            # to host2039 this step assumes that SLURM_PROCID=0 corresponds to 
            # the first node in SLURM_NODELIST !
            MASTER_NODE=spark://$( scontrol show hostname $SLURM_NODELIST | head -n 1 ):7077
            "$SPARK_ROOT/bin/spark-class" org.apache.spark.deploy.worker.Worker $MASTER_NODE
        fi
    fi
    

    现在开始 sbatch 作业,然后example.jar:

    mkdir -p -- "$HOME/spark/logs"
    jobid=$( sbatch ./start_spark_slurm.sh )
    jobid=${jobid##Submitted batch job }
    MASTER_WEB_UI=''
    while [ -z "$MASTER_WEB_UI" ]; do 
        sleep 1s
        if [ -f "$HOME/spark/logs/$jobid.err" ]; then
            MASTER_WEB_UI=$( sed -n -r 's|.*Started MasterWebUI at (http://[0-9.:]*)|\1|p' "$HOME/spark/logs/$jobid.err" )
        fi
    done
    MASTER_ADDRESS=$( cat -- "$HOME/spark/logs/${jobid}_spark_master" ) 
    "$HOME/spark-1.5.2-bin-hadoop2.6/bin/spark-submit" --master "$MASTER_ADDRESS" example.jar
    firefox "$MASTER_WEB_UI"
    
    • 9
  2. Albert Chu
    2016-06-28T14:19:28+08:002016-06-28T14:19:28+08:00

    正如maxmlnkn 回答所述,您需要一种机制来在 Slurm 分配中设置/启动适当的 Spark 守护程序,然后才能通过 spark-submit 执行 Spark jar。

    已经开发了几个为您进行此设置的脚本/系统。您在上面链接的答案提到了 Magpie @ https://github.com/LLNL/magpie(完全披露:我是这些脚本的开发者/维护者)。Magpie 提供了一个作业提交文件 (submission-scripts/script-sbatch-srun/magpie.sbatch-srun-spark) 供您编辑并放入您的集群细节和作业脚本以执行。配置完成后,您将通过 'sbatch -k ./magpie.sbatch-srun-spark' 提交此文件)。有关更多详细信息,请参阅 doc/README.spark。

    我会提到还有其他脚本/系统可以为您执行此操作。我缺乏与他们的经验,所以除了在下面链接它们之外无法发表评论。

    https://github.com/glennklockwood/myhadoop

    https://github.com/hpcugent/hanythingondemand

    • 2

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve