Spark:并行处理多个 kafka 主题 [英] Spark: processing multiple kafka topic in parallel

查看:61
本文介绍了Spark:并行处理多个 kafka 主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 spark 1.5.2.我需要使用 kafka 作为流媒体源运行 Spark 流媒体作业.我需要从 kafka 中的多个主题中读取并以不同的方式处理每个主题.

I am using spark 1.5.2. I need to run spark streaming job with kafka as the streaming source. I need to read from multiple topics within kafka and process each topic differently.

  1. 在同一份工作中这样做是否是个好主意?如果是这样,我应该为每个主题创建具有多个分区或不同流的单个流吗?
  2. 我使用的是 Kafka direct steam.据我所知,spark 为每个分区启动长时间运行的接收器.我有一个相对较小的集群,6 个节点,每个节点有 4 个内核.如果我在每个主题中有很多主题和分区,由于大多数执行器都忙于长时间运行的接收器,效率会受到影响吗?如果我的理解有误,请指正

推荐答案

我做了以下观察,以防对某人有帮助:

I made the following observations, in case its helpful for someone:

  1. 在 kafka 直接流中,接收器不像长时间运行的任务那样运行.在每个batch inerval开始时,首先在executor中从kafka中读取数据.读取后,处理部分将接管.
  2. 如果我们创建一个包含多个主题的流,主题会一个接一个地读取.此外,过滤 dstream 以应用不同的处理逻辑将为作业添加另一个步骤
  3. 创建多个流有两个方面的帮助: 1. 您不需要应用过滤操作来以不同的方式处理不同的主题.2. 您可以并行读取多个流(而不是在单个流的情况下一个一个).为此,有一个未公开的配置参数 spark.streaming.concurrentJobs*.所以,我决定创建多个流.

  1. In kafka direct stream, the receivers are not run as long running tasks. At the beginning of each batch inerval, first the data is read from kafka in executors. Once read, the processing part takes over.
  2. If we create a single stream with multiple topics, the topics are read one after the other. Also, filtering the dstream for applying different processing logic would add another step to the job
  3. Creating multiple streams would help in two ways: 1. You don't need to apply the filter operation to process different topics differently. 2. You can read multiple streams in parallel (as opposed to one by one in case of single stream). To do so, there is an undocumented config parameter spark.streaming.concurrentJobs*. So, I decided to create multiple streams.

sparkConf.set("spark.streaming.concurrentJobs", "4");

这篇关于Spark:并行处理多个 kafka 主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