You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/08/05 21:12:58 UTC

[GitHub] [beam] iindyk commented on a change in pull request #15271: Decreasing peak memory usage for `beam.TupleCombineFn`.

iindyk commented on a change in pull request #15271:
URL: https://github.com/apache/beam/pull/15271#discussion_r683791140



##########
File path: sdks/python/apache_beam/transforms/combiners.py
##########
@@ -616,10 +621,23 @@ def create_accumulator(self, *args, **kwargs):
     return [c.create_accumulator(*args, **kwargs) for c in self._combiners]
 
   def merge_accumulators(self, accumulators, *args, **kwargs):
-    return [
-        c.merge_accumulators(a, *args, **kwargs) for c,
-        a in zip(self._combiners, zip(*accumulators))
-    ]
+    # Make sure that `accumulators` is an iterator (so that the position is
+    # remembered).
+    accumulators = iter(accumulators)
+    result = next(accumulators)
+    while True:
+      # Load accumulators into memory and merge in batches to decrease peak
+      # memory usage.
+      accumulators_batch = list(

Review comment:
       You mean the # of packed accumulators (i.e. tupled CombineFns) ?
   
   Yes, ideally, it's a function of # of packed accumulators and their sizes, but since we don't know their sizes we wouldn't be able to derive a meaningful estimate for the batch size given just the # of packed accumulators. 
   It might still make sense to have default have a ~ reverse linear dependency on the # of packed accumulators though, but I'm not certain how to come up with a magic number, e.g. `merge_accumulators_batch_size` = max(100, 10000/# of combiners in a tuple). WDYT?




-- 
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@beam.apache.org

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