Skip to content

ORC-1138 Optimizes the read of streams in ORC by combining multiple nearby reads into a single read, optionally allowing the retention or drop of the extra bytes - #1072

Closed
pavibhai wants to merge 7 commits into
apache:mainfrom
pavibhai:gh_1138_seek_v_read

Conversation

@pavibhai

Copy link
Copy Markdown
Contributor

Optimizes the read of streams in ORC by combining multiple nearby reads a single read, optionally allowing the retention or drop of the extra bytes.

  • minSeekSize: If separation between multiple reads is within minSeekSize then these are combined into a single read
  • minSeekSizeTolerance: Helps in the decisioning of whether to retain the extra bytes (extra memory) or take extra CPU to drop the unwanted bytes

What changes were proposed in this pull request?

We are introducing two new configuration parameters that control how read of streams takes place in ORC

  • minSeekSize: If separation between multiple reads is within minSeekSize then these are combined into a single read
  • minSeekSizeTolerance: Helps in the decisioning of whether to retain the extra bytes (extra memory) or take extra CPU to drop the unwanted bytes

Why are the changes needed?

This leads to significant time savings (and cost also) when dealing with AWS S3. Reads with gaps e.g. reading alternate columns shows a significant penalty 5.8s vs 1.4s with the patch.

How was this patch tested?

  • New Unit Tests were added
  • None of the existing tests were changed

Optimizes the read of streams in ORC by combining multiple nearby reads a single read, optionally allowing the retention or drop of the extra bytes.

* minSeekSize: If separation between multiple reads is within minSeekSize then these are combined into a single read
* minSeekSizeTolerance: Helps in the decisioning of whether to retain the extra bytes (extra memory) or take extra CPU to drop the unwanted bytes
@github-actions github-actions Bot added the JAVA label Mar 28, 2022

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, @pavibhai .

cc @williamhyun

