DSE Spark Streaming:长活动批处理队列

时间:2018-04-24 12:19:21

标签: scala apache-spark spark-streaming cassandra-3.0 spark-cassandra-connector

我有以下代码:

val conf = new SparkConf()
  .setAppName("KafkaReceiver")
  .set("spark.cassandra.connection.host", "192.168.0.78")
  .set("spark.cassandra.connection.keep_alive_ms", "20000")
  .set("spark.executor.memory", "2g")
  .set("spark.driver.memory", "4g")
  .set("spark.submit.deployMode", "cluster")
  .set("spark.executor.instances", "3")
  .set("spark.executor.cores", "3")
  .set("spark.shuffle.service.enabled", "false")
  .set("spark.dynamicAllocation.enabled", "false")
  .set("spark.io.compression.codec", "snappy")
  .set("spark.rdd.compress", "true")
  .set("spark.streaming.backpressure.enabled", "true")
  .set("spark.streaming.backpressure.initialRate", "200")
  .set("spark.streaming.receiver.maxRate", "500")

val sc = SparkContext.getOrCreate(conf)
val ssc = new StreamingContext(sc, Seconds(10))
val sqlContext = new SQLContext(sc)
val kafkaParams = Map[String, String](
  "bootstrap.servers" -> "192.168.0.113:9092",
  "group.id" -> "test-group-aditya",
  "auto.offset.reset" -> "largest")

val topics = Set("random")
val kafkaStream = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](ssc, kafkaParams, topics)

我使用以下命令通过spark-submit运行代码:

dse> bin/dse spark-submit --class test.kafkatesting /home/aditya/test.jar

我在不同的计算机上安装了三节点Cassandra DSE群集。每当我运行应用程序时,它会占用大量数据并开始创建活动批处理队列,这反过来会产生积压和长调度延迟。如何提高性能并控制队列,使其仅在完成当前批处理后才接收新批处理?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,在代码中做了一些优化。而不是保存RDD尝试创建Dataframe,与RDD相比,将DF保存到Cassandra的速度要快得多。此外,增加核心和执行器内存的数量以获得良好的结果。

谢谢,