gpt4 book ai didi

scala - 什么是 Spark 流中的饥饿场景?

转载 作者:行者123 更新时间:2023-12-01 12:19:03 24 4
gpt4 key购买 nike

在著名的spark streaming字数统计例子中,spark配置对象初始化如下:

/* Create a local StreamingContext with two working thread and batch interval of 1 second.
The master requires 2 cores to prevent from a starvation scenario. */

val sparkConf = new SparkConf().
setMaster("local[2]").setAppName("WordCount")

在这里,如果我将 master 从 local[2] 更改为 local 或者不设置 Master,我不会得到预期的输出,事实上字数统计不会根本不会发生。

评论说:

"The master requires 2 cores to prevent from a starvation scenario" that's why they have done setMaster("local[2]").

有人能解释一下为什么它需要 2 个内核以及什么是饥饿场景吗?

最佳答案

来自documentation :

[...] note that a Spark worker/executor is a long-running task, hence it occupies one of the cores allocated to the Spark Streaming application. Therefore, it is important to remember that a Spark Streaming application needs to be allocated enough cores (or threads, if running locally) to process the received data, as well as to run the receiver(s).

换句话说,一个线程将用于运行接收器,至少还需要一个线程来处理接收到的数据。对于一个集群,分配的核数必须大于接收者数,否则系统无法处理数据。

因此,在本地运行时,您至少需要 2 个线程,而在使用集群时,至少需要为您的系统分配 2 个内核。


饥饿场景指的是这类问题,一些线程根本无法执行,而另一些线​​程却在执行。

有两个经典问题中饥饿是众所周知的:

关于scala - 什么是 Spark 流中的饥饿场景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45874103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com