-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9703:Free up resources when splitting huge batches #8286
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,14 +268,17 @@ public Deque<ProducerBatch> split(int splitBatchSize) { | |
| // A newly created batch can always host the first message. | ||
| if (!batch.tryAppendForSplit(record.timestamp(), record.key(), record.value(), record.headers(), thunk)) { | ||
| batches.add(batch); | ||
| batch.closeForRecordAppends(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably also want to close the last batch for append in line 279.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @becketqin My negligence! The last batch should also be closed. I have modified it. |
||
| batch = createBatchOffAccumulatorForRecord(record, splitBatchSize); | ||
| batch.tryAppendForSplit(record.timestamp(), record.key(), record.value(), record.headers(), thunk); | ||
| } | ||
| } | ||
|
|
||
| // Close the last batch and add it to the batch list after split. | ||
| if (batch != null) | ||
| if (batch != null) { | ||
| batches.add(batch); | ||
| batch.closeForRecordAppends(); | ||
| } | ||
|
|
||
| produceFuture.set(ProduceResponse.INVALID_OFFSET, NO_TIMESTAMP, new RecordBatchTooLargeException()); | ||
| produceFuture.done(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
batch.closeForRecordAppendsdoes NOT release the byte array hosted byMemoryRecordsBuilderappendStreamis a wrap ofbufferStream. Not sure whether callingbatch.closeForRecordAppends()can resolve the OOM or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chia7712 Thanks for reporting the issue. But I'd like to understand this problem a bit more. Supposedly the split batches will be closed when they are drained out of the
RecordAccumulator.https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java#L608
and
ProducerBatch#close()callsProducerBatch#closeForRecordAppends().Do you have a heap dump when the OOM happens so we can take a further look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@becketqin In my case, the OOM is caused by negative estimatedCompressionRatio. I have committed #8285 to fix it.