[adapters] Wake up Kafka receiver thread when backpressure is relieved.#5934
Merged
[adapters] Wake up Kafka receiver thread when backpressure is relieved.#5934
Conversation
The Kafka input connector uses threads to read data from librdkafka queues for the main connector thread to poll. Particularly when "synchronize_partitions" is turned on, queues could accumulate an arbitrary amount of data for the main thread to read, so we implement a backpressure mechanism that prevents any given queue from getting too big, with an arbitrary 1 MB per-queue limit. Each of our receiver threads, in RecvThread::run, polls a number of queues in turn. If any work can be done in any of them, it loops, but if all of them either have an empty queue or are subject to backpressure, we park for up to one second to avoid wasting CPU. If we're parking for empty queues, a callback should wake the thread up if any of them become nonempty (see the call to `set_nonempty_callback`), so in that case the 1-second park timeout is "just in case". However, until now there's been nothing similar for parking if all of the queues are subject to backpressure. This commit fixes that: it gives each PartitionReceiver the ability to wake up its ReceiverThread, and makes them do that whenever they dequeue data from the thread such that it should no longer be subject to backpressure. This made a simple test case with "synchronize_partitions" enabled much faster for me, reducing it from several times as slow as with that feature disabled to more like ~5% slower, based on eyeballing the performance in the web console. Signed-off-by: Ben Pfaff <blp@feldera.com>
mihaibudiu
approved these changes
Mar 26, 2026
|
|
||
| /// Returns true if a partition queue that holds `n_bytes` should pause for | ||
| /// backpressure. | ||
| fn needs_backpressure(n_bytes: usize) -> bool { |
Contributor
There was a problem hiding this comment.
will this become some kind of configuration parameter?
Member
Author
There was a problem hiding this comment.
I don't see value in that yet.
ryzhyk
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Kafka input connector uses threads to read data from librdkafka queues for the main connector thread to poll. Particularly when "synchronize_partitions" is turned on, queues could accumulate an arbitrary amount of data for the main thread to read, so we implement a backpressure mechanism that prevents any given queue from getting too big, with an arbitrary 1 MB per-queue limit.
Each of our receiver threads, in RecvThread::run, polls a number of queues in turn. If any work can be done in any of them, it loops, but if all of them either have an empty queue or are subject to backpressure, we park for up to one second to avoid wasting CPU. If we're parking for empty queues, a callback should wake the thread up if any of them become nonempty (see the call to
set_nonempty_callback), so in that case the 1-second park timeout is "just in case".However, until now there's been nothing similar for parking if all of the queues are subject to backpressure. This commit fixes that: it gives each PartitionReceiver the ability to wake up its ReceiverThread, and makes them do that whenever they dequeue data from the thread such that it should no longer be subject to backpressure.
This made a simple test case with "synchronize_partitions" enabled much faster for me, reducing it from several times as slow as with that feature disabled to more like ~5% slower, based on eyeballing the performance in the web console.
Describe Manual Test Plan
I manually tested the performance.