Skip to content
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

lower segment heap footprint and fix bug with expression type coercion #14002

Merged

Conversation

clintropolis
Copy link
Member

@clintropolis clintropolis commented Mar 30, 2023

Description

While working on some other stuff I noticed that we were doing something when loading segments which results in some extra heap usage storing redundant stuff we don't really need. Specifically, the changes in #12279 causes us to make a combined column and dimension list in the form of Indexed to pass to the SimpleQueryableIndex, which it was doing prior to this PR with https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/IndexIO.java#L648 GenericIndexed.fromIterable which is going to make new heap bytebuffers of the column and dimension lists. The columns Indexed is thrown away basically, but the dimensions list is kept around forever.

We actually already have to have all of these column names on heap, and are already interning them via the FileSmooshMapper https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/java/util/common/io/smoosh/SmooshedFileMapper.java#L88 which does so whenever it reads meta.smoosh to get the internal file list of a smoosh. There is an internal file as the entry point for every column name, so if we re-use this interner for the map of ColumnHolder suppliers as well as to back the Indexed<String> for the dimension list then we can save some heap.

With my laptop test cluster of ~5k segments it reduces the heap footprint by ~20MB

Before:
Screenshot 2023-03-29 at 8 27 59 PM

After:
Screenshot 2023-03-29 at 8 28 22 PM

Looking specifically at strings, we now have about 1/3 as many on heap (from the map of ColumnHolder suppliers), not counting all of the heap bytebuffers which were backing the dimensions lists.
Screenshot 2023-03-29 at 8 38 54 PM
Screenshot 2023-03-29 at 8 39 00 PM

Completely unrelated, this PR also fixes a bug with native expression type coercion with complex types. The added test would fail where it would return "unknown complex" sometimes when using the ExpressionTypeCoercion.operator method. I guess I could have made it its own PR, but both things were small...

This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • been tested in a test Druid cluster.

@@ -48,7 +48,11 @@
*/
public class SmooshedFileMapper implements Closeable
{
private static final Interner<String> STRING_INTERNER = Interners.newWeakInterner();
/**
* Interner for smoosh internal files, which includes all column names since very column has an internal file
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: s/very/every/

@clintropolis clintropolis merged commit 518698a into apache:master Mar 31, 2023
@clintropolis clintropolis deleted the smaller-segment-heap-footprint branch March 31, 2023 20:53
@clintropolis clintropolis added this to the 26.0 milestone Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants