You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "adarshsanjeev (via GitHub)" <gi...@apache.org> on 2024/03/14 06:19:41 UTC

[PR] Resolve a bug where datasketches would not downsample sketches sufficiently (druid)

adarshsanjeev opened a new pull request, #16119:
URL: https://github.com/apache/druid/pull/16119

   Fix a bug where MSQ datasketches would not downsample the sketches enough. This would cause the sketches to retain more memory, potentially more than the limit configured. This in some cases lead to OutOfMemory errors.
   
   The bug should only occur with when adding keys with large weights, with a single bucket.
   
   <hr>
   To reproduce, where trips is the 3 days Taxi Cab sample dataset:
   
   ```sql
   WITH 
   "main" AS (
     SELECT 
       "pickup" AS "pickup",
       COUNT(*) AS "Count"
     FROM "trips"
     WHERE TIME_IN_INTERVAL("__time", '2015-01-11/2016-01-01')
     GROUP BY 1
     ORDER BY "Count" DESC
     LIMIT 200
   ),
   "compare0" AS (
     SELECT 
       "pickup" AS "pickup",
       COUNT(*) AS "Count"
     FROM "trips"
     WHERE TIME_IN_INTERVAL(TIME_SHIFT("__time", 'P1M', 1), '2015-01-11/2016-01-01')
     GROUP BY 1
   )
   SELECT 
     "main"."pickup" AS "pickup",
     "main"."Count" AS "Count",
     COALESCE("compare0"."Count", 0) AS "#prev: Count"
   FROM "main"
   LEFT JOIN "compare0" ON "main"."pickup" IS NOT DISTINCT FROM "compare0"."pickup"
   ```
   
   <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] Resolve a bug where datasketches would not downsample sketches sufficiently (druid)

Posted by "adarshsanjeev (via GitHub)" <gi...@apache.org>.
adarshsanjeev merged PR #16119:
URL: https://github.com/apache/druid/pull/16119


-- 
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] Resolve a bug where datasketches would not downsample sketches sufficiently (druid)

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


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/ClusterByStatisticsCollectorImpl.java:
##########
@@ -443,7 +449,9 @@ void downSample()
       bucketHolder.keyCollector.downSample();
       newTotalRetainedBytes += bucketHolder.updateRetainedBytes();
 
-      if (i == sortedHolders.size() - 1 || sortedHolders.get(i + 1).rhs.retainedBytes > bucketHolder.retainedBytes || bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) {
+      if ((bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) ||

Review Comment:
   Can you please add the reasoning for the condition in the `if` here? 



-- 
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] Resolve a bug where datasketches would not downsample sketches sufficiently (druid)

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


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/ClusterByStatisticsCollectorImpl.java:
##########
@@ -443,7 +449,9 @@ void downSample()
       bucketHolder.keyCollector.downSample();
       newTotalRetainedBytes += bucketHolder.updateRetainedBytes();
 
-      if (i == sortedHolders.size() - 1 || sortedHolders.get(i + 1).rhs.retainedBytes > bucketHolder.retainedBytes || bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) {
+      if ((bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) ||

Review Comment:
   Reverted this change



-- 
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] Resolve a bug where datasketches would not downsample sketches sufficiently (druid)

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


##########
extensions-core/multi-stage-query/src/main/java/org/apache/druid/msq/statistics/ClusterByStatisticsCollectorImpl.java:
##########
@@ -443,7 +449,9 @@ void downSample()
       bucketHolder.keyCollector.downSample();
       newTotalRetainedBytes += bucketHolder.updateRetainedBytes();
 
-      if (i == sortedHolders.size() - 1 || sortedHolders.get(i + 1).rhs.retainedBytes > bucketHolder.retainedBytes || bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) {
+      if ((bucketHolder.keyCollector.estimatedRetainedKeys() <= 1) ||

Review Comment:
   Can you add the reasoning for the if..else here? 



-- 
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