Showing posts with label POF. Show all posts
Showing posts with label POF. Show all posts

Monday, June 4, 2012

Best Practices for Coherence Portable Object Format (POF)



POF objects are indexed so it is possible to quickly traverse/navigate the binary (serialized form) to a specific element for extraction or updating using the indices without de-serializing the entire binary. Out of the box, coherence provides SimplePofPath class that can navigate a POF value based on integer indices. In the simplest form, all you need to do is to provide the index of the attribute that you want to extract/update. Some of the best practices that are coming to my mind are as under:
  • Order your reads and writes: start with the lowest index value in the serialization routine and finish with the highest. When deserializing a value, perform reads in the same order as writes.
  • Use the smallest possible integer for indexing the objects
  • Non-contiguous indexes are acceptable but must be read/written sequentially.
  • For subclasses reserve index ranges: index's are cumulative across derived types. As such, each derived type must be aware of the POF index range reserved by its super class.
  • Do not re-purpose indexes: to support Evolvable, it's imperative that indexes of attributes are not re-purposed across class revisions.
  • Label each of the index for the attribute
  • The most frequently used attribute in the Filter(s) and Extractor(s) should be assigned lowest index.
  • Enable POF Object  reference if the objects have circular/nested references (feature available in 3.7.1 + only)

Thursday, October 6, 2011

Coherence: POF Exceptions

If you are trying to use POF for object serialization as recommended for better performance and less RAM utilization with Coherence, there are 2 ways to implement it:

1. Implement PortableObject interface for all objects that will be stored in the Coherence Grid - Need to modify the object class and implement readExternal and writeExternal methods.
2. Externalize the serialization logic by creating classes that implement PofSerializer interface and logic for serialization and de-serialization of your objects is implemented in this class using the serialize/deserialize methods. Later, you can map this class as the serializer for your object in pof-config.xml

More details on both the above ways can be found here.

If you are getting an error while using the PortableObject interface as below:

Caused by: java.io.EOFException: user type POF stream terminated at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeUserTypeInfo(PofBufferWriter.java:2621) at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeRemainder(PofBufferWriter.java:2497) at com.tangosol.io.pof.PortableObjectSerializer.serialize(PortableObjectSerializer.java:96) at com.tangosol.io.pof.PofBufferWriter.writeUserType(PofBufferWriter.java:1667)
... 13 more


Remember to remove the readRemainder() and writeRemainder() from the readExternal/writeExternal methods as they are used with POFSerializer interface.

Search This Blog