What is Starvation scenario in Spark streaming?

≯℡__Kan透↙ 提交于 2019-12-12 16:18:21

问题


In the famous word count example for spark streaming, the spark configuration object is initialized as follows:

/* 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")

Here if I change the master from local[2] to local or does not set the Master, I do not get the expected output and in fact word counting doesn't happen at all.

The comment says:

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

Can somebody explain me why it requires 2 cores and what is starvation scenario ?


回答1:


From the 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).

In other words, one thread will be used to run the receiver and at least one more is necessary for processing the received data. For a cluster, the number of allocated cores must be more than the number of receivers, otherwise the system can not process the data.

Hence, when running locally, you need at least 2 threads and when using a cluster at least 2 cores need to be allocated to your system.


Starvation scenario refers to this type of problem, where some threads are not able to execute at all while others make progress.

There are two classical problems where starvation is well known:

  • Dining philosophers
  • Readers-writer problem, here it's possible to synchronize the threads so the readers or writers starve. It's also possible to make sure that no starvation occurs.


来源:https://stackoverflow.com/questions/45874103/what-is-starvation-scenario-in-spark-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!