Integer.MAX_VALUE - 1024, "When reading stripes >2GB, specify max limit for the chunk size."),
ORC_MIN_DISK_SEEK_SIZE("orc.min.disk.seek.size",
"hive.exec.orc.min.disk.seek.size",
0,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

indentation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure about the change on BufferChunk.equals method. Are you sure, @pavibhai ?

return (chunk != null && ob.chunk != null && chunk.equals(ob.chunk))
|| (chunk == null && ob.chunk == null
&& offset == ob.offset
&& getLength() == ob.getLength());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like breaking the contact of equals.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It looks like the offset/length comparison is missing when chunck != null, how about this

return Objects.equals(chunk, ob.chunk) && offset == ob.offset && getLength() == ob.getLength();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would agree with @guiyanakuang we should have the comparison on offset and length. I include that proposal in the revision.

@dongjoon-hyun I am using this currently only in the tests, so I don't mind reverting this back and having this custom comparison in the tests.

@dongjoon-hyun dongjoon-hyun Mar 29, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for reverting this part, @pavibhai .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dongjoon-hyun I have reverted this and included this comparison logic in the unit test.

IMO it is more thorough to check for offset and length in the equals. We can take that up independent of this patch.

@omalley or @pgaref any thoughts on this?

@dongjoon-hyun

Copy link
Copy Markdown
Member

cc @pgaref and @guiyanakuang , too

"When determining contiguous reads, gaps within this size are "
+ "read contiguously and not seeked. Default value of zero disables this "
+ "optimization"),
ORC_MIN_DISK_SEEK_SIZE_TOLERANCE("orc.min.disk.seek.size.tolerance",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for sharing the patch. AWS S3 connectors by default has readahead (mostly set to 64 or 128KB). So in a way, the data is read in addition to what is requested for.

  1. Would this patch be different from that?
  2. There can be cases when this could be reading more than necessary and throwing off the read bytes later. Would that cause perf penalties?

@pavibhai pavibhai Mar 29, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would this patch be different from that?

I can see the following differences:

  • In this case the decision of reading extra bytes is based on the read plan in ORC as compared to a simple read ahead
    • We will not request extra if the read does not intend on going there
    • In our tests we are seeing 4MB seems to work well as shown in the benchmark results
  • This can additionally be tweaked to other FS by configuring these values based on FS

There can be cases when this could be reading more than necessary and throwing off the read bytes later. Would that cause perf penalties?

There will be a trade-off between memory and cpu, the option to both read the extra bytes and drop the extra bytes is configurable allowing one to turn both or one of them off as the need demands.

+ "read contiguously and not seeked. Default value of zero disables this "
+ "optimization"),
ORC_MIN_DISK_SEEK_SIZE_TOLERANCE("orc.min.disk.seek.size.tolerance",
"hive.exec.orc.min.disk.seek.size.tolerance", 0.00,

@dongjoon-hyun dongjoon-hyun Apr 9, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we remove this Hive conf? Actually, Apache Hive has no future release plan to use this, doesn't it? I'm a little reluctant to add a misleading Hive configuration from Apache ORC side if there is no agreement from Apache Hive community.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dongjoon-hyun Agreed, I have reverted both the properties to use the ORC configuration

@dongjoon-hyun

Copy link
Copy Markdown
Member

Thank you for updates, @pavibhai .

ORC_MIN_DISK_SEEK_SIZE_TOLERANCE("orc.min.disk.seek.size.tolerance",
"orc.min.disk.seek.size.tolerance", 0.00,
"Define the tolerance for for extra bytes read as a result of "
+ "orc.min.disk.seek.size. If the (bytesRead - bytesNeeded) / bytesNeeded"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

bytesNeeded" -> bytesNeeded "

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* @param last the last range to read
* @param allocateDirect should we use direct buffers
*/
static void readRanges(FSDataInputStream file,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think we can keep this in some way, @pavibhai ? Although it's impl package, we know that some downstream like Hive and Flink is using our internals. If possible, we should not remove anything for safety.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I checked out hive@master, flink@master and I don't see any references to this method.

I think it should be fine to remove this method. As you called out given that it is in impl I think we should be ok cleaning up a method that is package local.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for checking, @pavibhai . However, it wasn't okay at all. Please see the history.

ORC-685: Add ReaderImpl.extractFileTail back (#570)
ORC-677: Add a deprecated legacy constructor SargApplier back (#557)
ORC-676. Add getRawDataSizeFromColIndices back to ReaderImpl (#555)
ORC-671. Add OrcTail.getStripeStatistics back for backward compatiblility

Is there any difficulty to keep this method, @pavibhai ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hive and Flink were just examples here because they didn't use the last Apache ORC yet due to those breaking change from our side. Please check our Adopter page. I don't think it's safe for new Improvement PR to remove something in the feature release.

https://orc.apache.org/docs/adopters.html

Even Apache ORC 2.0, I'd avoid this kind approach.

@dongjoon-hyun dongjoon-hyun Apr 14, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hive is using <orc.version>1.6.9</orc.version> and Flink is using <orc.version>1.5.6</orc.version> because Apache ORC breaks like this. Even for the implementation package, Apache ORC community had better conservative instead of moving away from our customers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So you are recommending that any member that is not private should be assumed to be public? Is that correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the quick call to clarify this.

I have added the deleted method back. There is some code duplication as a result of this in the method, if you are ok with rewriting this method with the new code while retaining the same interface I can do that as well.

return last;
}

static BufferChunk findSingleRead(BufferChunk first) {

@dongjoon-hyun dongjoon-hyun Apr 14, 2022 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please move function to the original line after the original comment because this is public.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is package local moved

}
}

static void readDiskRanges(FSDataInputStream file,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ditto. We should put this public method after the method description.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

moved the package local method as suggested

* @param minSeekSizeTolerance allowed tolerance for extra bytes in memory as a result of
* minSeekSize
*/
static void readDiskRanges(FSDataInputStream file,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to add this method as public? Shall we add it as private?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, made it private

@dongjoon-hyun

Copy link
Copy Markdown
Member

Could you revise the PR title, @pavibhai ?

@pavibhai pavibhai changed the title ORC-1138 ORC-1138 Optimizes the read of streams in ORC by combining multiple nearby reads a single read, optionally allowing the retention or drop of the extra bytes Apr 14, 2022
@pavibhai pavibhai changed the title ORC-1138 Optimizes the read of streams in ORC by combining multiple nearby reads a single read, optionally allowing the retention or drop of the extra bytes ORC-1138 Optimizes the read of streams in ORC by combining multiple nearby reads into a single read, optionally allowing the retention or drop of the extra bytes Apr 14, 2022

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @pavibhai .

@dongjoon-hyun dongjoon-hyun added this to the 1.8.0 milestone Apr 25, 2022
@pavibhai
pavibhai deleted the gh_1138_seek_v_read branch May 2, 2022 21:10
cxzl25 pushed a commit to cxzl25/orc that referenced this pull request Jan 11, 2024
…nearby reads into a single read, optionally allowing the retention or drop of the extra bytes

We are introducing two new configuration parameters that control how read of streams takes place in ORC
* minSeekSize: If separation between multiple reads is within minSeekSize then these are combined into a single read
* minSeekSizeTolerance: Helps in the decisioning of whether to retain the extra bytes (extra memory) or take extra CPU to drop the unwanted bytes

This leads to significant time savings (and cost also) when dealing with AWS S3. Reads with gaps e.g. reading alternate columns shows a significant penalty 5.8s vs 1.4s with the patch.

* New Unit Tests were added
* None of the existing tests were changed

Closes apache#1072

Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants