You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "korowa (via GitHub)" <gi...@apache.org> on 2023/02/19 19:46:15 UTC

[GitHub] [arrow-datafusion] korowa opened a new pull request, #5339: Memory reservation & metrics for cross join

korowa opened a new pull request, #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #5162.
   Part of #5220.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   Memory management for at least on Join operator
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
    - `CrossJoinExec.reservation` -- the actual reservation, used in `load_left_input` closure to reserve memory for build-side data, and in stream polling function to free memory after probe-side stream has been exhausted. Another point where memory gets freed is a destructor of reservation (i.e. in case when parent operator has `LIMIT`), so it's not required to store reservation as a stream attribute, but explicitly calling `free` seems like more correct way
    - `BuildProbeJoinMetrics` -- at this moment CrossJoinExec lacks metrics which could be exposed in `explain analyze` -- the counters from `CrossJoinStream` has been moved to `BuildProbeJoinMetrics` structure -- it could also be used in followups for both `NestedLoopJoinExec` and `HashJoinExec` as they all share almost the same "build & probe" idea, so their metrics could be similar.
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Test cases for normal cross join execution and asserting error in case of overallocation attempt have been added
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] ursabot commented on pull request #5339: Memory reservation & metrics for cross join

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339#issuecomment-1448307404

   Benchmark runs are scheduled for baseline = 20d08ab1fc960162c71d156935a7b29cc51ab4fb and contender = ea3b965dd4861f966a5ec1c4a65f748f0e5dcc12. ea3b965dd4861f966a5ec1c4a65f748f0e5dcc12 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/cd6234407d7c4d0ba6d15d5a182780b7...54a3bbb0b18c42cf9b515835ad76a2de/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/b9ecb23e4b6c4588bb6e9e901394ad06...8495a37e815140629f37249605a63d62/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/7ee8dcd1c389466f9261e8140bdf2faa...761fcef6eda541f9a7e52814bce249e2/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e9ba2e63040f4ebca2429bfdb3e4fb34...2195e83baaaf46eaa1b595e64e1aa9cd/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #5339: Memory reservation & metrics for cross join

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339#issuecomment-1445352291

   Thank you @korowa  -- I plan to review this carefully tomorrow


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb merged pull request #5339: Memory reservation & metrics for cross join

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5339: Memory reservation & metrics for cross join

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339#discussion_r1119306849


##########
datafusion/core/src/physical_plan/joins/cross_join.rs:
##########
@@ -434,15 +453,7 @@ impl CrossJoinStream {
                     Some(result)
                 }
                 other => {
-                    debug!(

Review Comment:
   I think it is a nice improvement that the metrics are now included in things like `EXPLAIN ANALYZE`



##########
datafusion/core/src/physical_plan/joins/cross_join.rs:
##########
@@ -111,22 +116,28 @@ async fn load_left_input(
     let stream = merge.execute(0, context)?;
 
     // Load all batches and count the rows
-    let (batches, num_rows) = stream
-        .try_fold((Vec::new(), 0usize), |mut acc, batch| async {
-            acc.1 += batch.num_rows();
-            acc.0.push(batch);
-            Ok(acc)
-        })
+    let (batches, num_rows, _, _) = stream
+        .try_fold(
+            (Vec::new(), 0usize, metrics, reservation),
+            |mut acc, batch| async {
+                let batch_size = batch.get_array_memory_size();
+                // Reserve memory for incoming batch
+                acc.3.lock().try_grow(batch_size)?;
+                // Update metrics

Review Comment:
   ❤️ 



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] korowa commented on pull request #5339: Memory reservation & metrics for cross join

Posted by "korowa (via GitHub)" <gi...@apache.org>.
korowa commented on PR #5339:
URL: https://github.com/apache/arrow-datafusion/pull/5339#issuecomment-1447708169

   Thank you for the review @alamb!
   
   > I think we should also add sql level test for the memory limit code in; I think it should be easy to add one to https://github.com/apache/arrow-datafusion/blob/main/datafusion/core/tests/memory_limit.rs. I am happy to add such a test if you prefer as a follow on PR.
   
   Seems like new `test_overallocation` is sort of duplicate of `memory_limit` tests  -- so, I guess, it'll be better to add new `memory_limit` test instead of existing one in this PR


-- 
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: github-unsubscribe@arrow.apache.org

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