我想修改 Amazon EMR Studio Workspace 中的 Spark 配置。
简短描述
要为 Amazon Elastic Compute Cloud (Amazon EC2) 或 EMR Serverless 远程集群自定义 Spark 配置,请使用 Sparkmagic 命令来更改 executorMemory、executorCores 和资源分配。
对于 Amazon Elastic Kubernetes Service (Amazon EKS) 远程集群,请在 SparkContext 对象中设置 Spark 配置。Amazon EKS 不支持 Sparkmagic 命令。有关详细信息,请参阅注意事项和限制。
解决方法
为 Amazon EC2 或 EMR Serverless 远程集群自定义 Spark 配置
完成以下步骤:
-
要修改作业配置,请在 Workspace 单元中运行 %%configure 命令。
示例:
%%configure -f
{"executorMemory":"4G"}
注意: 在上述示例中,已修改 Spark 作业的 executorMemory。
-
对于通过 -conf 选项传递的其他配置,请使用嵌套的 JSON 对象。
注意: 要将对象传递给 SparkContext 或 Sparksession,请使用 -conf 而非 conf。有关更多信息,请参阅 Apache Livy 网站上的 Spark configuration(Spark 配置)。
-
示例:
%%configure -f
{
"driverMemory": "4G",
"driverCores": 4,
"executorMemory" : "8G",
"executorCores": 2,
"conf": {
"spark.dynamicAllocation.maxExecutors" : 10,
"spark.dynamicAllocation.minExecutors": 1
}
}
要在连接到 Amazon EKS 集群的 Workspace 中自定义 Spark 配置,请在 SparkContext 对象中设置 Spark 配置:
spark.conf.set("spark.executor.memory", "8g")
确认 Spark 配置
执行以下操作:
-
对于 Amazon EC2 和 EMR Serverless,请在客户端 Workspace 上运行 %%info 命令:
输出示例:
Current session configs: {'driverMemory': '4G', 'driverCores': 4, 'executorMemory': '8G', 'executorCores': 2, 'conf': {'spark.dynamicAllocation.maxExecutors': 10, 'spark.dynamicAllocation.minExecutors': 1}, 'proxyUser': 'assumed-role_Admin_biditdas-Isengard', 'kind': 'pyspark'}
-
对于 Amazon EC2,请查看集群主节点中位于 /var/log/livy/livy-livy-server.out 的日志。如果 Spark 会话已启动,则您会看到类似于以下的日志条目:
20/06/24 10:11:22 INFO InteractiveSession$: Creating Interactive session 2: [owner: null, request: [kind: pyspark, proxyUser: None, executorMemory: 4G, conf: spark.dynamicAllocation.enabled -> false, heartbeatTimeoutInSecond: 0]]
-
对于 Amazon EKS,请使用 Spark UI。
相关信息
Enhanced kernels with magic commands(使用 magic 命令增强内核)
Apache Livy 网站上的 REST API
GitHub 网站上的 Features available with the new kernels(新内核所提供的功能)