spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davies <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-2538] [PySpark] Hash based disk spillin...
Date Fri, 18 Jul 2014 22:21:22 GMT
Github user davies commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1460#discussion_r15136736
  
    --- 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 --
    
    In most cases, the merger will work in no-spill mode. So it's better to fallback into
no-spill mode when in Windows, an show an warning.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message