DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Building Your Tech Career Like Code: A Systematic AI Approach
  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • The Evolution of Adaptive Frameworks
  • How to Design Event Streams, Part 1

Trending

  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp
  • Delta Lake UniForm to Snowflake: Cross-Platform Table Access Without a Second Copy
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Data Engineering
  3. Big Data
  4. Throttle Spark-Kafka Streaming Volume

Throttle Spark-Kafka Streaming Volume

Time to dive into the settings to configure your loads.

By 
Sudhish koloth
·
Updated Dec. 21, 20 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
9.1K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

This article will help any new developer who wants to control the volume of Spark Kafka streaming.

A Spark streaming job internally uses a micro-batch processing technique to stream and process data. The initial state of the job will be in the "queued" status, then it will then move to the "processing" status, and then it is marked with the "completed" status.

Prerequisites

  • The developer should be familiar with Spark streaming
  • The developer should have some knowledge of Kafka and Spark.

Problem Statement

Apache Spark is often used for data streaming. One of the streaming stacks it is well aligned with is Kafka. Kafka, as we know, is a powerful distributed platform. There are instances where the Spark streaming job is up and running, and the sudden increase in data volume may cause some bottlenecks.

Though Spark is a great processing engine, given a multi-tenant cluster, and if your app is consuming a high volume of Kafka messages, then there is a high chance of messages getting stuck in the queued status.

Since volume is high and there are not enough resources, there are many jobs stuck in the queue. This problem is due to the fact that your job runs on some defined configuration; let's say it normally handles 2,000 TPS, but your app suddenly got an inflow of 15,000 TPS. 

This happens frequently — it can happen is when your Hadoop cluster is down for a prolonged duration, for example. Let's assume the job is down for four hours, and after it is up, when the job resumes, then a huge load of data piles up, and eventually your Spark job will not have enough resources to handle all that pending data at once.

Throttling Technique  

The throttling technique comes up in rescue to solve this problem. Using this technique you can control the volume of data that your spark streaming job can handle maximum at once. 

For Spark streaming Kafka, there is one key property that can be used to control the volume.

Python
 




x


 
1
spark.streaming.kafka.maxRatePerPartition 3000
2
#Configured while creating topic
3
spark.kafka.topic.partition 16



In the above properties, 'spark.streaming.Kafka.maxRatePerPartition'  plays a key role in throttling the messages. 

Above, we defined the throttling value as 3,000, and the actual partition for this topic is 16. Now the maximum it can process at one micro-batch is:

Plain Text
 




x


 
1
max = 16*2*3000



So, at max, 96K messages will be processed per micro-batch. 

This is one example — the actual settings will differ from job to job, and so will the max volume of data your job can process. Based on your executors and executor memory, you have to define the right configuration to throttle. 

Throttling is a key technique for your job stability. Determining the right settings and configuration will play a crucial role in the processing of a high volume of data. 

career kafka Data (computing)

Opinions expressed by DZone contributors are their own.

Related

  • Building Your Tech Career Like Code: A Systematic AI Approach
  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • The Evolution of Adaptive Frameworks
  • How to Design Event Streams, Part 1

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook