SlideShare a Scribd company logo
1 of 12
Java Incremental
Deserialization/reserialization (JID)




              Bill La Forge
      CTO, Jactor Consulting
     http://jactorconsulting.com
The Problem
●   Data is stored on disk as byte arrays, which
    may be quite large.
●   These arrays must be deserialized before the
    data can be updated and then reserialized.
●   There are various techniques for deserialization
    and reserialization but they are all quite slow as
    all the data is deserialized and then
    reserialized.
Incremental Deserialization and
       Reserialization

JID Benchmark results for deserializing, updating and then
reserializing large collections.

       Entries       List Insertion   Map Update
       1,000         .014 ms          .027 ms
       10.000        .035 ms          .056 ms
       100,000       .24 ms           .48 ms
       1,000,000     2.9 ms           6.9 ms


High performance is achieved by deserializing only
the data that is needed and reserializing only the
data that has been updated.
Types of Serialization
●   Many applications use      ●   Hard-coded serialization
    reflection-based               directly converst data
    serialization.                 from/to arrays of bytes.
●   Reflection-based           ●   This is harder to
    serialization is the           implement, but runs
    easiest to use, but also       faster.
    the slowest.               ●   But mixing applicaiton
●   There are three main           logic with serialization
    types: native                  logic detracts from the
    serialization, XML-based       clarity of the code.
    and Jason.
JID is Complex
●   Every JID object must track the serialized data
    that has not been outdated and any data that
    has been deserialized, along with notifying its
    container when there is a change.
●   Serializable data structures are trees of JID
    objects that are mostly instances of pre-defined
    classes.
●   Application classes contain no serialization
    logic, but subclass a JID vector of homogenious
    JID types.
Factories
●   Registered factory objects are needed to instantiate
    and initialize JID objects.
●   Each registered facory object represents a different
    JID type and has a unique name.
●   All factory objects are instances of subclasses of the
    JidFactory class.
●   Factory objects used to instantiate application JID
    objects are instances of subclasses of AppJidFactory.
●   These factory objects provide the type names of the
    registered factory objects needed to create the tuple
    elements of the application objects.
User Class
public class User extends AppJid {
  private StringJid getNameJid() throws Exception {
     return (StringJid) _iGet(0);}
  private IntegerJid getAgeJid() throws Exception {
     return (IntegerJid) _iGet(1);}
  public String getName() throws Exception {
     return getNameJid().getValue();}
  public void setName(String name) throws Exception {
     getNameJid().setValue(name);}
  public int getAge() throws Exception {
     return getAgeJid().getValue();}
  public void setAge(int age) throws Exception {
     getAgeJid().setValue(age);}
}
UserFactoryClass
public class UserFactory extends AppJidFactory {
  final public static UserFactory fac = new UserFactory();

    public UserFactory() {
      super("User",
             JidFactories.STRING_JID_TYPE,
             JidFactories.INTEGER_JID_TYPE);
    }

    protected User instantiateActor()
         throws Exception {
      return new User();
    }
}
User Test Environment
public class Apps {
  public static void main(String[] args) throws Exception {
     JAFactory factory = new JAFactory();
     (new JidFactories()).initialize(factory);
     factory.registerActorFactory(UserFactory.fac);
     .
     .
     .
  }
}
Serializing
RootJid rootJid0 = (RootJid)
   factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid0.setValue("User");
User user0 = (User) rootJid0.getValue();
user0.setName("Fred");
user0.setAge(38);
int serializedLength0 = rootJid0.getSerializedLength();
byte[] serializedData0 = new byte[serializedLength0];
rootJid0.save(serializedData0, 0);
Deserialization
RootJid rootJid1 = (RootJid)
  factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid1.load(serializedData0, 0, serializedLength0);
User user1 = (User) rootJid1.getValue();

if (!"Fred".equals(user1.getName()))
    throw new Exception("unexpected result");
if (38 != user1.getAge())
    throw new Exception("unexpected result");
JID Project




JID Project Page:
  http://jactorconsulting.com/product/jid/

License: LGPL

More Related Content

What's hot

Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialSyed Shahul
 
Serialization in java
Serialization in javaSerialization in java
Serialization in javaJanu Jahnavi
 
Cloud computing BI publication 1
Cloud computing BI   publication 1Cloud computing BI   publication 1
Cloud computing BI publication 1Jobe Bacwadi
 
Modular ObjectLens
Modular ObjectLensModular ObjectLens
Modular ObjectLensESUG
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving DataAnuchit Chalothorn
 

What's hot (8)

Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Hibernate
HibernateHibernate
Hibernate
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Serialization in java
Serialization in javaSerialization in java
Serialization in java
 
Cloud computing BI publication 1
Cloud computing BI   publication 1Cloud computing BI   publication 1
Cloud computing BI publication 1
 
04 Data Access
04 Data Access04 Data Access
04 Data Access
 
Modular ObjectLens
Modular ObjectLensModular ObjectLens
Modular ObjectLens
 
Android App Development 05 : Saving Data
Android App Development 05 : Saving DataAndroid App Development 05 : Saving Data
Android App Development 05 : Saving Data
 

Similar to Incremental Java Deserialization/Reserialization

Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java DeserializationShiv Sahni
 
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyLeveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyDATAVERSITY
 
.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdfMirco Vanini
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Apostolos Giannakidis
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEEeanimou
 
RIBs - Fragments which work
RIBs - Fragments which workRIBs - Fragments which work
RIBs - Fragments which workDmitry Zaytsev
 
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)Igalia
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConos890
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)hchen1
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android JetpackAhmad Arif Faizin
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basicsAathikaJava
 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate BasicsDeeptiJava
 
Mitigating Java Deserialization attacks from within the JVM
Mitigating Java Deserialization attacks from within the JVMMitigating Java Deserialization attacks from within the JVM
Mitigating Java Deserialization attacks from within the JVMApostolos Giannakidis
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer ReferenceMuthuselvam RS
 
MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library Magda Miu
 
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020Geir Høydalsvik
 

Similar to Incremental Java Deserialization/Reserialization (20)

Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Insecure Java Deserialization
Insecure Java DeserializationInsecure Java Deserialization
Insecure Java Deserialization
 
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL TechnologyLeveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
Leveraging your Knowledge of ORM Towards Performance-based NoSQL Technology
 
.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf.NET 7 Performance Improvements_10_03_2023.pdf
.NET 7 Performance Improvements_10_03_2023.pdf
 
Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)Mitigating Java Deserialization attacks from within the JVM (improved version)
Mitigating Java Deserialization attacks from within the JVM (improved version)
 
Green dao
Green daoGreen dao
Green dao
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
 
RIBs - Fragments which work
RIBs - Fragments which workRIBs - Fragments which work
RIBs - Fragments which work
 
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Hibernate basics
Hibernate basicsHibernate basics
Hibernate basics
 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate Basics
 
Mitigating Java Deserialization attacks from within the JVM
Mitigating Java Deserialization attacks from within the JVMMitigating Java Deserialization attacks from within the JVM
Mitigating Java Deserialization attacks from within the JVM
 
Hibernate Developer Reference
Hibernate Developer ReferenceHibernate Developer Reference
Hibernate Developer Reference
 
MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library MobiConf 2018 | Room: an SQLite object mapping library
MobiConf 2018 | Room: an SQLite object mapping library
 
Data access
Data accessData access
Data access
 
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020MySQL Goes to 8!  FOSDEM 2020 Database Track, January 2nd, 2020
MySQL Goes to 8! FOSDEM 2020 Database Track, January 2nd, 2020
 

Incremental Java Deserialization/Reserialization

  • 1. Java Incremental Deserialization/reserialization (JID) Bill La Forge CTO, Jactor Consulting http://jactorconsulting.com
  • 2. The Problem ● Data is stored on disk as byte arrays, which may be quite large. ● These arrays must be deserialized before the data can be updated and then reserialized. ● There are various techniques for deserialization and reserialization but they are all quite slow as all the data is deserialized and then reserialized.
  • 3. Incremental Deserialization and Reserialization JID Benchmark results for deserializing, updating and then reserializing large collections. Entries List Insertion Map Update 1,000 .014 ms .027 ms 10.000 .035 ms .056 ms 100,000 .24 ms .48 ms 1,000,000 2.9 ms 6.9 ms High performance is achieved by deserializing only the data that is needed and reserializing only the data that has been updated.
  • 4. Types of Serialization ● Many applications use ● Hard-coded serialization reflection-based directly converst data serialization. from/to arrays of bytes. ● Reflection-based ● This is harder to serialization is the implement, but runs easiest to use, but also faster. the slowest. ● But mixing applicaiton ● There are three main logic with serialization types: native logic detracts from the serialization, XML-based clarity of the code. and Jason.
  • 5. JID is Complex ● Every JID object must track the serialized data that has not been outdated and any data that has been deserialized, along with notifying its container when there is a change. ● Serializable data structures are trees of JID objects that are mostly instances of pre-defined classes. ● Application classes contain no serialization logic, but subclass a JID vector of homogenious JID types.
  • 6. Factories ● Registered factory objects are needed to instantiate and initialize JID objects. ● Each registered facory object represents a different JID type and has a unique name. ● All factory objects are instances of subclasses of the JidFactory class. ● Factory objects used to instantiate application JID objects are instances of subclasses of AppJidFactory. ● These factory objects provide the type names of the registered factory objects needed to create the tuple elements of the application objects.
  • 7. User Class public class User extends AppJid { private StringJid getNameJid() throws Exception { return (StringJid) _iGet(0);} private IntegerJid getAgeJid() throws Exception { return (IntegerJid) _iGet(1);} public String getName() throws Exception { return getNameJid().getValue();} public void setName(String name) throws Exception { getNameJid().setValue(name);} public int getAge() throws Exception { return getAgeJid().getValue();} public void setAge(int age) throws Exception { getAgeJid().setValue(age);} }
  • 8. UserFactoryClass public class UserFactory extends AppJidFactory { final public static UserFactory fac = new UserFactory(); public UserFactory() { super("User", JidFactories.STRING_JID_TYPE, JidFactories.INTEGER_JID_TYPE); } protected User instantiateActor() throws Exception { return new User(); } }
  • 9. User Test Environment public class Apps { public static void main(String[] args) throws Exception { JAFactory factory = new JAFactory(); (new JidFactories()).initialize(factory); factory.registerActorFactory(UserFactory.fac); . . . } }
  • 10. Serializing RootJid rootJid0 = (RootJid) factory.newActor(JidFactories.ROOT_JID_TYPE); rootJid0.setValue("User"); User user0 = (User) rootJid0.getValue(); user0.setName("Fred"); user0.setAge(38); int serializedLength0 = rootJid0.getSerializedLength(); byte[] serializedData0 = new byte[serializedLength0]; rootJid0.save(serializedData0, 0);
  • 11. Deserialization RootJid rootJid1 = (RootJid) factory.newActor(JidFactories.ROOT_JID_TYPE); rootJid1.load(serializedData0, 0, serializedLength0); User user1 = (User) rootJid1.getValue(); if (!"Fred".equals(user1.getName())) throw new Exception("unexpected result"); if (38 != user1.getAge()) throw new Exception("unexpected result");
  • 12. JID Project JID Project Page: http://jactorconsulting.com/product/jid/ License: LGPL