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

    https://github.com/apache/spark/pull/1460#discussion_r15073011
  
    --- Diff: python/pyspark/serializers.py ---
    @@ -297,6 +297,33 @@ class MarshalSerializer(FramedSerializer):
         loads = marshal.loads
     
     
    +class AutoSerializer(FramedSerializer):
    +    """
    +    Choose marshal or cPickle as serialization protocol autumatically
    +    """
    +    def __init__(self):
    +        FramedSerializer.__init__(self)
    +        self._type = None
    +
    +    def dumps(self, obj):
    +        try:
    +            if self._type is not None:
    +                raise TypeError("fallback")
    +            return 'M' + marshal.dumps(obj)
    +        except Exception:
    +            self._type = 'P'
    +            return 'P' + cPickle.dumps(obj, -1)
    --- End diff --
    
    If the objects are not marshal-able but are pickle-able, is there a big 
performance cost to throwing an exception on each write? Would be good to test 
this, because if not, we can make this serializer our default where we now use 
Pickle. Even if there is a cost maybe we can do something where if 10% of the 
objects written fail to marshal we switch to always using pickle.


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