Question

I'm doing some performance tuning on my application and would like to know a good way of measuring the size of the object that I am sending over RMI.

The aim is to make my object leaner.

Was it helpful?

Solution

the easiest way to do this is to put in some test code which writes the object to a file. then, look at the size of the file.

or, if you don't want to write to disk (and your objects are not going to blow out memory):

ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bout);
oos.writeObject(theObjectIWantTheSizeOf);
oos.close();
System.out.println("The object size is: " + bout.toByteArray().length:

OTHER TIPS

Because your object is serializable already - you can use the size() method on ObjectOutputStream to do this.

You need to check first what RMI protocol you are using. If you are using EJB 3 it might be calling CORBA (RMI-IIOP). If you want to improve the performance you can use the RMI over - Zipped IOP (ZIOP) — A zipped version of GIOP that reduces the bandwidth usage. try http://docs.jboss.org/jbossremoting/2.5.2.SP2/html_single/

This is not enough - the class may be sent as well as the serialized form of its instance.

The class should only be sent once and it will be the size it is on disk. Are you only sending the object once, or many times? If the latter the size of the class shouldn't be important.

A few month ago, I found this article Instrumentation Memory Counter at the Javaspecialist site, about calculating memory usage of Java objects. Perhaps it could be helpful for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top