Skip to content

KAFKA-19227: Piggybacked share fetch acknowledgements performance issue #19612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2025

Conversation

apoorvmittal10
Copy link
Contributor

@apoorvmittal10 apoorvmittal10 commented May 1, 2025

The PR fixes the issue when ShareAcknowledgements are piggybacked on
ShareFetch. The current default configuration in clients sets batch size and max fetch records as per the max.poll.records config,
default 500. Which means all records in a single poll will be fetched
and acknowledged. Also the default configuration for inflight records in
a partition is 200. Which means prior fetch records has to be
acknowledged prior fetching another batch from share partition.

The piggybacked share fetch-acknowledgement calls from KafkaApis are
async and later the response is combined. If respective share fetch
starts waiting in purgatory because all inflight records are currently
full, hence when startOffset is moved as part of acknowledgement, then a
trigger should happen which should try completing any pending share
fetch requests in purgatory. Else the share fetch requests wait in
purgatory for timeout though records are available, which dips the share
fetch performance.

The regular fetch has a single criteria to land requests in purgatory,
which is min bytes criteria, hence any produce in respective topic
partition triggers to check any pending fetch requests. But share fetch
can wait in purgatory because of multiple reasons: 1) Min bytes 2)
Inflight records exhaustion 3) Share partition fetch lock competition.
The trigger already happens for 1 and current PR fixes 2. We will
investigate further if there should be any handling required for 3.

Reviewers: Abhinav Dixit [email protected], Andrew Schofield
[email protected]

@github-actions github-actions bot added triage PRs from the community core Kafka Broker KIP-932 Queues for Kafka small Small PRs labels May 1, 2025
@apoorvmittal10 apoorvmittal10 added ci-approved and removed triage PRs from the community labels May 1, 2025
@@ -2405,13 +2424,10 @@ && checkForStartOffsetWithinBatch(inFlightBatch.firstOffset(), inFlightBatch.las
lock.writeLock().unlock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a maybeCompleteDelayedShareFetchRequest in this finally block as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There exists code at line 2439 in this method itself for trigger. So for release, first cache is updated and persister call is just to record correct delivery count. So notification to purgatory is not tied with persister.

@adixitconfluent
Copy link
Contributor

adixitconfluent commented May 2, 2025

@apoorvmittal10 Thanks for making the change. The change makes sense to me. Can you post the metrics evidence that this is the part of the code causing the problem?

@apoorvmittal10
Copy link
Contributor Author

apoorvmittal10 commented May 2, 2025

@apoorvmittal10 Thanks for making the change. The change makes sense to me. Can you post the metrics evidence that this is the part of the code causing the problem?

You should look for ExpiresPerSec - DelayedShareFetch metric with and without produce.

Copy link
Contributor

@adixitconfluent adixitconfluent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@AndrewJSchofield AndrewJSchofield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. We should increase the locks per share-partition to improve sharing with multiple consumers too.

@apoorvmittal10
Copy link
Contributor Author

Thanks for the PR. We should increase the locks per share-partition to improve sharing with multiple consumers too.

Sure, I ll update it as part of https://issues.apache.org/jira/browse/KAFKA-19245

@apoorvmittal10 apoorvmittal10 merged commit ac9520b into apache:trunk May 6, 2025
23 checks passed
shmily7829 pushed a commit to shmily7829/kafka that referenced this pull request May 7, 2025
…ue (apache#19612)

The PR fixes the issue when ShareAcknowledgements are piggybacked on
ShareFetch. The current default configuration in clients sets `batch
size` and `max fetch records` as per the `max.poll.records` config,
default 500. Which means all records in a single poll will be fetched
and acknowledged. Also the default configuration for inflight records in
a partition is 200. Which means prior fetch records has to be
acknowledged prior fetching another batch from share partition.

The piggybacked share fetch-acknowledgement calls from KafkaApis are
async and later the response is combined. If respective share fetch
starts waiting in purgatory because all inflight records are currently
full, hence when startOffset is moved as part of acknowledgement, then a
trigger should happen which should try completing any pending share
fetch requests in purgatory. Else the share fetch requests wait in
purgatory for timeout though records are available, which dips the share
fetch performance.

The regular fetch has a single criteria to land requests in purgatory,
which is min bytes criteria, hence any produce in respective topic
partition triggers to check any pending fetch requests. But share fetch
can wait in purgatory because of multiple reasons: 1) Min bytes 2)
Inflight records exhaustion 3) Share partition fetch lock competition.
The trigger already happens for 1 and current PR fixes 2. We will
investigate further if there should be any handling required for 3.

Reviewers: Abhinav Dixit <[email protected]>, Andrew Schofield
<[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-approved core Kafka Broker KIP-932 Queues for Kafka small Small PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants