如何解决火花上纱线容器尺寸问题?

sim*_*ple 12 hadoop-yarn apache-spark pyspark

我想开展一些pyspark工作YARN.我有2个节点,每个节点10 GB.我可以像这样打开pyspark shell: pyspark

现在,当我有一个非常简单的例子,我试图启动:

import random
NUM_SAMPLES=1000
def inside(p):
    x, y = random.random(), random.random()
    return x*x + y*y < 1

count = sc.parallelize(xrange(0, NUM_SAMPLES)) \
             .filter(inside).count()
print "Pi is roughly %f" % (4.0 * count / NUM_SAMPLES)
Run Code Online (Sandbox Code Playgroud)

因此,我得到一个带有错误输出的非常长的火花日志.最重要的信息是:

ERROR cluster.YarnScheduler: Lost executor 1 on (ip>: Container marked as failed: <containerID> on host: <ip>. Exit status 1.  Diagnostics: Exception from container-launch.  ......
Run Code Online (Sandbox Code Playgroud)

后来我在日志中看到......

ERROR scheduler.TaskSetManager: Task 0 in stage 0.0 failed 1 times: aborting job
INFO cluster.YarnClientSchedulerBackend: Asked to remove non-existent executor 1
INFO spark.ExecutorAllocationManager: Existing executor 1 has been removed (new total is 0)
Run Code Online (Sandbox Code Playgroud)

从我从上面的日志中收集的内容来看,这似乎是纱线中的容器尺寸问题.

我的yarn-site.xml文件有以下设置:

yarn.scheduler.maximum-allocation-mb = 10240
yarn.nodemanager.resource.memory-mb = 10240
Run Code Online (Sandbox Code Playgroud)

spark-defaults.conf包含:

spark.yarn.executor.memoryOverhead=2048
spark.driver.memory=3g
Run Code Online (Sandbox Code Playgroud)

如果您还有其他想要了解的设置,请告诉我们.

如何正确设置纱线容器尺寸?
(对于可以帮助我的人的路上的赏金)

cod*_*ode 16

我先解释一下在YARN集群上调整spark应用程序所需的基本属性集.

注意: YARN中的Container等同于Spark中的Executor.为了便于理解,您可以认为两者都是相同的.

在yarn-site.xml上:

yarn.nodemanager.resource.memory-mb 是来自给定节点的群集可用的总内存.

yarn.nodemanager.resource.cpu-vcores 是来自给定节点的群集可用的CPU vcore的总数.

yarn.scheduler.maximum-allocation-mb 是每个纱线容器分配的最大内存mb.

yarn.scheduler.maximum-allocation-vcores 是每个纱线容器可以分配的最大vcores数.

示例:如果节点具有16GB和8vcores,并且您希望向群集(对于容器)贡献14GB和6vcores,则设置属性,如下所示:

yarn.nodemanager.resource.memory-mb:14336(14GB)

yarn.nodemanager.resource.cpu-vcores:6

并且,要创建每个容量为2GB和1vcore的容器,请设置以下属性:

yarn.scheduler.maximum-allocation-mb:2049

yarn.scheduler.maximum-allocation-vcores:1

注意:即使有足够的内存(14gb)来创建7个容量为2GB的容器,上面的配置只会创建6个容量为2GB的容器,而14GB中只有12GB容器将用于群集.这是因为群集只有6vcores可用.

现在在Spark方面,

下面的属性指定每个执行程序/容器请求的内存

spark.driver.memory

spark.executor.memory

下面的属性指定每个执行程序/容器请求的vcores

spark.driver.cores

spark.executor.cores

IMP: 所有Spark的内存和vcore属性应该小于或等于YARN的配置

下面的属性指定可以从YARN群集用于spark应用程序的执行程序/容器的总数.

spark.executor.instances

此属性应小于YARN群集中可用容器的总数.

一旦纱线配置完成,火花应该请求可以根据YARN配置分配的容器.这意味着如果YARN配置为每个容器最多分配2GB并且Spark请求具有3GB内存的容器,则作业将停止或停止,因为YARN无法满足spark的请求.

现在针对您的用例: 通常,群集调整基于工作负载.但是下面的配置应该更合适.

可用内存:10GB*2节点 Vcores可用:5*2 vcores [假设]

在yarn-site.xml上 [在两个节点中]

yarn.nodemanager.resource.memory-mb :10240

yarn.nodemanager.resource.cpu-vcores :5

yarn.scheduler.maximum-allocation-mb :2049

yarn.scheduler.maximum-allocation-vcores :1

使用上面的配置,您可以在每个容器上创建最多10个容器,每个容器具有2GB,1vcore.

Spark配置

spark.driver.memory 1536MB

spark.yarn.executor.memoryOverhead 512MB

spark.executor.memory 1536MB

spark.yarn.executor.memoryOverhead 512MB

spark.driver.cores 1

spark.executor.cores 1

spark.executor.instances 19

请随意玩这些配置以满足您的需求.