RMI Remoting Optimization
Remoting is a key element in modern enterprise applications . While it can help to increase scalabilty and performance it might also become a bottleneck. Especially in highly transactional applications the network easily becomes the bottleneck.
I examined possible performance optimizations in Java RMI following the guidance given in the book Java RMI. The results are very interesting.
I used a simple address service which sends backa number of persons and the countries they live in. The class diagram below shows the structure. The empty BasePerson class is just for presentation purposes. The FastPerson class is used only to override the serialization behaviour.
I compared a testrun using standard serialization compared to implementing the Externalizable
Interface. Below is the code for custom serialization in the FastPerson class.
public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {
firstName = in.readUTF();
lastName = in.readUTF();
birthdate = new Date (in.readLong());
country = (Country) in.readObject();
} @Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(firstName);
out.writeUTF(lastName);
out.writeLong(this.birthdate.getTime());
out.writeObject(this.country);
}
The results below that the performance of the custom serialization is 32 percent faster and sends 21 percent less data. However the effort to implement custom serialization is higher.
In order to analyse the differences deeper let us take a look at the API breakdown. We can see that the time difference is mainly caused by serialization. The upper charts show the CPU and execution time for standard serialization and the lower charts show the times for custom serialization. The differences in the Client and Address Server layer can be explained by serialization. However they are minimal.
Leave a comment