You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "saithal-confluent (via GitHub)" <gi...@apache.org> on 2024/05/30 08:42:26 UTC

[PR] Remove DimensionDictionary size call as its expensive (druid)

saithal-confluent opened a new pull request, #16517:
URL: https://github.com/apache/druid/pull/16517

   <!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
   
   <!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
   
   <!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
   
   <!-- If you are a committer, follow the PR action item checklist for committers:
   https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
   
   ### Description
   
   <!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
   
   <!-- Describe your patch: what did you change in code? How did you fix the problem? -->
   
   <!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
   
   ![image](https://github.com/apache/druid/assets/111732128/7c4aa673-97df-487f-aa98-8b5a21e9dfff)
   
   
   Checking the size of the dimension lookup dictionary is expensive as it involves locks. This was seen in one of the CPU profiles taken on indexers.
   The fix for this is to have a flag which tracks changes to the dimension lookup dictionary and use that value at the end instead of checking the dimension lookup dictionary again.
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   #### Release note
   <!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users. 
   
   If your change doesn't have end user impact, you can skip this section.
   
   For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
   
   -->
   
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * [CHANGED] processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer::processRowValsToUnsortedEncodedKeyComponent
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   
   - [ ] been self-reviewed.
      - [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] a release note entry in the PR description.
   - [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [ ] 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](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
   - [ ] added integration tests.
   - [ ] been tested in a test Druid cluster.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1623763753


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -83,7 +83,7 @@ public StringDimensionIndexer(
   public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@Nullable Object dimValues, boolean reportParseExceptions)
   {
     final int[] encodedDimensionValues;
-    final int oldDictSize = dimLookup.size();
+    volatile boolean dictionaryChanged = false;

Review Comment:
   I'll revert it to using plain boolean. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1623910785


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -94,13 +94,21 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     if (dimValues == null) {
       final int nullId = dimLookup.getId(null);
       encodedDimensionValues = nullId == DimensionDictionary.ABSENT_VALUE_ID ? new int[]{dimLookup.add(null)} : new int[]{nullId};
+      if (nullId == DimensionDictionary.ABSENT_VALUE_ID) {
+        encodedDimensionValues = new int[]{dimLookup.add(null)};
+        dictionaryChanged = true;
+      } else {
+        encodedDimensionValues = new int[]{nullId};
+      }

Review Comment:
   Removed the check 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1625821371


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   Since the dimLookup.size() is quite expensive, as seen from the screenshot, I've tried to remove that call by implicitly checking if the `add` to `dimLookup` results in a change in the size of `dimLookup`. 
   You're right about the behavioural change. To keep the same behaviour, I've pushed a commit which would now check if the result of `dimLookup.add()` with `-1` and then set the boolean `dictionaryChanged` accordingly. 
   Please take a look @kgyrtkirk 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1627535702


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   I believe the main purpose of the `dimLookup` field is to provide a common place where the different strings get an assigned number - so that if its able to recall an earlier value that's actually very important ...this change will destroy the `sortedLookup` cache even in case all calls to `add` were hits.
   
   I think you should either remove the changes in this file - or find a different way to address this; one idea could be: to connect the `sortedLookup` more closely when an add happens:
   * move the sorted dictionary caching to `StringDimensionDictionary`
   * extract a protected `realAdd` from the current `add` in `DimensionDictionary` 
   * implement `realAdd` to clear the cached `sorted` stuff in `StringDimensionDictionary`
   
   again; let me invite @clintropolis to see if He have a different idea :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1627535702


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   I believe the main purpose of the `dimLookup` field is to provide a common place where the different strings get an assigned number - so that if its able to recall an earlier value that's actually very important ...this change will destroy the `sortedLookup` cache even in case all calls to `add` were hits.
   
   I think you should either remove the changes in this file - or find a different way to address this; one idea could be; to connect the `StringDimensionIndexer` class as a modification listener of `dimLookup` - so that when a real add happens the `sortedLookup` will automatically destructed:
   * move the sorted dictionary caching to `StringDimensionDictionary`
   * extract a protected `realAdd` from the current `add` in `DimensionDictionary` 
   * implement `realAdd` to clear the cached `sorted` stuff in `StringDimensionDictionary`
   
   again; let me invite @clintropolis to see if He have a different idea :)



##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -93,14 +95,26 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
 
     if (dimValues == null) {
       final int nullId = dimLookup.getId(null);

Review Comment:
   you don't need the `if` in case you use `dimLookup.add(null)` instead of `getId`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1627164179


##########
processing/src/main/java/org/apache/druid/segment/DictionaryEncodedColumnMerger.java:
##########
@@ -322,7 +322,7 @@ public void processMergedRow(ColumnValueSelector selector) throws IOException
     if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
       ((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
     } else {
-      int value = row.size() == 0 ? 0 : row.get(0);
+      int value = rowSize == 0 ? 0 : row.get(0);

Review Comment:
   oh - that's true; and its being used as well around here!
   
   but how it works now is that it will call `getRow` for every `size` and `get(i)` invocations as well [see here](https://github.com/apache/druid/blob/30c59042e0cde3c76392afa3ba73d0830b11b0a5/processing/src/main/java/org/apache/druid/segment/DictionaryEncodedColumnIndexer.java#L161)
   
   the costly process is to produce the `row`  itself; currently built by: [StringDimensionIndexer$IndexerDimensionSelector#getRow](https://github.com/apache/druid/blob/30c59042e0cde3c76392afa3ba73d0830b11b0a5/processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java#L304) - if that could be cached somehow - that would result in the same benefits.
   There are better access to internals there; I believe if the "same" entry is being used (`currEntry.get()`) then it might be ok to return the previously built row.
   Although the [IncrementalIndexRow](https://github.com/apache/druid/blob/30c59042e0cde3c76392afa3ba73d0830b11b0a5/processing/src/main/java/org/apache/druid/segment/incremental/IncrementalIndexRow.java#L110)  looks partially mutable; but the since the `timestamp` can't be set: I think its not intended to be reused - so I think you could put a caching logic there based on whether `currEntry.get()` is the same
   
   to ensure that I'll don't send you on a wild goose chase I'll ask @clintropolis to possibly doublecheck the above thinking :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1622175524


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   only the `add` method are called on `dimLookup` above - which naturally changes the `size` ; I'm not sure what the addition of this `boolean` adds - as it must be set to true after all `add` calls.
   
   Actually since the `add` call may even [bail out and do nothing](https://github.com/apache/druid/blob/3c72ec8413fc066dbb56e9f02d6fbc6e3b28bbe1/processing/src/main/java/org/apache/druid/segment/DimensionDictionary.java#L164) in some cases: Theoretically this may force `sortedLookup` to become `null` in cases in which earlier it would not done that - which seems like a behaviour change...
   
   ...and because of the above I wonder how does the introduction of this boolean improves performance?



##########
processing/src/main/java/org/apache/druid/segment/DictionaryEncodedColumnMerger.java:
##########
@@ -322,7 +322,7 @@ public void processMergedRow(ColumnValueSelector selector) throws IOException
     if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
       ((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
     } else {
-      int value = row.size() == 0 ? 0 : row.get(0);
+      int value = rowSize == 0 ? 0 : row.get(0);

Review Comment:
   this seems good to me :)
   from the attached screenshot it appears to me that mainly the `dimSelectorWithUnsortedValues.getRow()` method is the bottleneck ; when its called from `SortedDimentsionSelector`
   
   
   as `get` also calls that method - wouldn't it be a possibly more complete fix to either precompute ; or lazily store the computed value of `dimSelectorWithUnsortedValues.getRow()` in the `DictionaryEncordedColumnIndexer$SortedDimensionSelector` class? that could cache the row built by `StringDimensionIndexer$IndexerDimensionSelector#getRow` - which builds an `ArrayBasedIndexedInts` which has the `size` flattened in.
   
   this could enable the same optimization to seamlessly flow to other places as well :)



##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -83,7 +83,7 @@ public StringDimensionIndexer(
   public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@Nullable Object dimValues, boolean reportParseExceptions)
   {
     final int[] encodedDimensionValues;
-    final int oldDictSize = dimLookup.size();
+    volatile boolean dictionaryChanged = false;

Review Comment:
   I'm a bit confused by this `volatile` - whats the reasoning behind the usage of that?
   I don't see how this local variable can be accessed from multiple threads...
   



##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -94,13 +94,21 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     if (dimValues == null) {
       final int nullId = dimLookup.getId(null);
       encodedDimensionValues = nullId == DimensionDictionary.ABSENT_VALUE_ID ? new int[]{dimLookup.add(null)} : new int[]{nullId};
+      if (nullId == DimensionDictionary.ABSENT_VALUE_ID) {
+        encodedDimensionValues = new int[]{dimLookup.add(null)};
+        dictionaryChanged = true;
+      } else {
+        encodedDimensionValues = new int[]{nullId};
+      }

Review Comment:
   with the addition of these lines I think `dimLookup.add(null)` will be called more than before
   
   seems like the `?:` version of this if was not removed?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "clintropolis (via GitHub)" <gi...@apache.org>.
clintropolis commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1628457954


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   >so that if its able to recall an earlier value that's actually very important ...this change will destroy the sortedLookup cache even in case all calls to add were hits.
   
   The lookup is only sorted when persisting a segment, so `add` shouldn't really happen after the dictionary is sorted. I would guess this is here as a safeguard.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "kgyrtkirk (via GitHub)" <gi...@apache.org>.
kgyrtkirk commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1630732784


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   I think based on @clintropolis's comment:
   > I would guess this is here as a safeguard.
   
   you could just set it to `null` unconditionally - no need for the Pair and other complications



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1631137740


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -20,12 +20,14 @@
 package org.apache.druid.segment;
 
 import com.google.common.primitives.Ints;
+import com.sun.org.apache.xpath.internal.operations.Bool;

Review Comment:
   ## Access to unsupported JDK-internal API
   
   Access to unsupported JDK-internal API 'com.sun.org.apache.xpath.internal.operations.Bool'.
   
   [Show more details](https://github.com/apache/druid/security/code-scanning/7441)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16517:
URL: https://github.com/apache/druid/pull/16517#issuecomment-2357243051

   This pull request/issue has been closed due to lack of activity. If you think that
   is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #16517: Optimise indexer resource usage based on CPU profile
URL: https://github.com/apache/druid/pull/16517


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #16517:
URL: https://github.com/apache/druid/pull/16517#issuecomment-2299978014

   This pull request has been marked as stale due to 60 days of inactivity.
   It will be closed in 4 weeks if no further activity occurs. If you think
   that's incorrect or this pull request should instead be reviewed, please simply
   write any comment. Even if closed, you can still revive the PR at any time or
   discuss it on the dev@druid.apache.org list.
   Thank you for your contributions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1624265065


##########
processing/src/main/java/org/apache/druid/segment/DictionaryEncodedColumnMerger.java:
##########
@@ -322,7 +322,7 @@ public void processMergedRow(ColumnValueSelector selector) throws IOException
     if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
       ((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
     } else {
-      int value = row.size() == 0 ? 0 : row.get(0);
+      int value = rowSize == 0 ? 0 : row.get(0);

Review Comment:
   From the [DimensionSelector](https://github.com/apache/druid/blob/1974a38bc90783e7ff2d38362509377001177047/processing/src/main/java/org/apache/druid/segment/DimensionSelector.java#L61), the comment says something on the lines of not storing the result and calculate on demand. 
   
   What would you suggest considering this? @kgyrtkirk 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1623764102


##########
processing/src/main/java/org/apache/druid/segment/DictionaryEncodedColumnMerger.java:
##########
@@ -322,7 +322,7 @@ public void processMergedRow(ColumnValueSelector selector) throws IOException
     if (encodedValueSerializer instanceof ColumnarMultiIntsSerializer) {
       ((ColumnarMultiIntsSerializer) encodedValueSerializer).addValues(row);
     } else {
-      int value = row.size() == 0 ? 0 : row.get(0);
+      int value = rowSize == 0 ? 0 : row.get(0);

Review Comment:
   Makes sense, let me try caching the results or providing an efficient get method.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


Re: [PR] Optimise indexer resource usage based on CPU profile (druid)

Posted by "saithal-confluent (via GitHub)" <gi...@apache.org>.
saithal-confluent commented on code in PR #16517:
URL: https://github.com/apache/druid/pull/16517#discussion_r1630658620


##########
processing/src/main/java/org/apache/druid/segment/StringDimensionIndexer.java:
##########
@@ -132,12 +142,14 @@ public EncodedKeyComponent<int[]> processRowValsToUnsortedEncodedKeyComponent(@N
     } else if (dimValues instanceof byte[]) {
       encodedDimensionValues =
           new int[]{dimLookup.add(emptyToNullIfNeeded(StringUtils.encodeBase64String((byte[]) dimValues)))};
+      dictionaryChanged = true;
     } else {
       encodedDimensionValues = new int[]{dimLookup.add(emptyToNullIfNeeded(dimValues))};
+      dictionaryChanged = true;
     }
 
     // If dictionary size has changed, the sorted lookup is no longer valid.
-    if (oldDictSize != dimLookup.size()) {
+    if (dictionaryChanged) {

Review Comment:
   You are right, this invalidates the cache hits as well and changes the behaviour. I've pushed a new commit which would change the return type of `add` function from `int` to `Pair<Integer, Boolean>` where the boolean indicates whether an element was actually added to the dictionary or not. The integer however remains the same. 
   Please take a look @kgyrtkirk and @clintropolis 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org