How to stream 100GB of data in Kafka topic?

Viewed 627

So, in one of our kafka topic, there's close to 100 GB of data. We are running spark-structured streaming to get the data in S3

When the data is upto 10GB, streaming runs fine and we are able to get the data in S3. But with 100GB, it is taking forever to stream the data in kafka.

Question: How does spark-streaming reads data from Kafka? Does it take the entire data from current offset? Or does it take in batch of some size?

1 Answers

Spark will work off consumer groups, just as any other Kafka consumer, but in batches. Therefore it takes as much data as possible (based on various Kafka consumer settings) from the last consumed offsets. In theory, if you have the same number of partitions, with the same commit interval as 10 GB, it should only take 10x longer to do 100 GB. You've not stated how long that currently takes, but to some people 1 minute vs 10 minutes might seem like "forever", sure.

I would recommend you plot the consumer lag over time using the kafka-consumer-groups command line tool combined with something like Burrow or Remora... If you notice an upward trend in the lag, then Spark is not consuming records fast enough. To overcome this, the first option would be to ensure that the number of Spark executors is evenly consuming all Kafka partitions.

You'll also want to be making sure you're not doing major data transforms other than simple filters and maps between consuming and writing the records, as this also introduces lag.


For non-Spark approaches, I would like to point out that the Confluent S3 connector is also batch-y in that it'll only periodically flush to S3, but the consumption itself is still closer to real-time than Spark. I can verify that it's able to write very large S3 files (several GB in size), though, if the heap is large enough and the flush configurations are set to large values.

Secor by Pinterest is another option that requires no manual coding

Related