-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Reduce memory usage in reader by reset all underlying readers #24912
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
Conversation
dc0d512
to
b09bbaf
Compare
b09bbaf
to
c897e09
Compare
Please add unit tests checking various combinations of stripe encodings. |
@@ -40,7 +40,7 @@ public static BatchStreamReader createStreamReader(Type type, StreamDescriptor s | |||
case INT: | |||
case LONG: | |||
case DATE: | |||
return new LongBatchStreamReader(type, streamDescriptor, systemMemoryContext); | |||
return new LongBatchStreamReader(type, streamDescriptor, systemMemoryContext, options.isResetAllReaders()); |
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.
Why are you changing batch readers? They are not used in Spark.
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.
Right, those are not used in spark. but I think not reset all underlying readers is a generic bug, hence including them. Let me know if you prefer to keep the current behavior in this PR.
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 reader is rarely used in prod. I'd suggest to not touch it.
@@ -52,9 +52,10 @@ public LongSelectiveStreamReader( | |||
Optional<Type> outputType, | |||
OrcAggregatedMemoryContext systemMemoryContext, | |||
boolean isLowMemory, | |||
long maxSliceSize) | |||
long maxSliceSize, | |||
boolean resetAllReaders) |
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.
Don't introduce resetAllReaders, it does not make much sense.
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.
The main purpose of resetAllReaders for performance comparison in prod.
I plan to remove this option if we decide to enable it by default later.
Let me know if this make sense
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.
Please remove it now to make it a default behavior.
@@ -73,12 +74,20 @@ public void startStripe(Stripe stripe) | |||
directReader = new LongDirectSelectiveStreamReader(context); | |||
} | |||
currentReader = directReader; | |||
if (dictionaryReader != null && context.isResetAllReaders()) { |
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.
I think it would be better to close and nullify the other reader if it exists. Reader creation is not very expensive, and usually stripes stick with the same encoding.
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.
sure. will try that and run some test.
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.
Overall LGTM. Asks are to 1) remove the new flag and make it default behavior; 2) remove setting system properties.
@@ -40,7 +40,7 @@ public static BatchStreamReader createStreamReader(Type type, StreamDescriptor s | |||
case INT: | |||
case LONG: | |||
case DATE: | |||
return new LongBatchStreamReader(type, streamDescriptor, systemMemoryContext); | |||
return new LongBatchStreamReader(type, streamDescriptor, systemMemoryContext, options.isResetAllReaders()); |
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 reader is rarely used in prod. I'd suggest to not touch it.
@@ -52,9 +52,10 @@ public LongSelectiveStreamReader( | |||
Optional<Type> outputType, | |||
OrcAggregatedMemoryContext systemMemoryContext, | |||
boolean isLowMemory, | |||
long maxSliceSize) | |||
long maxSliceSize, | |||
boolean resetAllReaders) |
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.
Please remove it now to make it a default behavior.
break; | ||
case DICTIONARY: | ||
if (dictionaryReader == null) { | ||
dictionaryReader = new LongDictionarySelectiveStreamReader(context); | ||
} | ||
currentReader = dictionaryReader; | ||
if (directReader != null && context.isResetAllReaders()) { | ||
directReader.startStripe(stripe); | ||
System.setProperty("RESET_LONG_READER", "RESET_LONG_READER"); |
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.
Don't set system properties in OSS, remove this from all classes. If you need it for testing use a build with local changes.
Thanks for the release note entry! Nits of formatting, so the automation can pick it up for the next release note PR.
|
Description
Currently for reader with multiple underlying readers (e.g. dictionaryReader and directReader in LongSelectiveStreamReader), only the current reader get reset in startStripe(), the other reader won't get reset, leads to extra memory usage and OOM.
This PR avoid those extra memory usage by reset all underlying readers in startStripe(). This behavior is controlled by resetAllReaders in OrcReaderOptions, and it's disabled by default
Impact
Reduce memory usage in reader.
Test Plan
Tested with Spark workload.
Around 10% workload triggered the code path which reset all underlying readers, leading to less memory usage and OOM.