Get Hands-on with Amazon EKS - Workshop Event Series
Whether you're taking your first steps with Kubernetes or you're an experienced practitioner looking to sharpen your skills, our Amazon EKS workshop series delivers practical, real-world experience that moves you forward. Learn directly from AWS solutions architects and EKS specialists through hands-on sessions designed to build your confidence with Kubernetes. Register now and start building with Amazon EKS!
如何在 Amazon EMR 中设置 Spark 参数?
我想在 Amazon EMR 中配置 Apache Spark 参数。
简短描述
要配置 Spark 应用程序,请使用命令行参数,例如 spark-submit。或者配置 spark-defaults.conf 文件中的值以使更改永久生效。
解决方法
使用 spark-submit 配置 Spark 参数
要通过 Spark Shell 和 spark-submit 命令动态加载配置,请使用以下选项之一:
- 命令行选项,例如 --num-executors。
- --conf 标志。
**注意:**要查看完整的选项列表,请运行 spark-submit--help。
spark-submit 命令从 spark-defaults.conf 读取配置选项。
在 spark-defaults.conf 文件中,每行都包含一个键和一个由空格分隔的值。
有关详细信息,请参阅使用 Submitting user applications with spark-submit(通过 spark-submit 提交用户应用程序)。有关 Spark 支持的参数的详细信息,请参阅 Apache Spark 网站上的 Spark configuration(Spark 配置)。
配置选项示例:
--class \ --master \ --deploy-mode \ --conf = \ --num-executors \ --executor-memory G \ --driver-memory G \ --executor-cores \ --driver-cores \ --jars \ --packages \ --py-files < Comma-separated list of .zip, .egg, or .py files to place on the PYTHONPATH for Python apps> \
spark-submit 命令会自动将应用程序 JAR 以及 --jars 选项中包含的任何 JAR 传输到集群。必须用逗号分隔 --jars 之后提供的 URL。spark-submit 将列表包含在驱动程序和执行程序类路径中,并将 JAR 和文件复制到执行程序节点上每个 SparkContext 的工作目录中。
**注意:**目录扩展不适用于 --jars。
spark-submit 命令示例:
spark-submit \ --deploy-mode cluster \ --class org.apache.spark.examples.SparkPi \ --conf spark.dynamicAllocation.enabled=false \ --master yarn \ --num-executors 4 \ --driver-memory 4G \ --executor-memory 4G \ --executor-cores 1 \ /usr/lib/spark/examples/jars/spark-examples.jar \ 10
要传递内存参数,请使用标志 --conf:
spark-submit \ --deploy-mode cluster \ --class org.apache.spark.examples.SparkPi \ --conf spark.dynamicAllocation.enabled=false \ --master yarn \ --conf spark.driver.memory=1G \ --conf spark.executor.memory=1G \ /usr/lib/spark/examples/jars/spark-examples.jar \ 10
使用自定义 Spark 参数启动 spark-shell 和 pyspark Shell
要启动 spark-shell 或 pyspark Shell,请运行以下命令:
spark-shell
spark-shell \ --conf spark.driver.maxResultSize=1G \ --conf spark.driver.memory=1G \ --deploy-mode client \ --conf spark.executor.memory=1G \ --conf spark.executor.heartbeatInterval=10000000s \ --conf spark.network.timeout=10000001s \ --executor-cores 1 \ --num-executors 5 \ --packages org.apache.spark:spark-avro_2.12:3.1.2 \ --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer'
pyspark Shell
pyspark \ --conf spark.driver.maxResultSize=1G \ --conf spark.driver.memory=1G \ --deploy-mode client \ --conf spark.executor.memory=1G \ --conf spark.executor.heartbeatInterval=10000000s \ --conf spark.network.timeout=10000001s \ --executor-cores 1 \ --num-executors 5 \ --packages org.apache.spark:spark-avro_2.12:3.1.2 \ --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer'
使用 spark-defaults.conf 配置 Spark 参数
要使配置更改永久生效,请将配置附加到 /etc/spark/conf/spark-defaults.conf 文件中。然后,重新启动 Spark History Server。以下示例在 spark-defaults.conf 中配置执行程序内存和驱动程序内存。在此示例中,每一行由一个键和一个由空格分隔的值组成。
示例
spark.executor.memory 9486M spark.driver.memory 9486M
以下示例配置在集群启动期间配置 Spark 驱动程序和执行程序内存:
[ { "Classification": "spark-defaults", "Properties": { "spark.executor.memory": "9486M", "spark.driver.memory": "9486M" } } ]
**注意:**在 Amazon EMR 上,spark.yarn.executor.memoryOverhead 配置的默认值为 18.75%,但标准 Spark 的默认值为 0.1875%。配置 Spark 作业后,监控其性能并分析资源利用率,以收集详情并进一步调整作业参数。
相关信息
AWS open data analytics(AWS 开放数据分析)
Modify your cluster on the fly with Amazon EMR reconfiguration(使用 Amazon EMR 重新配置即时修改您的集群)
- 语言
- 中文 (简体)
