cassandra DSESpark流:长活动批处理队列

x0fgdtte  于 2022-11-23  发布在  Cassandra
关注(0)|答案(1)|浏览(128)

下面的代码:

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集群,安装在不同的机器上。每当我运行应用程序时,它会获取大量数据,并开始创建活动批处理队列,这反过来又会产生积压和长时间的调度延迟。我如何提高性能并控制队列,使其仅在执行完当前批处理后才接收新批处理?

bz4sfanl

bz4sfanl1#

我找到了解决方案,在代码中做了一些优化。尝试创建Dataframe而不是保存RDD,将DF保存到Cassandra中比RDD快得多。同时,增加核心和执行器内存的数量,以达到良好的效果。
谢谢你,

相关问题