Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

High performance serialization and deserialization to cache objects in redis [closed]

we are currently writing a REST service with jax-rs where we are caching the DB entities(javax.persistence.Entity) i.e.object representation of a table in database, in the redis server. Before even putting the objects to redis we serialize the objects to json via jackson and when we need the entity object we deserialize it after fetching from redis.

I want to know whether there is a faster/more performant way of doing serialization and deserialization. I am ok if somebody suggest a more performant way without converting the object to human readable format like json and also i don't want the intra language interoperability.

Please let me know if somebody needs some more details on this. Thanks.

like image 817
Trying Avatar asked Oct 14 '25 03:10

Trying


1 Answers

There are many, many libraries for serializing Objects in Java. JVM Serializers benchmark, for example, includes two dozens or so.

Couple of things that do help you get even faster serialization, if that is the primary concern:

  • If you use Jackson databind, check out Afterburner module: it can speed up handling by 20-30% without any changes to code
  • Try binary JSON formats like Smile or CBOR with Jackson (https://github.com/FasterXML/jackson-dataformat-smile, https://github.com/FasterXML/jackson-dataformat-cbor). These are not developer-readable, but take up less space, are bit faster to process, and can be read from other languages too (i.e. not Java specific)
  • If compatibility with JSON structure does not matter, and you do not need support from languages other than Java, Kryo is relatively mature ser/deser library, used by many systems.

For JSON, Jackson is amongst fastest, and while there are some cases where others (Boon, fastjson) can be faster, you really need to benchmark your particular use case to know if yours is one. But even then, difference is unlikely to be huge.

like image 107
StaxMan Avatar answered Oct 18 '25 08:10

StaxMan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!