Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider a faster json serialization library? #365

Closed
limdauto opened this issue Feb 29, 2016 · 2 comments
Closed

Consider a faster json serialization library? #365

limdauto opened this issue Feb 29, 2016 · 2 comments

Comments

@limdauto
Copy link

Hi, I was wondering if there has been discussion about using a faster json serialization library such as ujson (or rapidjson but it's not very backward compatible). It could speed up some APIs such as bulk indexing considerably. I haven't benchmarked it yet but just want to see if you are keen.

@honzakral
Copy link
Contributor

Hi @limdauto, unfortunately not many of these json implementations are very stable in terms of error handling and other very important feature - ujson for example serializes object() as {} which can lead to very hard to find errors, rapidjson then throws a RuntimeError which could be very dangerous to try and catch.

For those reasons I don't see them as being implemented as part of the library any time soon. Especially since there is nothing stopping users from implementing the alternative serializers themselves:

class UJsonSerializer(object):
    mimetype = 'application/json'
    def dumps(self, data):
        try:
            return ujson.dumps(data)
        except:
            raise SerializationError()

    def loads(self, data):
        try:
            return ujson.loads(data)
        except:
            raise SerializationError()


es = Elasticsearch(serializer=UJsonSerializer())

@limdauto
Copy link
Author

Thank you for taking the time to answer. The custom serializer solution looks great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants