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.

Class Diagram of Entity Classes
Class Diagram of Entity Classes

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 {

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.

Performance Comparision of Standard vs. Custom Serialization

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.

API Breakdown Comparison
API Breakdown Comparison
ConclusionImplementing custom serialization can help to improve response times and reduce network overhead. However additional effort for implementation and maintainance is required. It is best to choose on a case-by-case basis which approach to take.