![](/img/trans.png)
[英]How to set up load balancing with java 8 collection parallel stream processing?
[英]How Spark Stream Processing sets up computation?
關於火花流處理如何工作,我有一個基本問題。
在這里 ,有一個塊表示:“請注意,執行這些行時,Spark Streaming僅設置將在啟動后執行的計算,而尚未開始真正的處理。要在所有轉換之后開始進行處理已經設置好了,我們終於調用了start方法。”
我無法消化以上描述。 理想情況下,計算將屬於一個函數,並以某種方式要求“ ssc.start()”循環執行此函數。 但是在這里,首先執行核心計算,然后啟動流上下文。 這有什么意義?
public final class JavaNetworkWordCount {
private static final Pattern SPACE = Pattern.compile(" ");
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage: JavaNetworkWordCount <hostname> <port>");
System.exit(1);
}
StreamingExamples.setStreamingLogLevels();
// Create the context with a 1 second batch size
SparkConf sparkConf = new SparkConf().setAppName("JavaNetworkWordCount");
JavaStreamingContext ssc = new JavaStreamingContext(sparkConf, Durations.seconds(1));
// Create a JavaReceiverInputDStream on target ip:port and count the
// words in input stream of \n delimited text (eg. generated by 'nc')
// Note that no duplication in storage level only for running locally.
// Replication necessary in distributed scenario for fault tolerance.
/* below four statements represents the core computation */
JavaReceiverInputDStream<String> lines = ssc.socketTextStream(
args[0], Integer.parseInt(args[1]), StorageLevels.MEMORY_AND_DISK_SER);
JavaDStream<String> words = lines.flatMap(x -> Arrays.asList(SPACE.split(x)).iterator());
JavaPairDStream<String, Integer> wordCounts = words.mapToPair(s -> new Tuple2<>(s, 1))
.reduceByKey((i1, i2) -> i1 + i2);
wordCounts.print();
/* starting actual stream processing */
ssc.start();
ssc.awaitTermination();
}
}
但是在這里,首先執行核心計算,然后啟動流上下文。 這有什么意義?
因為“核心計算”不是“計算”。 描述了是否啟動了StreamingContext
以及是否接收到任何數據,應該執行的操作。
如果仍然不明確-它是什么並不怎么和內部不被泄漏到用戶代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.