Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1460#discussion_r15072768
  
    --- Diff: python/pyspark/rdd.py ---
    @@ -168,6 +170,123 @@ def _replaceRoot(self, value):
                 self._sink(1)
     
     
    +class Merger(object):
    +    """
    +    External merger will dump the aggregated data into disks when memory 
usage is above
    +    the limit, then merge them together.
    +
    +    >>> combiner = lambda x, y:x+y
    +    >>> merger = Merger(combiner, 10)
    +    >>> N = 10000
    +    >>> merger.merge(zip(xrange(N), xrange(N)) * 10)
    +    >>> merger.spills
    +    100
    +    >>> sum(1 for k,v in merger.iteritems())
    +    10000
    +    """
    +
    +    PARTITIONS = 64
    +    BATCH = 1000
    +
    +    def __init__(self, combiner, memory_limit=256, path="/tmp/pyspark", 
serializer=None):
    +        self.combiner = combiner
    +        self.path = os.path.join(path, str(os.getpid()))
    +        self.memory_limit = memory_limit
    +        self.serializer = serializer or 
BatchedSerializer(AutoSerializer(), 1024)
    +        self.item_limit = None
    +        self.data = {}
    +        self.pdata = []
    +        self.spills = 0
    +
    +    def used_memory(self):
    +        rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
    +        if platform.system() == 'Linux':
    +            rss >>= 10
    +        elif platform.system() == 'Darwin':
    +            rss >>= 20
    --- End diff --
    
    We also need to make it work on Windows, or at least fail gracefully. Do 
you know how to get this number on Windows? You can spin up a Windows machine 
on EC2 to try it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to