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
Fixing memory leak due to HoodieLogFileReader holding on to a logblock #346
Conversation
n3nash
commented
Mar 14, 2018
- Removed inMemory HashMap usage in merge(..) code in LogScanner
- Removed inMemory HashMap usage in merge(..) code in LogScanner
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.
@n3nash can you help me understand where the long lived block is held? both places look like temporary allocations to me..
HoodieAvroDataBlock dataBlock) throws IOException { | ||
// TODO (NA) - Instead of creating a new HashMap use the spillable map | ||
Map<String, HoodieRecord<? extends HoodieRecordPayload>> recordsFromLastBlock = Maps |
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.
This intermediate map was causing the issue? I guess we don't need this anymore given we are lazy reading the metadata and the content is only read when we are sure we want to merge?
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.
2 issues. This one is just extra overhead which we don't need and cannot afford. So yes, we merge only when we are sure so this is not needed.
@@ -56,7 +56,6 @@ | |||
private static final byte[] oldMagicBuffer = new byte[4]; | |||
private static final byte[] magicBuffer = new byte[6]; | |||
private final Schema readerSchema; | |||
private HoodieLogBlock nextBlock = null; |
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.
does this cause additional memory overhead?
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.
For this issue. The following is my analysis. Essentially, we pass an inputstream from HoodieLogFileReader to the LogBlocks. An inputstream can be shared in more than 1 logblock. A list of logBlocks are kept until they are merged. So until all logblocks holding the inputstream generated in HoodieLogFileReader are GC'd, they will continue to hold memory. So the last block read is kept in this variable nextBlock
and so till the HoodieLogFileReader instance in GC'd this will cause memory overhead.
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.
Per the screenshot in the ticket, most retained memory comes from private List<IndexedRecord> records;
in the AvroDataBlock and not the inputStream itself? The inputstream being held does not seem to have causing these issues..
This might be just a large data block being loaded into memory?
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.
But I think we will hold onto the last block in each file and that's what you are seeing..