apache spark – Best way to push 2 GBPS data to Kafka topic via PySpark
I am trying to do load testing for the Kafka Producer and Kafka Consumer. For this reason, I have generated 2 GBPS data of one file with a payload of 4KB each. I have used PySpark to load this data and push it to the Kafka topic since I want to achieve 2 GBPS throughput.
from pyspark.sql.session import SparkSession
spark = SparkSession.\
builder. \
appName("Batch JSON read"). \
config("spark.jars.packages", "org.apache.spark:spark-sql-kafka-0-10_2.12:3.3.0"). \
getOrCreate()
df = spark.read.option("multiline","true").json("/Users/Downloads/sample_data.json")
df.selectExpr("to_json(struct(*)) AS value") \
.write.format('kafka') \
.option("kafka.bootstrap.servers", "localhost:9092") \
.option("topic", "test01") \
.save()
I can push the data but wanted some suggestions if this is the correct way to push the data in "batches" if I want to go ahead with PySpark or if I can leverage batch.size or linder.ms properties of Kafka with CLI.
Once the approach is fixed I will integrate it with JMeter for load testing.
Any hints are appreciated.
TIA.
Read more here: Source link
