我写了一个 sparkR 代码,想知道是否可以在 EMR 集群上使用 spark-submit 或 sparkR 提交它。

我尝试了几种方法,例如:
sparkR mySparkRScript.r 或 sparkR --no-save mySparkScript.r 等等。但每次我都遇到以下错误:

Error in sparkR.sparkContext(master, appName, sparkHome, sparkConfigMap,  :
JVM is not ready after 10 seconds

示例代码:
#Set the path for the R libraries you would like to use.
#You may need to modify this if you have custom R libraries.
.libPaths(c(.libPaths(), '/usr/lib/spark/R/lib'))

#Set the SPARK_HOME environment variable to the location on EMR
Sys.setenv(SPARK_HOME = '/usr/lib/spark')

#Load the SparkR library into R
library(SparkR, lib.loc = c(file.path(Sys.getenv("SPARK_HOME"), "R", "lib")))

#Initiate a Spark context and identify where the master node is located.
#local is used here because the RStudio server
#was installed on the master node

sc <- sparkR.session(master = "local[*]", sparkEnvir = list(spark.driver.memory="2g"))

sqlContext <- sparkRSQL.init(sc)

注意:我可以通过直接粘贴或使用 source("mySparkRScript.R") 在 sparkr-shell 中运行我的代码。

引用:
  • Crunching Statistics at Scale with SparkR on Amazon EMR
  • SparkR Spark documentation
  • R on Spark
  • Executing-existing-r-scripts-from-spark-rutger-de-graaf
  • Github
  • 最佳答案

    我能够通过 Rscript 运行它。您需要做一些事情,这可能是一个过程密集型的过程。如果你愿意试一试,我会推荐:

  • 弄清楚如何进行自动化 SparkR 或 sparklyR 构建。通过: https://github.com/UrbanInstitute/spark-social-science
  • 首先使用 AWS CLI 创建一个带有 EMR 模板和引导脚本的集群,您将通过以下步骤 1 创建。(确保将 EMR 模板和 rstudio_sparkr_emrlyr_blah_blah.sh sripts 放入 S3 存储桶)
  • 将您的 R 代码放入一个文件中,然后将其放入另一个 S3 存储桶中...您提供的示例代码可以正常工作,但我建议您实际进行一些操作,例如从 S3 读取数据,将值添加到
  • ,然后将其写回(只是为了在进入“繁重”代码之前确认它有效)
  • 创建另一个 .sh 文件,将 R 文件从您拥有的 S3 存储桶复制到集群,然后通过 Rscript 执行它。将此 shell 脚本与 R 代码文件放在同一个 S3 存储桶中(为简单起见)。此 shell 文件内容的示例可能如下所示:
    #!/bin/bash
    aws s3 cp s3://path/to/the/R/file/from/step3.R theNameOfTheFileToRun.R
    Rscript theNameOfTheFileToRun.R
    
  • 在 AWS CLI 中,在创建集群时,将 --step 插入到您的集群创建调用中,使用 Amazon 提供的 CUSTOM JAR RUNNER 运行复制和执行 R 代码的 shell 脚本
  • 确保在 R 代码结束时停止 Spark session 。

  • AWS CLI 命令的一个示例可能如下所示(在我的示例中,我在 Amazon 上使用 us-east-1 区域,并在集群中的每个工作程序上转换一个 100GB 磁盘......只需将您的区域放在您的任何位置请参阅“us-east-1”并选择您想要的任何大小的磁盘)
    aws emr create-cluster --name "MY COOL SPARKR OR SPARKLYR CLUSTER WITH AN RSCRIPT TO RUN SOME R CODE" --release-label emr-5.8.0 --applications Name=Spark Name=Ganglia Name=Hadoop --instance-groups InstanceGroupType=MASTER,InstanceCount=1,InstanceType=m4.xlarge 'InstanceGroupType=CORE,InstanceCount=2,InstanceType=m4.2xlarge,EbsConfiguration={EbsOptimized=true,EbsBlockDeviceConfigs=[{VolumeSpecification={VolumeType=gp2,SizeInGB=100}},{VolumeSpecification={VolumeType=io1,SizeInGB=100,Iops=100},VolumesPerInstance=1}]}' --log-uri s3://path/to/EMR/sparkr_logs --bootstrap-action Path=s3://path/to/EMR/sparkr_bootstrap/rstudio_sparkr_emr5lyr-proc.sh,Args=['--user','cool_dude','--user-pw','top_secret','--shiny','true','--sparkr','true','sparklyr','true'] --ec2-attributes KeyName=mykeyfilename,InstanceProfile=EMR_EC2_DefaultRole,AdditionalMasterSecurityGroups="sg-abc123",SubnetId="subnet-abc123" --service-role EMR_DefaultRole --scale-down-behavior TERMINATE_AT_TASK_COMPLETION --auto-terminate --region us-east-1 --steps Type=CUSTOM_JAR,Name=CustomJAR,ActionOnFailure=CONTINUE,Jar=s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar,Args=["s3://path/to/the/shell/file/from/step4.sh"]
    

    祝你好运!干杯,内特

    关于r - 如何在 EMR 集群上使用 spark-submit 或 sparkR 运行 SparkR 脚本?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47198617/

    10-12 13:58